]> The Tcpdump Group git mirrors - tcpdump/blob - print-null.c
s/u_short/u_int16_t/ for KAME-origin source codes
[tcpdump] / print-null.c
1 /*
2 * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that: (1) source code distributions
7 * retain the above copyright notice and this paragraph in its entirety, (2)
8 * distributions including binary code include the above copyright notice and
9 * this paragraph in its entirety in the documentation or other materials
10 * provided with the distribution, and (3) all advertising materials mentioning
11 * features or use of this software display the following acknowledgement:
12 * ``This product includes software developed by the University of California,
13 * Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
14 * the University nor the names of its contributors may be used to endorse
15 * or promote products derived from this software without specific prior
16 * written permission.
17 * THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
18 * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
19 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
20 */
21
22 #ifndef lint
23 static const char rcsid[] =
24 "@(#) $Header: /tcpdump/master/tcpdump/print-null.c,v 1.30 1999-12-22 06:27:21 itojun Exp $ (LBL)";
25 #endif
26
27 #ifdef HAVE_CONFIG_H
28 #include "config.h"
29 #endif
30
31 #include <sys/param.h>
32 #include <sys/time.h>
33 #include <sys/socket.h>
34 #include <sys/file.h>
35 #include <sys/ioctl.h>
36
37 #if __STDC__
38 struct mbuf;
39 struct rtentry;
40 #endif
41 #include <net/if.h>
42
43 #include <netinet/in.h>
44 #include <netinet/in_systm.h>
45 #include <netinet/ip.h>
46 #include <netinet/if_ether.h>
47 #include <netinet/ip_var.h>
48 #include <netinet/udp.h>
49 #include <netinet/udp_var.h>
50 #include <netinet/tcp.h>
51
52 #include <pcap.h>
53 #include <stdio.h>
54 #include <string.h>
55
56 #ifdef INET6
57 #include <netinet/ip6.h>
58 #endif
59
60 #include "interface.h"
61 #include "addrtoname.h"
62
63 #ifndef AF_NS
64 #define AF_NS 6 /* XEROX NS protocols */
65 #endif
66
67 /*
68 * The DLT_NULL packet header is 4 bytes long. It contains a network
69 * order 32 bit integer that specifies the family, e.g. AF_INET
70 */
71 #define NULL_HDRLEN 4
72
73 static void
74 null_print(const u_char *p, const struct ip *ip, u_int length)
75 {
76 u_int family;
77
78 memcpy((char *)&family, (char *)p, sizeof(family));
79
80 if (nflag) {
81 /* XXX just dump the header */
82 return;
83 }
84 switch (family) {
85
86 case AF_INET:
87 printf("ip: ");
88 break;
89
90 #ifdef INET6
91 case AF_INET6:
92 printf("ip6: ");
93 break;
94 #endif
95
96 case AF_NS:
97 printf("ns: ");
98 break;
99
100 default:
101 printf("AF %d: ", family);
102 break;
103 }
104 }
105
106 void
107 null_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
108 {
109 u_int length = h->len;
110 u_int caplen = h->caplen;
111 const struct ip *ip;
112
113 ts_print(&h->ts);
114
115 /*
116 * Some printers want to get back at the link level addresses,
117 * and/or check that they're not walking off the end of the packet.
118 * Rather than pass them all the way down, we set these globals.
119 */
120 packetp = p;
121 snapend = p + caplen;
122
123 length -= NULL_HDRLEN;
124
125 ip = (struct ip *)(p + NULL_HDRLEN);
126
127 if (eflag)
128 null_print(p, ip, length);
129
130 switch (ip->ip_v) {
131 case 4:
132 ip_print((const u_char *)ip, length);
133 break;
134 #ifdef INET6
135 case 6:
136 ip6_print((const u_char *)ip, length);
137 break;
138 #endif /* INET6 */
139 default:
140 printf("ip v%d", ip->ip_v);
141 break;
142 }
143
144 if (xflag)
145 default_print((const u_char *)ip, caplen - NULL_HDRLEN);
146 putchar('\n');
147 }
148