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)";
30 #include <tcpdump-stdinc.h>
35 #include "interface.h"
37 #include "addrtoname.h"
38 #include "ethertype.h"
42 const struct tok ethertype_values
[] = {
43 { ETHERTYPE_IP
, "IPv4" },
44 { ETHERTYPE_MPLS
, "MPLS unicast" },
45 { ETHERTYPE_MPLS_MULTI
, "MPLS multicast" },
46 { ETHERTYPE_IPV6
, "IPv6" },
47 { ETHERTYPE_8021Q
, "802.1Q" },
48 { ETHERTYPE_VMAN
, "VMAN" },
49 { ETHERTYPE_PUP
, "PUP" },
50 { ETHERTYPE_ARP
, "ARP"},
51 { ETHERTYPE_REVARP
, "Reverse ARP"},
52 { ETHERTYPE_NS
, "NS" },
53 { ETHERTYPE_SPRITE
, "Sprite" },
54 { ETHERTYPE_TRAIL
, "Trail" },
55 { ETHERTYPE_MOPDL
, "MOP DL" },
56 { ETHERTYPE_MOPRC
, "MOP RC" },
57 { ETHERTYPE_DN
, "DN" },
58 { ETHERTYPE_LAT
, "LAT" },
59 { ETHERTYPE_SCA
, "SCA" },
60 { ETHERTYPE_TEB
, "TEB" },
61 { ETHERTYPE_LANBRIDGE
, "Lanbridge" },
62 { ETHERTYPE_DECDNS
, "DEC DNS" },
63 { ETHERTYPE_DECDTS
, "DEC DTS" },
64 { ETHERTYPE_VEXP
, "VEXP" },
65 { ETHERTYPE_VPROD
, "VPROD" },
66 { ETHERTYPE_ATALK
, "Appletalk" },
67 { ETHERTYPE_AARP
, "Appletalk ARP" },
68 { ETHERTYPE_IPX
, "IPX" },
69 { ETHERTYPE_PPP
, "PPP" },
70 { ETHERTYPE_MPCP
, "MPCP" },
71 { ETHERTYPE_SLOW
, "Slow Protocols" },
72 { ETHERTYPE_PPPOED
, "PPPoE D" },
73 { ETHERTYPE_PPPOES
, "PPPoE S" },
74 { ETHERTYPE_EAPOL
, "EAPOL" },
75 { ETHERTYPE_RRCP
, "RRCP" },
76 { ETHERTYPE_JUMBO
, "Jumbo" },
77 { ETHERTYPE_LOOPBACK
, "Loopback" },
78 { ETHERTYPE_ISO
, "OSI" },
79 { ETHERTYPE_GRE_ISO
, "GRE-OSI" },
80 { ETHERTYPE_CFM_OLD
, "CFM (old)" },
81 { ETHERTYPE_CFM
, "CFM" },
82 { ETHERTYPE_LLDP
, "LLDP" },
87 ether_hdr_print(register const u_char
*bp
, u_int length
)
89 register const struct ether_header
*ep
;
92 ep
= (const struct ether_header
*)bp
;
94 (void)printf("%s > %s",
95 etheraddr_string(ESRC(ep
)),
96 etheraddr_string(EDST(ep
)));
98 ether_type
= EXTRACT_16BITS(&ep
->ether_type
);
100 if (ether_type
<= ETHERMTU
)
101 (void)printf(", 802.3");
103 (void)printf(", ethertype %s (0x%04x)",
104 tok2str(ethertype_values
,"Unknown", ether_type
),
107 if (ether_type
<= ETHERMTU
)
108 (void)printf(", 802.3");
110 (void)printf(", %s", tok2str(ethertype_values
,"Unknown Ethertype (0x%04x)", ether_type
));
113 (void)printf(", length %u: ", length
);
117 * Print an Ethernet frame.
118 * This might be encapsulated within another frame; we might be passed
119 * a pointer to a function that can print header information for that
120 * frame's protocol, and an argument to pass to that function.
123 ether_print(const u_char
*p
, u_int length
, u_int caplen
,
124 void (*print_encap_header
)(const u_char
*), const u_char
*encap_header_arg
)
126 struct ether_header
*ep
;
129 u_short extracted_ether_type
;
131 if (caplen
< ETHER_HDRLEN
|| length
< ETHER_HDRLEN
) {
137 if (print_encap_header
!= NULL
)
138 (*print_encap_header
)(encap_header_arg
);
139 ether_hdr_print(p
, length
);
141 orig_length
= length
;
143 length
-= ETHER_HDRLEN
;
144 caplen
-= ETHER_HDRLEN
;
145 ep
= (struct ether_header
*)p
;
148 ether_type
= EXTRACT_16BITS(&ep
->ether_type
);
152 * Is it (gag) an 802.3 encapsulation?
154 if (ether_type
<= ETHERMTU
) {
155 /* Try to print the LLC-layer header & higher layers */
156 if (llc_print(p
, length
, caplen
, ESRC(ep
), EDST(ep
),
157 &extracted_ether_type
) == 0) {
158 /* ether_type not known, print raw packet */
160 if (print_encap_header
!= NULL
)
161 (*print_encap_header
)(encap_header_arg
);
162 ether_hdr_print((u_char
*)ep
, orig_length
);
165 if (!suppress_default_print
)
166 default_print(p
, caplen
);
168 } else if (ether_type
== ETHERTYPE_8021Q
) {
170 * Print VLAN information, and then go back and process
171 * the enclosed type field.
173 if (caplen
< 4 || length
< 4) {
178 u_int16_t tag
= EXTRACT_16BITS(p
);
180 printf("vlan %u, p %u%s, ",
183 (tag
& 0x1000) ? ", CFI" : "");
186 ether_type
= EXTRACT_16BITS(p
+ 2);
187 if (eflag
&& ether_type
> ETHERMTU
)
188 printf("ethertype %s, ", tok2str(ethertype_values
,"0x%04x", ether_type
));
193 } else if (ether_type
== ETHERTYPE_JUMBO
) {
195 * Alteon jumbo frames.
198 * http://tools.ietf.org/html/draft-ietf-isis-ext-eth-01
200 * which indicates that, following the type field,
201 * there's an LLC header and payload.
203 /* Try to print the LLC-layer header & higher layers */
204 if (llc_print(p
, length
, caplen
, ESRC(ep
), EDST(ep
),
205 &extracted_ether_type
) == 0) {
206 /* ether_type not known, print raw packet */
208 if (print_encap_header
!= NULL
)
209 (*print_encap_header
)(encap_header_arg
);
210 ether_hdr_print((u_char
*)ep
, orig_length
);
213 if (!suppress_default_print
)
214 default_print(p
, caplen
);
217 if (ethertype_print(ether_type
, p
, length
, caplen
) == 0) {
218 /* ether_type not known, print raw packet */
220 if (print_encap_header
!= NULL
)
221 (*print_encap_header
)(encap_header_arg
);
222 ether_hdr_print((u_char
*)ep
, orig_length
);
225 if (!suppress_default_print
)
226 default_print(p
, caplen
);
232 * This is the top level routine of the printer. 'p' points
233 * to the ether header of the packet, 'h->ts' is the timestamp,
234 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
235 * is the number of bytes actually captured.
238 ether_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
240 ether_print(p
, h
->len
, h
->caplen
, NULL
, NULL
);
242 return (ETHER_HDRLEN
);
246 * Prints the packet payload, given an Ethernet type code for the payload's
249 * Returns non-zero if it can do so, zero if the ethertype is unknown.
253 ethertype_print(u_short ether_type
, const u_char
*p
, u_int length
, u_int caplen
)
255 switch (ether_type
) {
258 ip_print(gndo
, p
, length
);
263 ip6_print(p
, length
);
268 case ETHERTYPE_REVARP
:
269 arp_print(gndo
, p
, length
, caplen
);
273 decnet_print(p
, length
, caplen
);
276 case ETHERTYPE_ATALK
:
278 fputs("et1 ", stdout
);
279 atalk_print(p
, length
);
283 aarp_print(p
, length
);
287 printf("(NOV-ETHII) ");
288 ipx_print(p
, length
);
292 isoclns_print(p
+1, length
-1, length
-1);
295 case ETHERTYPE_PPPOED
:
296 case ETHERTYPE_PPPOES
:
297 case ETHERTYPE_PPPOED2
:
298 case ETHERTYPE_PPPOES2
:
299 pppoe_print(p
, length
);
302 case ETHERTYPE_EAPOL
:
303 eap_print(gndo
, p
, length
);
307 rrcp_print(gndo
, p
- 14 , length
+ 14);
313 ppp_print(p
, length
);
318 mpcp_print(p
, length
);
322 slow_print(p
, length
);
326 case ETHERTYPE_CFM_OLD
:
327 cfm_print(p
, length
);
331 lldp_print(p
, length
);
334 case ETHERTYPE_LOOPBACK
:
338 case ETHERTYPE_MPLS_MULTI
:
339 mpls_print(p
, length
);
344 case ETHERTYPE_MOPRC
:
345 case ETHERTYPE_MOPDL
:
346 /* default_print for now */
355 * c-style: whitesmith