1 | #include <machine/rtems-bsd-user-space.h> |
---|
2 | |
---|
3 | /* |
---|
4 | * Copyright (c) 1991, 1993, 1994, 1995, 1996, 1997 |
---|
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 | * $FreeBSD$ |
---|
24 | */ |
---|
25 | |
---|
26 | #ifndef lint |
---|
27 | static const char rcsid[] _U_ = |
---|
28 | "@(#) $Header: /tcpdump/master/tcpdump/print-null.c,v 1.57 2006-03-23 14:58:44 hannes Exp $ (LBL)"; |
---|
29 | #endif |
---|
30 | |
---|
31 | #ifdef HAVE_CONFIG_H |
---|
32 | #include "config.h" |
---|
33 | #endif |
---|
34 | |
---|
35 | #include <tcpdump-stdinc.h> |
---|
36 | |
---|
37 | #include <pcap.h> |
---|
38 | #include <stdio.h> |
---|
39 | #include <string.h> |
---|
40 | |
---|
41 | #include "interface.h" |
---|
42 | #include "addrtoname.h" |
---|
43 | |
---|
44 | #include "ip.h" |
---|
45 | #ifdef INET6 |
---|
46 | #include "ip6.h" |
---|
47 | #endif |
---|
48 | #include "af.h" |
---|
49 | |
---|
50 | /* |
---|
51 | * The DLT_NULL packet header is 4 bytes long. It contains a host-byte-order |
---|
52 | * 32-bit integer that specifies the family, e.g. AF_INET. |
---|
53 | * |
---|
54 | * Note here that "host" refers to the host on which the packets were |
---|
55 | * captured; that isn't necessarily *this* host. |
---|
56 | * |
---|
57 | * The OpenBSD DLT_LOOP packet header is the same, except that the integer |
---|
58 | * is in network byte order. |
---|
59 | */ |
---|
60 | #define NULL_HDRLEN 4 |
---|
61 | |
---|
62 | /* |
---|
63 | * Byte-swap a 32-bit number. |
---|
64 | * ("htonl()" or "ntohl()" won't work - we want to byte-swap even on |
---|
65 | * big-endian platforms.) |
---|
66 | */ |
---|
67 | #define SWAPLONG(y) \ |
---|
68 | ((((y)&0xff)<<24) | (((y)&0xff00)<<8) | (((y)&0xff0000)>>8) | (((y)>>24)&0xff)) |
---|
69 | |
---|
70 | static inline void |
---|
71 | null_hdr_print(u_int family, u_int length) |
---|
72 | { |
---|
73 | if (!qflag) { |
---|
74 | (void)printf("AF %s (%u)", |
---|
75 | tok2str(bsd_af_values,"Unknown",family),family); |
---|
76 | } else { |
---|
77 | (void)printf("%s", |
---|
78 | tok2str(bsd_af_values,"Unknown AF %u",family)); |
---|
79 | } |
---|
80 | |
---|
81 | (void)printf(", length %u: ", length); |
---|
82 | } |
---|
83 | |
---|
84 | /* |
---|
85 | * This is the top level routine of the printer. 'p' points |
---|
86 | * to the ether header of the packet, 'h->ts' is the timestamp, |
---|
87 | * 'h->len' is the length of the packet off the wire, and 'h->caplen' |
---|
88 | * is the number of bytes actually captured. |
---|
89 | */ |
---|
90 | u_int |
---|
91 | null_if_print(const struct pcap_pkthdr *h, const u_char *p) |
---|
92 | { |
---|
93 | u_int length = h->len; |
---|
94 | u_int caplen = h->caplen; |
---|
95 | u_int family; |
---|
96 | |
---|
97 | if (caplen < NULL_HDRLEN) { |
---|
98 | printf("[|null]"); |
---|
99 | return (NULL_HDRLEN); |
---|
100 | } |
---|
101 | |
---|
102 | memcpy((char *)&family, (char *)p, sizeof(family)); |
---|
103 | |
---|
104 | /* |
---|
105 | * This isn't necessarily in our host byte order; if this is |
---|
106 | * a DLT_LOOP capture, it's in network byte order, and if |
---|
107 | * this is a DLT_NULL capture from a machine with the opposite |
---|
108 | * byte-order, it's in the opposite byte order from ours. |
---|
109 | * |
---|
110 | * If the upper 16 bits aren't all zero, assume it's byte-swapped. |
---|
111 | */ |
---|
112 | if ((family & 0xFFFF0000) != 0) |
---|
113 | family = SWAPLONG(family); |
---|
114 | |
---|
115 | if (eflag) |
---|
116 | null_hdr_print(family, length); |
---|
117 | |
---|
118 | length -= NULL_HDRLEN; |
---|
119 | caplen -= NULL_HDRLEN; |
---|
120 | p += NULL_HDRLEN; |
---|
121 | |
---|
122 | switch (family) { |
---|
123 | |
---|
124 | case BSD_AFNUM_INET: |
---|
125 | ip_print(gndo, p, length); |
---|
126 | break; |
---|
127 | |
---|
128 | #ifdef INET6 |
---|
129 | case BSD_AFNUM_INET6_BSD: |
---|
130 | case BSD_AFNUM_INET6_FREEBSD: |
---|
131 | case BSD_AFNUM_INET6_DARWIN: |
---|
132 | ip6_print(gndo, p, length); |
---|
133 | break; |
---|
134 | #endif |
---|
135 | |
---|
136 | case BSD_AFNUM_ISO: |
---|
137 | isoclns_print(p, length, caplen); |
---|
138 | break; |
---|
139 | |
---|
140 | case BSD_AFNUM_APPLETALK: |
---|
141 | atalk_print(p, length); |
---|
142 | break; |
---|
143 | |
---|
144 | case BSD_AFNUM_IPX: |
---|
145 | ipx_print(p, length); |
---|
146 | break; |
---|
147 | |
---|
148 | default: |
---|
149 | /* unknown AF_ value */ |
---|
150 | if (!eflag) |
---|
151 | null_hdr_print(family, length + NULL_HDRLEN); |
---|
152 | if (!suppress_default_print) |
---|
153 | default_print(p, caplen); |
---|
154 | } |
---|
155 | |
---|
156 | return (NULL_HDRLEN); |
---|
157 | } |
---|
158 | |
---|
159 | /* |
---|
160 | * Local Variables: |
---|
161 | * c-style: whitesmith |
---|
162 | * c-basic-offset: 8 |
---|
163 | * End: |
---|
164 | */ |
---|