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)";
28 #define NETDISSECT_REWORKED
33 #include <tcpdump-stdinc.h>
38 #include "interface.h"
40 #include "addrtoname.h"
41 #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_8021Q9100, "802.1Q-9100" },
51 { ETHERTYPE_8021QinQ, "802.1Q-QinQ" },
52 { ETHERTYPE_8021Q9200, "802.1Q-9200" },
53 { ETHERTYPE_VMAN, "VMAN" },
54 { ETHERTYPE_PUP, "PUP" },
55 { ETHERTYPE_ARP, "ARP"},
56 { ETHERTYPE_REVARP, "Reverse ARP"},
57 { ETHERTYPE_NS, "NS" },
58 { ETHERTYPE_SPRITE, "Sprite" },
59 { ETHERTYPE_TRAIL, "Trail" },
60 { ETHERTYPE_MOPDL, "MOP DL" },
61 { ETHERTYPE_MOPRC, "MOP RC" },
62 { ETHERTYPE_DN, "DN" },
63 { ETHERTYPE_LAT, "LAT" },
64 { ETHERTYPE_SCA, "SCA" },
65 { ETHERTYPE_TEB, "TEB" },
66 { ETHERTYPE_LANBRIDGE, "Lanbridge" },
67 { ETHERTYPE_DECDNS, "DEC DNS" },
68 { ETHERTYPE_DECDTS, "DEC DTS" },
69 { ETHERTYPE_VEXP, "VEXP" },
70 { ETHERTYPE_VPROD, "VPROD" },
71 { ETHERTYPE_ATALK, "Appletalk" },
72 { ETHERTYPE_AARP, "Appletalk ARP" },
73 { ETHERTYPE_IPX, "IPX" },
74 { ETHERTYPE_PPP, "PPP" },
75 { ETHERTYPE_MPCP, "MPCP" },
76 { ETHERTYPE_SLOW, "Slow Protocols" },
77 { ETHERTYPE_PPPOED, "PPPoE D" },
78 { ETHERTYPE_PPPOES, "PPPoE S" },
79 { ETHERTYPE_EAPOL, "EAPOL" },
80 { ETHERTYPE_RRCP, "RRCP" },
81 { ETHERTYPE_JUMBO, "Jumbo" },
82 { ETHERTYPE_LOOPBACK, "Loopback" },
83 { ETHERTYPE_ISO, "OSI" },
84 { ETHERTYPE_GRE_ISO, "GRE-OSI" },
85 { ETHERTYPE_CFM_OLD, "CFM (old)" },
86 { ETHERTYPE_CFM, "CFM" },
87 { ETHERTYPE_LLDP, "LLDP" },
88 { ETHERTYPE_TIPC, "TIPC"},
93 ether_hdr_print(netdissect_options *ndo,
94 const u_char *bp, u_int length)
96 register const struct ether_header *ep;
99 ep = (const struct ether_header *)bp;
101 (void)ND_PRINT((ndo, "%s > %s",
102 etheraddr_string(ESRC(ep)),
103 etheraddr_string(EDST(ep))));
105 ether_type = EXTRACT_16BITS(&ep->ether_type);
106 if (!ndo->ndo_qflag) {
107 if (ether_type <= ETHERMTU)
108 (void)ND_PRINT((ndo, ", 802.3"));
110 (void)ND_PRINT((ndo, ", ethertype %s (0x%04x)",
111 tok2str(ethertype_values,"Unknown", ether_type),
114 if (ether_type <= ETHERMTU)
115 (void)ND_PRINT((ndo, ", 802.3"));
117 (void)ND_PRINT((ndo, ", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", ether_type)));
120 (void)ND_PRINT((ndo, ", length %u: ", length));
124 * Print an Ethernet frame.
125 * This might be encapsulated within another frame; we might be passed
126 * a pointer to a function that can print header information for that
127 * frame's protocol, and an argument to pass to that function.
130 ether_print(netdissect_options *ndo,
131 const u_char *p, u_int length, u_int caplen,
132 void (*print_encap_header)(netdissect_options *ndo, const u_char *), const u_char *encap_header_arg)
134 struct ether_header *ep;
137 u_short extracted_ether_type;
139 if (caplen < ETHER_HDRLEN || length < ETHER_HDRLEN) {
140 ND_PRINT((ndo, "[|ether]"));
144 if (ndo->ndo_eflag) {
145 if (print_encap_header != NULL)
146 (*print_encap_header)(ndo, encap_header_arg);
147 ether_hdr_print(ndo, p, length);
149 orig_length = length;
151 length -= ETHER_HDRLEN;
152 caplen -= ETHER_HDRLEN;
153 ep = (struct ether_header *)p;
156 ether_type = EXTRACT_16BITS(&ep->ether_type);
160 * Is it (gag) an 802.3 encapsulation?
162 if (ether_type <= ETHERMTU) {
163 /* Try to print the LLC-layer header & higher layers */
164 if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
165 &extracted_ether_type) == 0) {
166 /* ether_type not known, print raw packet */
167 if (!ndo->ndo_eflag) {
168 if (print_encap_header != NULL)
169 (*print_encap_header)(ndo, encap_header_arg);
170 ether_hdr_print(ndo, (u_char *)ep, orig_length);
173 if (!ndo->ndo_suppress_default_print)
174 ndo->ndo_default_print(ndo, p, caplen);
176 } else if (ether_type == ETHERTYPE_8021Q ||
177 ether_type == ETHERTYPE_8021Q9100 ||
178 ether_type == ETHERTYPE_8021Q9200 ||
179 ether_type == ETHERTYPE_8021QinQ) {
181 * Print VLAN information, and then go back and process
182 * the enclosed type field.
184 if (caplen < 4 || length < 4) {
185 ND_PRINT((ndo, "[|vlan]"));
188 if (ndo->ndo_eflag) {
189 u_int16_t tag = EXTRACT_16BITS(p);
191 ND_PRINT((ndo, "vlan %u, p %u%s, ",
194 (tag & 0x1000) ? ", CFI" : ""));
197 ether_type = EXTRACT_16BITS(p + 2);
198 if (ndo->ndo_eflag && ether_type > ETHERMTU)
199 ND_PRINT((ndo, "ethertype %s, ", tok2str(ethertype_values,"0x%04x", ether_type)));
204 } else if (ether_type == ETHERTYPE_JUMBO) {
206 * Alteon jumbo frames.
209 * http://tools.ietf.org/html/draft-ietf-isis-ext-eth-01
211 * which indicates that, following the type field,
212 * there's an LLC header and payload.
214 /* Try to print the LLC-layer header & higher layers */
215 if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
216 &extracted_ether_type) == 0) {
217 /* ether_type not known, print raw packet */
218 if (!ndo->ndo_eflag) {
219 if (print_encap_header != NULL)
220 (*print_encap_header)(ndo, encap_header_arg);
221 ether_hdr_print(ndo, (u_char *)ep, orig_length);
224 if (!ndo->ndo_suppress_default_print)
225 ndo->ndo_default_print(ndo, p, caplen);
228 if (ethertype_print(ndo, ether_type, p, length, caplen) == 0) {
229 /* ether_type not known, print raw packet */
230 if (!ndo->ndo_eflag) {
231 if (print_encap_header != NULL)
232 (*print_encap_header)(ndo, encap_header_arg);
233 ether_hdr_print(ndo, (u_char *)ep, orig_length);
236 if (!ndo->ndo_suppress_default_print)
237 ndo->ndo_default_print(ndo, p, caplen);
243 * This is the top level routine of the printer. 'p' points
244 * to the ether header of the packet, 'h->ts' is the timestamp,
245 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
246 * is the number of bytes actually captured.
249 ether_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
252 ether_print(ndo, p, h->len, h->caplen, NULL, NULL);
254 return (ETHER_HDRLEN);
258 * This is the top level routine of the printer. 'p' points
259 * to the ether header of the packet, 'h->ts' is the timestamp,
260 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
261 * is the number of bytes actually captured.
263 * This is for DLT_NETANALYZER, which has a 4-byte pseudo-header
264 * before the Ethernet header.
267 netanalyzer_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
271 * Fail if we don't have enough data for the Hilscher pseudo-header.
273 if (h->len < 4 || h->caplen < 4) {
274 printf("[|netanalyzer]");
278 /* Skip the pseudo-header. */
279 ether_print(ndo, p + 4, h->len - 4, h->caplen - 4, NULL, NULL);
281 return (4 + ETHER_HDRLEN);
285 * This is the top level routine of the printer. 'p' points
286 * to the ether header of the packet, 'h->ts' is the timestamp,
287 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
288 * is the number of bytes actually captured.
290 * This is for DLT_NETANALYZER_TRANSPARENT, which has a 4-byte
291 * pseudo-header, a 7-byte Ethernet preamble, and a 1-byte Ethernet SOF
292 * before the Ethernet header.
295 netanalyzer_transparent_if_print(netdissect_options *ndo,
296 const struct pcap_pkthdr *h,
300 * Fail if we don't have enough data for the Hilscher pseudo-header,
303 if (h->len < 12 || h->caplen < 12) {
304 printf("[|netanalyzer-transparent]");
308 /* Skip the pseudo-header, preamble, and SOF. */
309 ether_print(ndo, p + 12, h->len - 12, h->caplen - 12, NULL, NULL);
311 return (12 + ETHER_HDRLEN);
315 * Prints the packet payload, given an Ethernet type code for the payload's
318 * Returns non-zero if it can do so, zero if the ethertype is unknown.
322 ethertype_print(netdissect_options *ndo,
323 u_short ether_type, const u_char *p,
324 u_int length, u_int caplen)
326 switch (ether_type) {
329 ip_print(ndo, p, length);
334 ip6_print(ndo, p, length);
339 case ETHERTYPE_REVARP:
340 arp_print(ndo, p, length, caplen);
344 decnet_print(/*ndo,*/p, length, caplen);
347 case ETHERTYPE_ATALK:
349 fputs("et1 ", stdout);
350 atalk_print(/*ndo,*/p, length);
354 aarp_print(/*ndo,*/p, length);
358 ND_PRINT((ndo, "(NOV-ETHII) "));
359 ipx_print(/*ndo,*/p, length);
363 isoclns_print(/*ndo,*/p+1, length-1, length-1);
366 case ETHERTYPE_PPPOED:
367 case ETHERTYPE_PPPOES:
368 case ETHERTYPE_PPPOED2:
369 case ETHERTYPE_PPPOES2:
370 pppoe_print(/*ndo,*/p, length);
373 case ETHERTYPE_EAPOL:
374 eap_print(ndo, p, length);
378 rrcp_print(ndo, p - 14 , length + 14);
384 ppp_print(/*ndo,*/p, length);
389 mpcp_print(/*ndo,*/p, length);
393 slow_print(/*ndo,*/p, length);
397 case ETHERTYPE_CFM_OLD:
398 cfm_print(/*ndo,*/p, length);
402 lldp_print(/*ndo,*/p, length);
405 case ETHERTYPE_LOOPBACK:
409 case ETHERTYPE_MPLS_MULTI:
410 mpls_print(/*ndo,*/p, length);
414 tipc_print(ndo, p, length, caplen);
419 case ETHERTYPE_MOPRC:
420 case ETHERTYPE_MOPDL:
421 /* default_print for now */
430 * c-style: whitesmith