]> The Tcpdump Group git mirrors - tcpdump/blob - print-null.c
Eliminate some unused parameters.
[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.41 2001-07-05 18:54:15 guy 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 struct mbuf;
38 struct rtentry;
39
40 #include <netinet/in.h>
41
42 #include <pcap.h>
43 #include <stdio.h>
44 #include <string.h>
45
46 #include "interface.h"
47 #include "addrtoname.h"
48
49 #include "ip.h"
50 #ifdef INET6
51 #include "ip6.h"
52 #endif
53
54 #ifndef AF_NS
55 #define AF_NS 6 /* XEROX NS protocols */
56 #endif
57
58 /*
59 * The DLT_NULL packet header is 4 bytes long. It contains a host-byte-order
60 * 32-bit integer that specifies the family, e.g. AF_INET.
61 *
62 * Note here that "host" refers to the host on which the packets were
63 * captured; that isn't necessarily *this* host.
64 *
65 * The OpenBSD DLT_LOOP packet header is the same, except that the integer
66 * is in network byte order.
67 */
68 #define NULL_HDRLEN 4
69
70 static void
71 null_print(u_int family, u_int length)
72 {
73 if (nflag)
74 printf("AF %u ", family);
75 else {
76 switch (family) {
77
78 case AF_INET:
79 printf("ip ");
80 break;
81
82 #ifdef INET6
83 case AF_INET6:
84 printf("ip6 ");
85 break;
86 #endif
87
88 case AF_NS:
89 printf("ns ");
90 break;
91
92 default:
93 printf("AF %u ", family);
94 break;
95 }
96 }
97 printf("%d: ", length);
98 }
99
100 /*
101 * Byte-swap a 32-bit number.
102 * ("htonl()" or "ntohl()" won't work - we want to byte-swap even on
103 * big-endian platforms.)
104 */
105 #define SWAPLONG(y) \
106 ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff))
107
108 void
109 null_if_print(u_char *user, const struct pcap_pkthdr *h, const u_char *p)
110 {
111 u_int length = h->len;
112 u_int caplen = h->caplen;
113 const struct ip *ip;
114 u_int family;
115
116 ++infodelay;
117 ts_print(&h->ts);
118
119 memcpy((char *)&family, (char *)p, sizeof(family));
120
121 /*
122 * This isn't necessarily in our host byte order; if this is
123 * a DLT_LOOP capture, it's in network byte order, and if
124 * this is a DLT_NULL capture from a machine with the opposite
125 * byte-order, it's in the opposite byte order from ours.
126 *
127 * If the upper 16 bits aren't all zero, assume it's byte-swapped.
128 */
129 if ((family & 0xFFFF0000) != 0)
130 family = SWAPLONG(family);
131
132 /*
133 * Some printers want to get back at the link level addresses,
134 * and/or check that they're not walking off the end of the packet.
135 * Rather than pass them all the way down, we set these globals.
136 */
137 packetp = p;
138 snapend = p + caplen;
139
140 length -= NULL_HDRLEN;
141
142 ip = (struct ip *)(p + NULL_HDRLEN);
143
144 if (eflag)
145 null_print(family, length);
146
147 switch (IP_V(ip)) {
148 case 4:
149 ip_print((const u_char *)ip, length);
150 break;
151 #ifdef INET6
152 case 6:
153 ip6_print((const u_char *)ip, length);
154 break;
155 #endif /* INET6 */
156 default:
157 printf("ip v%d", IP_V(ip));
158 break;
159 }
160
161 if (xflag)
162 default_print((const u_char *)ip, caplen - NULL_HDRLEN);
163 putchar('\n');
164 --infodelay;
165 if (infoprint)
166 info(0);
167 }
168