2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
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.
21 * Code by Matt Thomas, Digital Equipment Corporation
22 * with an awful lot of hacking by Jeffrey Mogul, DECWRL
29 #include <tcpdump-stdinc.h>
34 #include "interface.h"
35 #include "addrtoname.h"
36 #include "extract.h" /* must come after interface.h */
39 #include "ethertype.h"
42 static const struct tok llc_values
[] = {
43 { LLCSAP_NULL
, "Null" },
44 { LLCSAP_GLOBAL
, "Global" },
45 { LLCSAP_8021B_I
, "802.1B I" },
46 { LLCSAP_8021B_G
, "802.1B G" },
48 { LLCSAP_SNA
, "SNA" },
49 { LLCSAP_PROWAYNM
, "ProWay NM" },
50 { LLCSAP_8021D
, "STP" },
51 { LLCSAP_RS511
, "RS511" },
52 { LLCSAP_ISO8208
, "ISO8208" },
53 { LLCSAP_PROWAY
, "ProWay" },
54 { LLCSAP_SNAP
, "SNAP" },
55 { LLCSAP_IPX
, "IPX" },
56 { LLCSAP_NETBEUI
, "NetBeui" },
57 { LLCSAP_ISONS
, "OSI" },
61 static const struct tok llc_cmd_values
[] = {
68 { LLC_SABME
, "sabme" },
73 static const struct tok llc_flag_values
[] = {
75 { LLC_GSAP
, "Response" },
76 { LLC_U_POLL
, "Poll" },
77 { LLC_GSAP
|LLC_U_POLL
, "Final" },
78 { LLC_IS_POLL
, "Poll" },
79 { LLC_GSAP
|LLC_IS_POLL
, "Final" },
84 static const struct tok llc_ig_flag_values
[] = {
91 static const struct tok llc_supervisory_values
[] = {
92 { 0, "Receiver Ready" },
93 { 1, "Receiver not Ready" },
99 static const struct tok cisco_values
[] = {
100 { PID_CISCO_CDP
, "CDP" },
101 { PID_CISCO_VTP
, "VTP" },
102 { PID_CISCO_DTP
, "DTP" },
103 { PID_CISCO_UDLD
, "UDLD" },
104 { PID_CISCO_PVST
, "PVST" },
105 { PID_CISCO_VLANBRIDGE
, "VLAN Bridge" },
109 static const struct tok bridged_values
[] = {
110 { PID_RFC2684_ETH_FCS
, "Ethernet + FCS" },
111 { PID_RFC2684_ETH_NOFCS
, "Ethernet w/o FCS" },
112 { PID_RFC2684_802_4_FCS
, "802.4 + FCS" },
113 { PID_RFC2684_802_4_NOFCS
, "802.4 w/o FCS" },
114 { PID_RFC2684_802_5_FCS
, "Token Ring + FCS" },
115 { PID_RFC2684_802_5_NOFCS
, "Token Ring w/o FCS" },
116 { PID_RFC2684_FDDI_FCS
, "FDDI + FCS" },
117 { PID_RFC2684_FDDI_NOFCS
, "FDDI w/o FCS" },
118 { PID_RFC2684_802_6_FCS
, "802.6 + FCS" },
119 { PID_RFC2684_802_6_NOFCS
, "802.6 w/o FCS" },
120 { PID_RFC2684_BPDU
, "BPDU" },
124 static const struct tok null_values
[] = {
130 const struct tok
*tok
;
133 static const struct oui_tok oui_to_tok
[] = {
134 { OUI_ENCAP_ETHER
, ethertype_values
},
135 { OUI_CISCO_90
, ethertype_values
}, /* uses some Ethertype values */
136 { OUI_APPLETALK
, ethertype_values
}, /* uses some Ethertype values */
137 { OUI_CISCO
, cisco_values
},
138 { OUI_RFC2684
, bridged_values
}, /* bridged, RFC 2427 FR or RFC 2864 ATM */
143 * Returns non-zero IFF it succeeds in printing the header
146 llc_print(const u_char
*p
, u_int length
, u_int caplen
,
147 const u_char
*esrc
, const u_char
*edst
, u_short
*extracted_ethertype
)
149 u_int8_t dsap_field
, dsap
, ssap_field
, ssap
;
154 *extracted_ethertype
= 0;
157 (void)printf("[|llc]");
158 default_print((u_char
*)p
, caplen
);
163 ssap_field
= *(p
+ 1);
166 * OK, what type of LLC frame is this? The length
167 * of the control field depends on that - I frames
168 * have a two-byte control field, and U frames have
169 * a one-byte control field.
172 if ((control
& LLC_U_FMT
) == LLC_U_FMT
) {
179 * The control field in I and S frames is
183 (void)printf("[|llc]");
184 default_print((u_char
*)p
, caplen
);
189 * ...and is little-endian.
191 control
= EXTRACT_LE_16BITS(p
+ 2);
195 if (ssap_field
== LLCSAP_GLOBAL
&& dsap_field
== LLCSAP_GLOBAL
) {
197 * This is an Ethernet_802.3 IPX frame; it has an
198 * 802.3 header (i.e., an Ethernet header where the
199 * type/length field is <= ETHERMTU, i.e. it's a length
200 * field, not a type field), but has no 802.2 header -
201 * the IPX packet starts right after the Ethernet header,
202 * with a signature of two bytes of 0xFF (which is
205 * (It might also have been an Ethernet_802.3 IPX at
206 * one time, but got bridged onto another network,
207 * such as an 802.11 network; this has appeared in at
208 * least one capture file.)
212 printf("IPX 802.3: ");
214 ipx_print(gndo
, p
, length
);
218 dsap
= dsap_field
& ~LLC_IG
;
219 ssap
= ssap_field
& ~LLC_GSAP
;
222 printf("LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
223 tok2str(llc_values
, "Unknown", dsap
),
225 tok2str(llc_ig_flag_values
, "Unknown", dsap_field
& LLC_IG
),
226 tok2str(llc_values
, "Unknown", ssap
),
228 tok2str(llc_flag_values
, "Unknown", ssap_field
& LLC_GSAP
));
231 printf(", ctrl 0x%02x: ", control
);
233 printf(", ctrl 0x%04x: ", control
);
237 if (ssap
== LLCSAP_8021D
&& dsap
== LLCSAP_8021D
&&
239 stp_print(p
+3, length
-3);
243 if (ssap
== LLCSAP_IP
&& dsap
== LLCSAP_IP
&&
245 ip_print(gndo
, p
+4, length
-4);
249 if (ssap
== LLCSAP_IPX
&& dsap
== LLCSAP_IPX
&&
252 * This is an Ethernet_802.2 IPX frame, with an 802.3
253 * header and an 802.2 LLC header with the source and
254 * destination SAPs being the IPX SAP.
256 * Skip DSAP, LSAP, and control field.
259 printf("IPX 802.2: ");
261 ipx_print(gndo
, p
+3, length
-3);
265 #ifdef TCPDUMP_DO_SMB
266 if (ssap
== LLCSAP_NETBEUI
&& dsap
== LLCSAP_NETBEUI
267 && (!(control
& LLC_S_FMT
) || control
== LLC_U_FMT
)) {
269 * we don't actually have a full netbeui parser yet, but the
270 * smb parser can handle many smb-in-netbeui packets, which
271 * is very useful, so we call that
273 * We don't call it for S frames, however, just I frames
274 * (which are frames that don't have the low-order bit,
275 * LLC_S_FMT, set in the first byte of the control field)
276 * and UI frames (whose control field is just 3, LLC_U_FMT).
280 * Skip the LLC header.
289 netbeui_print(control
, p
, length
);
293 if (ssap
== LLCSAP_ISONS
&& dsap
== LLCSAP_ISONS
294 && control
== LLC_UI
) {
295 isoclns_print(p
+ 3, length
- 3, caplen
- 3);
299 if (ssap
== LLCSAP_SNAP
&& dsap
== LLCSAP_SNAP
300 && control
== LLC_UI
) {
302 * XXX - what *is* the right bridge pad value here?
303 * Does anybody ever bridge one form of LAN traffic
304 * over a networking type that uses 802.2 LLC?
306 ret
= snap_print(p
+3, length
-3, caplen
-3, 2);
313 if (esrc
== NULL
|| edst
== NULL
)
314 (void)printf("%s ", tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
316 (void)printf("%s > %s %s ",
317 etheraddr_string(esrc
),
318 etheraddr_string(edst
),
319 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
321 if (esrc
== NULL
|| edst
== NULL
)
322 (void)printf("%s > %s ",
323 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
324 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
326 (void)printf("%s %s > %s %s ",
327 etheraddr_string(esrc
),
328 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
329 etheraddr_string(edst
),
330 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
335 printf("Unnumbered, %s, Flags [%s], length %u",
336 tok2str(llc_cmd_values
, "%02x", LLC_U_CMD(control
)),
337 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_U_POLL
)),
342 if ((control
& ~LLC_U_POLL
) == LLC_XID
) {
343 if (*p
== LLC_XID_FI
) {
344 printf(": %02x %02x", p
[1], p
[2]);
348 if ((control
& LLC_S_FMT
) == LLC_S_FMT
) {
349 (void)printf("Supervisory, %s, rcv seq %u, Flags [%s], length %u",
350 tok2str(llc_supervisory_values
,"?",LLC_S_CMD(control
)),
352 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
355 (void)printf("Information, send seq %u, rcv seq %u, Flags [%s], length %u",
358 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
366 snap_print(const u_char
*p
, u_int length
, u_int caplen
, u_int bridge_pad
)
373 orgcode
= EXTRACT_24BITS(p
);
374 et
= EXTRACT_16BITS(p
+ 3);
377 const struct tok
*tok
= null_values
;
378 const struct oui_tok
*otp
;
380 for (otp
= &oui_to_tok
[0]; otp
->tok
!= NULL
; otp
++) {
381 if (otp
->oui
== orgcode
) {
386 (void)printf("oui %s (0x%06x), %s %s (0x%04x): ",
387 tok2str(oui_values
, "Unknown", orgcode
),
389 (orgcode
== 0x000000 ? "ethertype" : "pid"),
390 tok2str(tok
, "Unknown", et
),
398 case OUI_ENCAP_ETHER
:
401 * This is an encapsulated Ethernet packet,
402 * or a packet bridged by some piece of
403 * Cisco hardware; the protocol ID is
404 * an Ethernet protocol type.
406 ret
= ethertype_print(gndo
, et
, p
, length
, caplen
);
412 if (et
== ETHERTYPE_ATALK
) {
414 * No, I have no idea why Apple used one
415 * of their own OUIs, rather than
416 * 0x000000, and an Ethernet packet
417 * type, for Appletalk data packets,
418 * but used 0x000000 and an Ethernet
419 * packet type for AARP packets.
421 ret
= ethertype_print(gndo
, et
, p
, length
, caplen
);
430 cdp_print(p
, length
, caplen
);
433 dtp_print(gndo
, p
, length
);
436 udld_print(gndo
, p
, length
);
439 vtp_print(p
, length
);
442 case PID_CISCO_VLANBRIDGE
:
443 stp_print(p
, length
);
452 case PID_RFC2684_ETH_FCS
:
453 case PID_RFC2684_ETH_NOFCS
:
455 * XXX - remove the last two bytes for
456 * PID_RFC2684_ETH_FCS?
461 TCHECK2(*p
, bridge_pad
);
462 caplen
-= bridge_pad
;
463 length
-= bridge_pad
;
467 * What remains is an Ethernet packet.
469 ether_print(gndo
, p
, length
, caplen
, NULL
, NULL
);
472 case PID_RFC2684_802_5_FCS
:
473 case PID_RFC2684_802_5_NOFCS
:
475 * XXX - remove the last two bytes for
476 * PID_RFC2684_ETH_FCS?
479 * Skip the padding, but not the Access
482 TCHECK2(*p
, bridge_pad
);
483 caplen
-= bridge_pad
;
484 length
-= bridge_pad
;
488 * What remains is an 802.5 Token Ring
491 token_print(p
, length
, caplen
);
494 case PID_RFC2684_FDDI_FCS
:
495 case PID_RFC2684_FDDI_NOFCS
:
497 * XXX - remove the last two bytes for
498 * PID_RFC2684_ETH_FCS?
503 TCHECK2(*p
, bridge_pad
+ 1);
504 caplen
-= bridge_pad
+ 1;
505 length
-= bridge_pad
+ 1;
509 * What remains is an FDDI packet.
511 fddi_print(p
, length
, caplen
);
514 case PID_RFC2684_BPDU
:
515 stp_print(p
, length
);
522 (void)printf("[|snap]");
529 * c-style: whitesmith