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_MS_NLB_HB, "MS NLB heartbeat" },
82 { ETHERTYPE_JUMBO, "Jumbo" },
83 { ETHERTYPE_LOOPBACK, "Loopback" },
84 { ETHERTYPE_ISO, "OSI" },
85 { ETHERTYPE_GRE_ISO, "GRE-OSI" },
86 { ETHERTYPE_CFM_OLD, "CFM (old)" },
87 { ETHERTYPE_CFM, "CFM" },
88 { ETHERTYPE_LLDP, "LLDP" },
89 { ETHERTYPE_TIPC, "TIPC"},
94 ether_hdr_print(netdissect_options *ndo,
95 const u_char *bp, u_int length)
97 register const struct ether_header *ep;
100 ep = (const struct ether_header *)bp;
102 (void)ND_PRINT((ndo, "%s > %s",
103 etheraddr_string(ESRC(ep)),
104 etheraddr_string(EDST(ep))));
106 ether_type = EXTRACT_16BITS(&ep->ether_type);
107 if (!ndo->ndo_qflag) {
108 if (ether_type <= ETHERMTU)
109 (void)ND_PRINT((ndo, ", 802.3"));
111 (void)ND_PRINT((ndo, ", ethertype %s (0x%04x)",
112 tok2str(ethertype_values,"Unknown", ether_type),
115 if (ether_type <= ETHERMTU)
116 (void)ND_PRINT((ndo, ", 802.3"));
118 (void)ND_PRINT((ndo, ", %s", tok2str(ethertype_values,"Unknown Ethertype (0x%04x)", ether_type)));
121 (void)ND_PRINT((ndo, ", length %u: ", length));
125 * Print an Ethernet frame.
126 * This might be encapsulated within another frame; we might be passed
127 * a pointer to a function that can print header information for that
128 * frame's protocol, and an argument to pass to that function.
131 ether_print(netdissect_options *ndo,
132 const u_char *p, u_int length, u_int caplen,
133 void (*print_encap_header)(netdissect_options *ndo, const u_char *), const u_char *encap_header_arg)
135 struct ether_header *ep;
138 u_short extracted_ether_type;
140 if (caplen < ETHER_HDRLEN || length < ETHER_HDRLEN) {
141 ND_PRINT((ndo, "[|ether]"));
145 if (ndo->ndo_eflag) {
146 if (print_encap_header != NULL)
147 (*print_encap_header)(ndo, encap_header_arg);
148 ether_hdr_print(ndo, p, length);
150 orig_length = length;
152 length -= ETHER_HDRLEN;
153 caplen -= ETHER_HDRLEN;
154 ep = (struct ether_header *)p;
157 ether_type = EXTRACT_16BITS(&ep->ether_type);
161 * Is it (gag) an 802.3 encapsulation?
163 if (ether_type <= ETHERMTU) {
164 /* Try to print the LLC-layer header & higher layers */
165 if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
166 &extracted_ether_type) == 0) {
167 /* ether_type not known, print raw packet */
168 if (!ndo->ndo_eflag) {
169 if (print_encap_header != NULL)
170 (*print_encap_header)(ndo, encap_header_arg);
171 ether_hdr_print(ndo, (u_char *)ep, orig_length);
174 if (!ndo->ndo_suppress_default_print)
175 ndo->ndo_default_print(ndo, p, caplen);
177 } else if (ether_type == ETHERTYPE_8021Q ||
178 ether_type == ETHERTYPE_8021Q9100 ||
179 ether_type == ETHERTYPE_8021Q9200 ||
180 ether_type == ETHERTYPE_8021QinQ) {
182 * Print VLAN information, and then go back and process
183 * the enclosed type field.
185 if (caplen < 4 || length < 4) {
186 ND_PRINT((ndo, "[|vlan]"));
189 if (ndo->ndo_eflag) {
190 u_int16_t tag = EXTRACT_16BITS(p);
192 ND_PRINT((ndo, "vlan %u, p %u%s, ",
195 (tag & 0x1000) ? ", CFI" : ""));
198 ether_type = EXTRACT_16BITS(p + 2);
199 if (ndo->ndo_eflag && ether_type > ETHERMTU)
200 ND_PRINT((ndo, "ethertype %s, ", tok2str(ethertype_values,"0x%04x", ether_type)));
205 } else if (ether_type == ETHERTYPE_JUMBO) {
207 * Alteon jumbo frames.
210 * http://tools.ietf.org/html/draft-ietf-isis-ext-eth-01
212 * which indicates that, following the type field,
213 * there's an LLC header and payload.
215 /* Try to print the LLC-layer header & higher layers */
216 if (llc_print(p, length, caplen, ESRC(ep), EDST(ep),
217 &extracted_ether_type) == 0) {
218 /* ether_type not known, print raw packet */
219 if (!ndo->ndo_eflag) {
220 if (print_encap_header != NULL)
221 (*print_encap_header)(ndo, encap_header_arg);
222 ether_hdr_print(ndo, (u_char *)ep, orig_length);
225 if (!ndo->ndo_suppress_default_print)
226 ndo->ndo_default_print(ndo, p, caplen);
229 if (ethertype_print(ndo, ether_type, p, length, caplen) == 0) {
230 /* ether_type not known, print raw packet */
231 if (!ndo->ndo_eflag) {
232 if (print_encap_header != NULL)
233 (*print_encap_header)(ndo, encap_header_arg);
234 ether_hdr_print(ndo, (u_char *)ep, orig_length);
237 if (!ndo->ndo_suppress_default_print)
238 ndo->ndo_default_print(ndo, p, caplen);
244 * This is the top level routine of the printer. 'p' points
245 * to the ether header of the packet, 'h->ts' is the timestamp,
246 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
247 * is the number of bytes actually captured.
250 ether_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
253 ether_print(ndo, p, h->len, h->caplen, NULL, NULL);
255 return (ETHER_HDRLEN);
259 * This is the top level routine of the printer. 'p' points
260 * to the ether header of the packet, 'h->ts' is the timestamp,
261 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
262 * is the number of bytes actually captured.
264 * This is for DLT_NETANALYZER, which has a 4-byte pseudo-header
265 * before the Ethernet header.
268 netanalyzer_if_print(netdissect_options *ndo, const struct pcap_pkthdr *h,
272 * Fail if we don't have enough data for the Hilscher pseudo-header.
274 if (h->len < 4 || h->caplen < 4) {
275 printf("[|netanalyzer]");
279 /* Skip the pseudo-header. */
280 ether_print(ndo, p + 4, h->len - 4, h->caplen - 4, NULL, NULL);
282 return (4 + ETHER_HDRLEN);
286 * This is the top level routine of the printer. 'p' points
287 * to the ether header of the packet, 'h->ts' is the timestamp,
288 * 'h->len' is the length of the packet off the wire, and 'h->caplen'
289 * is the number of bytes actually captured.
291 * This is for DLT_NETANALYZER_TRANSPARENT, which has a 4-byte
292 * pseudo-header, a 7-byte Ethernet preamble, and a 1-byte Ethernet SOF
293 * before the Ethernet header.
296 netanalyzer_transparent_if_print(netdissect_options *ndo,
297 const struct pcap_pkthdr *h,
301 * Fail if we don't have enough data for the Hilscher pseudo-header,
304 if (h->len < 12 || h->caplen < 12) {
305 printf("[|netanalyzer-transparent]");
309 /* Skip the pseudo-header, preamble, and SOF. */
310 ether_print(ndo, p + 12, h->len - 12, h->caplen - 12, NULL, NULL);
312 return (12 + ETHER_HDRLEN);
316 * Prints the packet payload, given an Ethernet type code for the payload's
319 * Returns non-zero if it can do so, zero if the ethertype is unknown.
323 ethertype_print(netdissect_options *ndo,
324 u_short ether_type, const u_char *p,
325 u_int length, u_int caplen)
327 switch (ether_type) {
330 ip_print(ndo, p, length);
335 ip6_print(ndo, p, length);
340 case ETHERTYPE_REVARP:
341 arp_print(ndo, p, length, caplen);
345 decnet_print(/*ndo,*/p, length, caplen);
348 case ETHERTYPE_ATALK:
350 fputs("et1 ", stdout);
351 atalk_print(/*ndo,*/p, length);
355 aarp_print(/*ndo,*/p, length);
359 ND_PRINT((ndo, "(NOV-ETHII) "));
360 ipx_print(/*ndo,*/p, length);
364 isoclns_print(/*ndo,*/p+1, length-1, length-1);
367 case ETHERTYPE_PPPOED:
368 case ETHERTYPE_PPPOES:
369 case ETHERTYPE_PPPOED2:
370 case ETHERTYPE_PPPOES2:
371 pppoe_print(/*ndo,*/p, length);
374 case ETHERTYPE_EAPOL:
375 eap_print(ndo, p, length);
379 rrcp_print(ndo, p - 14 , length + 14);
385 ppp_print(/*ndo,*/p, length);
390 mpcp_print(/*ndo,*/p, length);
394 slow_print(/*ndo,*/p, length);
398 case ETHERTYPE_CFM_OLD:
399 cfm_print(/*ndo,*/p, length);
403 lldp_print(/*ndo,*/p, length);
406 case ETHERTYPE_LOOPBACK:
410 case ETHERTYPE_MPLS_MULTI:
411 mpls_print(/*ndo,*/p, length);
415 tipc_print(ndo, p, length, caplen);
418 case ETHERTYPE_MS_NLB_HB:
419 msnlb_print(ndo, p, length);
424 case ETHERTYPE_MOPRC:
425 case ETHERTYPE_MOPDL:
426 /* default_print for now */
435 * c-style: whitesmith