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.
24 static const char rcsid[] _U_ =
25 "@(#) $Header: /tcpdump/master/tcpdump/print-ether.c,v 1.106 2008-02-06 10:47:53 guy Exp $ (LBL)";
32 #include <tcpdump-stdinc.h>
37 #include "interface.h"
39 #include "addrtoname.h"
40 #include "ethertype.h"
44 const struct tok ethertype_values[] = {
45 { ETHERTYPE_IP, "IPv4" },
46 { ETHERTYPE_MPLS, "MPLS unicast" },
47 { ETHERTYPE_MPLS_MULTI, "MPLS multicast" },
48 { ETHERTYPE_IPV6, "IPv6" },
49 { ETHERTYPE_8021Q, "802.1Q" },
50 { ETHERTYPE_VMAN, "VMAN" },
51 { ETHERTYPE_PUP, "PUP" },
52 { ETHERTYPE_ARP, "ARP"},
53 { ETHERTYPE_REVARP, "Reverse ARP"},
54 { ETHERTYPE_NS, "NS" },
55 { ETHERTYPE_SPRITE, "Sprite" },
56 { ETHERTYPE_TRAIL, "Trail" },
57 { ETHERTYPE_MOPDL, "MOP DL" },
58 { ETHERTYPE_MOPRC, "MOP RC" },
59 { ETHERTYPE_DN, "DN" },
60 { ETHERTYPE_LAT, "LAT" },
61 { ETHERTYPE_SCA, "SCA" },
62 { ETHERTYPE_TEB, "TEB" },
63 { ETHERTYPE_LANBRIDGE, "Lanbridge" },
64 { ETHERTYPE_DECDNS, "DEC DNS" },
65 { ETHERTYPE_DECDTS, "DEC DTS" },
66 { ETHERTYPE_VEXP, "VEXP" },
67 { ETHERTYPE_VPROD, "VPROD" },
68 { ETHERTYPE_ATALK, "Appletalk" },
69 { ETHERTYPE_AARP, "Appletalk ARP" },
70 { ETHERTYPE_IPX, "IPX" },
71 { ETHERTYPE_PPP, "PPP" },
72 { ETHERTYPE_MPCP, "MPCP" },
73 { ETHERTYPE_SLOW, "Slow Protocols" },
74 { ETHERTYPE_PPPOED, "PPPoE D" },
75 { ETHERTYPE_PPPOES, "PPPoE S" },
76 { ETHERTYPE_EAPOL, "EAPOL" },
77 { ETHERTYPE_RRCP, "RRCP" },
78 { ETHERTYPE_JUMBO, "Jumbo" },
79 { ETHERTYPE_LOOPBACK, "Loopback" },
80 { ETHERTYPE_ISO, "OSI" },
81 { ETHERTYPE_GRE_ISO, "GRE-OSI" },
82 { ETHERTYPE_CFM_OLD, "CFM (old)" },
83 { ETHERTYPE_CFM, "CFM" },
84 { ETHERTYPE_LLDP, "LLDP" },
89 ether_hdr_print(register 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);
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(const u_char *p, u_int length, u_int caplen,
126 void (*print_encap_header)(const u_char *), const u_char *encap_header_arg)
128 struct ether_header *ep;
131 u_short extracted_ether_type;
133 if (caplen < ETHER_HDRLEN || length < ETHER_HDRLEN) {
139 if (print_encap_header != NULL)
140 (*print_encap_header)(encap_header_arg);
141 ether_hdr_print(p, length);
143 orig_length = length;
145 length -= ETHER_HDRLEN;
146 caplen -= ETHER_HDRLEN;
147 ep = (struct ether_header *)p;
150 ether_type = EXTRACT_16BITS(&ep->ether_type);
154 * Is it (gag) an 802.3 encapsulation?
156 if (ether_type <= ETHERMTU) {
157 /* Try to print the LLC-layer header & higher layers */
158 if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
159 &extracted_ether_type) == 0) {
160 /* ether_type not known, print raw packet */
162 if (print_encap_header != NULL)
163 (*print_encap_header)(encap_header_arg);
164 ether_hdr_print((u_char *)ep, orig_length);
167 if (!suppress_default_print)
168 default_print(p, caplen);
170 } else if (ether_type == ETHERTYPE_8021Q) {
172 * Print VLAN information, and then go back and process
173 * the enclosed type field.
175 if (caplen < 4 || length < 4) {
180 u_int16_t tag = EXTRACT_16BITS(p);
182 printf("vlan %u, p %u%s, ",
185 (tag & 0x1000) ? ", CFI" : "");
188 ether_type = EXTRACT_16BITS(p + 2);
189 if (eflag && ether_type > ETHERMTU)
190 printf("ethertype %s, ", tok2str(ethertype_values,"0x%04x", ether_type));
195 } else if (ether_type == ETHERTYPE_JUMBO) {
197 * Alteon jumbo frames.
200 * http://tools.ietf.org/html/draft-ietf-isis-ext-eth-01
202 * which indicates that, following the type field,
203 * there's an LLC header and payload.
205 /* Try to print the LLC-layer header & higher layers */
206 if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
207 &extracted_ether_type) == 0) {
208 /* ether_type not known, print raw packet */
210 if (print_encap_header != NULL)
211 (*print_encap_header)(encap_header_arg);
212 ether_hdr_print((u_char *)ep, orig_length);
215 if (!suppress_default_print)
216 default_print(p, caplen);
219 if (ethertype_print(ether_type, p, length, caplen) == 0) {
220 /* ether_type not known, print raw packet */
222 if (print_encap_header != NULL)
223 (*print_encap_header)(encap_header_arg);
224 ether_hdr_print((u_char *)ep, orig_length);
227 if (!suppress_default_print)
228 default_print(p, caplen);
234 * This is the top level routine of the printer. 'p' points
235 * to the ether header of the packet, 'h->ts' is the timestamp,
236 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
237 * is the number of bytes actually captured.
240 ether_if_print(const struct pcap_pkthdr *h, const u_char *p)
242 ether_print(p, h->len, h->caplen, NULL, NULL);
244 return (ETHER_HDRLEN);
248 * Prints the packet payload, given an Ethernet type code for the payload's
251 * Returns non-zero if it can do so, zero if the ethertype is unknown.
255 ethertype_print(u_short ether_type, const u_char *p, u_int length, u_int caplen)
257 switch (ether_type) {
260 ip_print(gndo, p, length);
265 ip6_print(p, length);
270 case ETHERTYPE_REVARP:
271 arp_print(gndo, p, length, caplen);
275 decnet_print(p, length, caplen);
278 case ETHERTYPE_ATALK:
280 fputs("et1 ", stdout);
281 atalk_print(p, length);
285 aarp_print(p, length);
289 printf("(NOV-ETHII) ");
290 ipx_print(p, length);
294 isoclns_print(p+1, length-1, length-1);
297 case ETHERTYPE_PPPOED:
298 case ETHERTYPE_PPPOES:
299 case ETHERTYPE_PPPOED2:
300 case ETHERTYPE_PPPOES2:
301 pppoe_print(p, length);
304 case ETHERTYPE_EAPOL:
305 eap_print(gndo, p, length);
309 rrcp_print(gndo, p - 14 , length + 14);
315 ppp_print(p, length);
320 mpcp_print(p, length);
324 slow_print(p, length);
328 case ETHERTYPE_CFM_OLD:
329 cfm_print(p, length);
333 lldp_print(p, length);
336 case ETHERTYPE_LOOPBACK:
340 case ETHERTYPE_MPLS_MULTI:
341 mpls_print(p, length);
346 case ETHERTYPE_MOPRC:
347 case ETHERTYPE_MOPDL:
348 /* default_print for now */
357 * c-style: whitesmith