xref: /openbsd-src/usr.sbin/tcpdump/print-raw.c (revision 426b943da867de522a7641ed6221b6e97830db2a)
1 /*	$OpenBSD: print-raw.c,v 1.9 2021/12/01 18:28:46 deraadt Exp $	*/
2 
3 /*
4  * Copyright (c) 1996
5  *	The Regents of the University of California.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that: (1) source code distributions
9  * retain the above copyright notice and this paragraph in its entirety, (2)
10  * distributions including binary code include the above copyright notice and
11  * this paragraph in its entirety in the documentation or other materials
12  * provided with the distribution, and (3) all advertising materials mentioning
13  * features or use of this software display the following acknowledgement:
14  * ``This product includes software developed by the University of California,
15  * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
16  * the University nor the names of its contributors may be used to endorse
17  * or promote products derived from this software without specific prior
18  * written permission.
19  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
20  * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
21  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
22  */
23 
24 #include <sys/time.h>
25 #include <sys/socket.h>
26 #include <sys/file.h>
27 #include <sys/ioctl.h>
28 
29 #include <net/if.h>
30 
31 #include <netinet/in.h>
32 #include <netinet/ip.h>
33 #include <netinet/if_ether.h>
34 #include <netinet/ip_var.h>
35 #include <netinet/udp.h>
36 #include <netinet/udp_var.h>
37 #include <netinet/tcp.h>
38 
39 #include <pcap.h>
40 #include <stdio.h>
41 #include <string.h>
42 
43 #include "addrtoname.h"
44 #include "interface.h"
45 
46 #ifndef AF_NS
47 #define AF_NS		6		/* XEROX NS protocols */
48 #endif
49 
50 /*
51  * The DLT_RAW packet has no header. It contains a raw IP packet.
52  */
53 
54 void
raw_if_print(u_char * user,const struct pcap_pkthdr * h,const u_char * p)55 raw_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
56 {
57 	u_int length = h->len;
58 	u_int caplen = h->caplen;
59 
60 	ts_print(&h->ts);
61 
62 	/*
63 	 * Some printers want to get back at the link level addresses,
64 	 * and/or check that they're not walking off the end of the packet.
65 	 * Rather than pass them all the way down, we set these globals.
66 	 */
67 	packetp = p;
68 	snapend = p + caplen;
69 
70 	if (eflag)
71 		printf("ip: ");
72 
73 	ip_print(p, length);
74 
75 	if (xflag)
76 		default_print(p, caplen);
77 	putchar('\n');
78 }
79