2 * Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997, 2000
3 * The Regents of the University of California. All rights reserved.
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
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.
22 static const char rcsid
[] _U_
=
23 "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.106 2008-02-06 10:47:53 guy Exp $ (LBL)";
26 #define NETDISSECT_REWORKED
31 #include <tcpdump-stdinc.h>
36 #include "interface.h"
38 #include "addrtoname.h"
39 #include "ethertype.h"
43 const struct tok ethertype_values
[] = {
44 { ETHERTYPE_IP
, "IPv4" },
45 { ETHERTYPE_MPLS
, "MPLS unicast" },
46 { ETHERTYPE_MPLS_MULTI
, "MPLS multicast" },
47 { ETHERTYPE_IPV6
, "IPv6" },
48 { ETHERTYPE_8021Q
, "802.1Q" },
49 { ETHERTYPE_VMAN
, "VMAN" },
50 { ETHERTYPE_PUP
, "PUP" },
51 { ETHERTYPE_ARP
, "ARP"},
52 { ETHERTYPE_REVARP
, "Reverse ARP"},
53 { ETHERTYPE_NS
, "NS" },
54 { ETHERTYPE_SPRITE
, "Sprite" },
55 { ETHERTYPE_TRAIL
, "Trail" },
56 { ETHERTYPE_MOPDL
, "MOP DL" },
57 { ETHERTYPE_MOPRC
, "MOP RC" },
58 { ETHERTYPE_DN
, "DN" },
59 { ETHERTYPE_LAT
, "LAT" },
60 { ETHERTYPE_SCA
, "SCA" },
61 { ETHERTYPE_TEB
, "TEB" },
62 { ETHERTYPE_LANBRIDGE
, "Lanbridge" },
63 { ETHERTYPE_DECDNS
, "DEC DNS" },
64 { ETHERTYPE_DECDTS
, "DEC DTS" },
65 { ETHERTYPE_VEXP
, "VEXP" },
66 { ETHERTYPE_VPROD
, "VPROD" },
67 { ETHERTYPE_ATALK
, "Appletalk" },
68 { ETHERTYPE_AARP
, "Appletalk ARP" },
69 { ETHERTYPE_IPX
, "IPX" },
70 { ETHERTYPE_PPP
, "PPP" },
71 { ETHERTYPE_MPCP
, "MPCP" },
72 { ETHERTYPE_SLOW
, "Slow Protocols" },
73 { ETHERTYPE_PPPOED
, "PPPoE D" },
74 { ETHERTYPE_PPPOES
, "PPPoE S" },
75 { ETHERTYPE_EAPOL
, "EAPOL" },
76 { ETHERTYPE_RRCP
, "RRCP" },
77 { ETHERTYPE_JUMBO
, "Jumbo" },
78 { ETHERTYPE_LOOPBACK
, "Loopback" },
79 { ETHERTYPE_ISO
, "OSI" },
80 { ETHERTYPE_GRE_ISO
, "GRE-OSI" },
81 { ETHERTYPE_CFM_OLD
, "CFM (old)" },
82 { ETHERTYPE_CFM
, "CFM" },
83 { ETHERTYPE_LLDP
, "LLDP" },
88 ether_hdr_print(netdissect_options
*ndo
,
89 const u_char
*bp
, u_int length
)
91 register const struct ether_header
*ep
;
94 ep
= (const struct ether_header
*)bp
;
96 (void)printf("%s > %s",
97 etheraddr_string(ESRC(ep
)),
98 etheraddr_string(EDST(ep
)));
100 ether_type
= EXTRACT_16BITS(&ep
->ether_type
);
101 if (!ndo
->ndo_qflag
) {
102 if (ether_type
<= ETHERMTU
)
103 (void)printf(", 802.3");
105 (void)printf(", ethertype %s (0x%04x)",
106 tok2str(ethertype_values
,"Unknown", ether_type
),
109 if (ether_type
<= ETHERMTU
)
110 (void)printf(", 802.3");
112 (void)printf(", %s", tok2str(ethertype_values
,"Unknown Ethertype (0x%04x)", ether_type
));
115 (void)printf(", length %u: ", length
);
119 * Print an Ethernet frame.
120 * This might be encapsulated within another frame; we might be passed
121 * a pointer to a function that can print header information for that
122 * frame's protocol, and an argument to pass to that function.
125 ether_print(netdissect_options
*ndo
,
126 const u_char
*p
, u_int length
, u_int caplen
,
127 void (*print_encap_header
)(netdissect_options
*ndo
, const u_char
*), const u_char
*encap_header_arg
)
129 struct ether_header
*ep
;
132 u_short extracted_ether_type
;
134 if (caplen
< ETHER_HDRLEN
|| length
< ETHER_HDRLEN
) {
139 if (ndo
->ndo_eflag
) {
140 if (print_encap_header
!= NULL
)
141 (*print_encap_header
)(ndo
, encap_header_arg
);
142 ether_hdr_print(ndo
, p
, length
);
144 orig_length
= length
;
146 length
-= ETHER_HDRLEN
;
147 caplen
-= ETHER_HDRLEN
;
148 ep
= (struct ether_header
*)p
;
151 ether_type
= EXTRACT_16BITS(&ep
->ether_type
);
155 * Is it (gag) an 802.3 encapsulation?
157 if (ether_type
<= ETHERMTU
) {
158 /* Try to print the LLC-layer header & higher layers */
159 if (llc_print(p
, length
, caplen
, ESRC(ep
), EDST(ep
),
160 &extracted_ether_type
) == 0) {
161 /* ether_type not known, print raw packet */
162 if (!ndo
->ndo_eflag
) {
163 if (print_encap_header
!= NULL
)
164 (*print_encap_header
)(ndo
, encap_header_arg
);
165 ether_hdr_print(ndo
, (u_char
*)ep
, orig_length
);
168 if (!ndo
->ndo_suppress_default_print
)
169 ndo
->ndo_default_print(ndo
, p
, caplen
);
171 } else if (ether_type
== ETHERTYPE_8021Q
) {
173 * Print VLAN information, and then go back and process
174 * the enclosed type field.
176 if (caplen
< 4 || length
< 4) {
180 if (ndo
->ndo_eflag
) {
181 u_int16_t tag
= EXTRACT_16BITS(p
);
183 printf("vlan %u, p %u%s, ",
186 (tag
& 0x1000) ? ", CFI" : "");
189 ether_type
= EXTRACT_16BITS(p
+ 2);
190 if (ndo
->ndo_eflag
&& ether_type
> ETHERMTU
)
191 printf("ethertype %s, ", tok2str(ethertype_values
,"0x%04x", ether_type
));
196 } else if (ether_type
== ETHERTYPE_JUMBO
) {
198 * Alteon jumbo frames.
201 * http://tools.ietf.org/html/draft-ietf-isis-ext-eth-01
203 * which indicates that, following the type field,
204 * there's an LLC header and payload.
206 /* Try to print the LLC-layer header & higher layers */
207 if (llc_print(p
, length
, caplen
, ESRC(ep
), EDST(ep
),
208 &extracted_ether_type
) == 0) {
209 /* ether_type not known, print raw packet */
210 if (!ndo
->ndo_eflag
) {
211 if (print_encap_header
!= NULL
)
212 (*print_encap_header
)(ndo
, encap_header_arg
);
213 ether_hdr_print(ndo
, (u_char
*)ep
, orig_length
);
216 if (!ndo
->ndo_suppress_default_print
)
217 ndo
->ndo_default_print(ndo
, p
, caplen
);
220 if (ethertype_print(ndo
, ether_type
, p
, length
, caplen
) == 0) {
221 /* ether_type not known, print raw packet */
222 if (!ndo
->ndo_eflag
) {
223 if (print_encap_header
!= NULL
)
224 (*print_encap_header
)(ndo
, encap_header_arg
);
225 ether_hdr_print(ndo
, (u_char
*)ep
, orig_length
);
228 if (!ndo
->ndo_suppress_default_print
)
229 ndo
->ndo_default_print(ndo
, p
, caplen
);
235 * This is the top level routine of the printer. 'p' points
236 * to the ether header of the packet, 'h->ts' is the timestamp,
237 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
238 * is the number of bytes actually captured.
241 ether_if_print(netdissect_options
*ndo
, const struct pcap_pkthdr
*h
,
244 ether_print(ndo
, p
, h
->len
, h
->caplen
, NULL
, NULL
);
246 return (ETHER_HDRLEN
);
250 * Prints the packet payload, given an Ethernet type code for the payload's
253 * Returns non-zero if it can do so, zero if the ethertype is unknown.
257 ethertype_print(netdissect_options
*ndo
,
258 u_short ether_type
, const u_char
*p
,
259 u_int length
, u_int caplen
)
261 switch (ether_type
) {
264 ip_print(ndo
, p
, length
);
269 ip6_print(/*ndo,*/ p
, length
);
274 case ETHERTYPE_REVARP
:
275 arp_print(ndo
, p
, length
, caplen
);
279 decnet_print(/*ndo,*/p
, length
, caplen
);
282 case ETHERTYPE_ATALK
:
284 fputs("et1 ", stdout
);
285 atalk_print(/*ndo,*/p
, length
);
289 aarp_print(/*ndo,*/p
, length
);
293 printf("(NOV-ETHII) ");
294 ipx_print(/*ndo,*/p
, length
);
298 isoclns_print(/*ndo,*/p
+1, length
-1, length
-1);
301 case ETHERTYPE_PPPOED
:
302 case ETHERTYPE_PPPOES
:
303 case ETHERTYPE_PPPOED2
:
304 case ETHERTYPE_PPPOES2
:
305 pppoe_print(/*ndo,*/p
, length
);
308 case ETHERTYPE_EAPOL
:
309 eap_print(ndo
, p
, length
);
313 rrcp_print(ndo
, p
- 14 , length
+ 14);
319 ppp_print(/*ndo,*/p
, length
);
324 mpcp_print(/*ndo,*/p
, length
);
328 slow_print(/*ndo,*/p
, length
);
332 case ETHERTYPE_CFM_OLD
:
333 cfm_print(/*ndo,*/p
, length
);
337 lldp_print(/*ndo,*/p
, length
);
340 case ETHERTYPE_LOOPBACK
:
344 case ETHERTYPE_MPLS_MULTI
:
345 mpls_print(/*ndo,*/p
, length
);
350 case ETHERTYPE_MOPRC
:
351 case ETHERTYPE_MOPDL
:
352 /* default_print for now */
361 * c-style: whitesmith