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.95 2005-04-06 21:32:39 mcr Exp $ (LBL)";
30 #include <tcpdump-stdinc.h>
35 #include "interface.h"
36 #include "addrtoname.h"
37 #include "ethertype.h"
42 const struct tok ethertype_values
[] = {
43 /* not really ethertypes but PIDs that are used
44 in the SNAP printer - its more convenient
45 to put them into a single tokentable */
46 { PID_RFC2684_ETH_FCS
, "Ethernet + FCS" },
47 { PID_RFC2684_ETH_NOFCS
, "Ethernet no FCS" },
48 { PID_RFC2684_802_4_FCS
, "802.4 + FCS" },
49 { PID_RFC2684_802_4_NOFCS
, "w/o FCS" },
50 { PID_RFC2684_802_5_FCS
, "Tokenring + FCS" },
51 { PID_RFC2684_802_5_NOFCS
, "Tokenring no FCS" },
52 { PID_RFC2684_FDDI_FCS
, "FDDI + FCS" },
53 { PID_RFC2684_FDDI_NOFCS
, "FDDI no FCS" },
54 { PID_RFC2684_802_6_FCS
, "802.6 + FCS" },
55 { PID_RFC2684_802_6_NOFCS
, "802.6 no FCS" },
56 { PID_RFC2684_BPDU
, "BPDU" },
57 /* the real Ethertypes */
58 { ETHERTYPE_IP
, "IPv4" },
59 { ETHERTYPE_MPLS
, "MPLS unicast" },
60 { ETHERTYPE_MPLS_MULTI
, "MPLS multicast" },
61 { ETHERTYPE_IPV6
, "IPv6" },
62 { ETHERTYPE_8021Q
, "802.1Q" },
63 { ETHERTYPE_VMAN
, "VMAN" },
64 { ETHERTYPE_PUP
, "PUP" },
65 { ETHERTYPE_ARP
, "ARP"},
66 { ETHERTYPE_REVARP
, "Reverse ARP"},
67 { ETHERTYPE_NS
, "NS" },
68 { ETHERTYPE_SPRITE
, "Sprite" },
69 { ETHERTYPE_TRAIL
, "Trail" },
70 { ETHERTYPE_MOPDL
, "MOP DL" },
71 { ETHERTYPE_MOPRC
, "MOP RC" },
72 { ETHERTYPE_DN
, "DN" },
73 { ETHERTYPE_LAT
, "LAT" },
74 { ETHERTYPE_SCA
, "SCA" },
75 { ETHERTYPE_LANBRIDGE
, "Lanbridge" },
76 { ETHERTYPE_DECDNS
, "DEC DNS" },
77 { ETHERTYPE_DECDTS
, "DEC DTS" },
78 { ETHERTYPE_VEXP
, "VEXP" },
79 { ETHERTYPE_VPROD
, "VPROD" },
80 { ETHERTYPE_ATALK
, "Appletalk" },
81 { ETHERTYPE_AARP
, "Appletalk ARP" },
82 { ETHERTYPE_IPX
, "IPX" },
83 { ETHERTYPE_PPP
, "PPP" },
84 { ETHERTYPE_PPPOED
, "PPPoE D" },
85 { ETHERTYPE_PPPOES
, "PPPoE S" },
86 { ETHERTYPE_EAPOL
, "EAPOL" },
87 { ETHERTYPE_JUMBO
, "Jumbo" },
88 { ETHERTYPE_LOOPBACK
, "Loopback" },
89 { ETHERTYPE_ISO
, "OSI" },
90 { ETHERTYPE_GRE_ISO
, "GRE-OSI" },
95 ether_hdr_print(register const u_char
*bp
, u_int length
)
97 register const struct ether_header
*ep
;
98 ep
= (const struct ether_header
*)bp
;
100 (void)printf("%s > %s",
101 etheraddr_string(ESRC(ep
)),
102 etheraddr_string(EDST(ep
)));
105 if (ntohs(ep
->ether_type
) <= ETHERMTU
)
106 (void)printf(", 802.3");
108 (void)printf(", ethertype %s (0x%04x)",
109 tok2str(ethertype_values
,"Unknown", ntohs(ep
->ether_type
)),
110 ntohs(ep
->ether_type
));
112 if (ntohs(ep
->ether_type
) <= ETHERMTU
)
113 (void)printf(", 802.3");
115 (void)printf(", %s", tok2str(ethertype_values
,"Unknown Ethertype (0x%04x)", ntohs(ep
->ether_type
)));
118 (void)printf(", length %u: ", length
);
122 ether_print(const u_char
*p
, u_int length
, u_int caplen
)
124 struct ether_header
*ep
;
126 u_short extracted_ether_type
;
128 if (caplen
< ETHER_HDRLEN
) {
134 ether_hdr_print(p
, length
);
136 length
-= ETHER_HDRLEN
;
137 caplen
-= ETHER_HDRLEN
;
138 ep
= (struct ether_header
*)p
;
141 ether_type
= ntohs(ep
->ether_type
);
144 * Is it (gag) an 802.3 encapsulation?
146 extracted_ether_type
= 0;
147 if (ether_type
<= ETHERMTU
) {
148 /* Try to print the LLC-layer header & higher layers */
149 if (llc_print(p
, length
, caplen
, ESRC(ep
), EDST(ep
),
150 &extracted_ether_type
) == 0) {
151 /* ether_type not known, print raw packet */
153 ether_hdr_print((u_char
*)ep
, length
+ ETHER_HDRLEN
);
155 if (!xflag
&& !qflag
)
156 default_print(p
, caplen
);
158 } else if (ether_encap_print(ether_type
, p
, length
, caplen
,
159 &extracted_ether_type
) == 0) {
160 /* ether_type not known, print raw packet */
162 ether_hdr_print((u_char
*)ep
, length
+ ETHER_HDRLEN
);
164 if (!xflag
&& !qflag
)
165 default_print(p
, caplen
);
170 * This is the top level routine of the printer. 'p' points
171 * to the ether header of the packet, 'h->ts' is the timestamp,
172 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
173 * is the number of bytes actually captured.
176 ether_if_print(const struct pcap_pkthdr
*h
, const u_char
*p
)
178 ether_print(p
, h
->len
, h
->caplen
);
180 return (ETHER_HDRLEN
);
184 * Prints the packet encapsulated in an Ethernet data segment
185 * (or an equivalent encapsulation), given the Ethernet type code.
187 * Returns non-zero if it can do so, zero if the ethertype is unknown.
189 * The Ethernet type code is passed through a pointer; if it was
190 * ETHERTYPE_8021Q, it gets updated to be the Ethernet type of
191 * the 802.1Q payload, for the benefit of lower layers that might
192 * want to know what it is.
196 ether_encap_print(u_short ether_type
, const u_char
*p
,
197 u_int length
, u_int caplen
, u_short
*extracted_ether_type
)
200 *extracted_ether_type
= ether_type
;
202 switch (ether_type
) {
205 ip_print(gndo
, p
, length
);
210 ip6_print(p
, length
);
215 case ETHERTYPE_REVARP
:
216 arp_print(gndo
, p
, length
, caplen
);
220 decnet_print(p
, length
, caplen
);
223 case ETHERTYPE_ATALK
:
225 fputs("et1 ", stdout
);
226 atalk_print(p
, length
);
230 aarp_print(p
, length
);
234 printf("(NOV-ETHII) ");
235 ipx_print(p
, length
);
238 case ETHERTYPE_8021Q
:
240 printf("vlan %u, p %u%s, ",
241 ntohs(*(u_int16_t
*)p
) & 0xfff,
242 ntohs(*(u_int16_t
*)p
) >> 13,
243 (ntohs(*(u_int16_t
*)p
) & 0x1000) ? ", CFI" : "");
245 ether_type
= ntohs(*(u_int16_t
*)(p
+ 2));
250 if (ether_type
> ETHERMTU
) {
252 printf("ethertype %s, ",
253 tok2str(ethertype_values
,"0x%04x", ether_type
));
257 *extracted_ether_type
= 0;
259 if (llc_print(p
, length
, caplen
, p
- 18, p
- 12,
260 extracted_ether_type
) == 0) {
261 ether_hdr_print(p
- 18, length
+ 4);
264 if (!xflag
&& !qflag
)
265 default_print(p
- 18, caplen
+ 4);
269 case ETHERTYPE_JUMBO
:
270 ether_type
= ntohs(*(u_int16_t
*)(p
));
275 if (ether_type
> ETHERMTU
) {
277 printf("ethertype %s, ",
278 tok2str(ethertype_values
,"0x%04x", ether_type
));
282 *extracted_ether_type
= 0;
284 if (llc_print(p
, length
, caplen
, p
- 16, p
- 10,
285 extracted_ether_type
) == 0) {
286 ether_hdr_print(p
- 16, length
+ 2);
289 if (!xflag
&& !qflag
)
290 default_print(p
- 16, caplen
+ 2);
295 isoclns_print(p
+1, length
-1, length
-1);
298 case ETHERTYPE_PPPOED
:
299 case ETHERTYPE_PPPOES
:
300 pppoe_print(p
, length
);
303 case ETHERTYPE_EAPOL
:
304 eap_print(gndo
, p
, length
);
310 ppp_print(p
, length
);
314 case ETHERTYPE_LOOPBACK
:
318 case ETHERTYPE_MPLS_MULTI
:
319 mpls_print(p
, length
);
324 case ETHERTYPE_MOPRC
:
325 case ETHERTYPE_MOPDL
:
326 /* default_print for now */
335 * c-style: whitesmith