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
26 static const char rcsid
[] _U_
=
27 "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.72 2007-03-19 15:14:14 hannes Exp $";
34 #include <tcpdump-stdinc.h>
39 #include "interface.h"
40 #include "addrtoname.h"
41 #include "extract.h" /* must come after interface.h */
44 #include "ethertype.h"
47 static struct tok llc_values
[] = {
48 { LLCSAP_NULL
, "Null" },
49 { LLCSAP_GLOBAL
, "Global" },
50 { LLCSAP_8021B_I
, "802.1B I" },
51 { LLCSAP_8021B_G
, "802.1B G" },
53 { LLCSAP_SNA
, "SNA" },
54 { LLCSAP_PROWAYNM
, "ProWay NM" },
55 { LLCSAP_8021D
, "STP" },
56 { LLCSAP_RS511
, "RS511" },
57 { LLCSAP_ISO8208
, "ISO8208" },
58 { LLCSAP_PROWAY
, "ProWay" },
59 { LLCSAP_SNAP
, "SNAP" },
60 { LLCSAP_IPX
, "IPX" },
61 { LLCSAP_NETBEUI
, "NetBeui" },
62 { LLCSAP_ISONS
, "OSI" },
66 static struct tok llc_cmd_values
[] = {
73 { LLC_SABME
, "sabme" },
78 static const struct tok llc_flag_values
[] = {
80 { LLC_GSAP
, "Response" },
81 { LLC_U_POLL
, "Poll" },
82 { LLC_GSAP
|LLC_U_POLL
, "Final" },
83 { LLC_IS_POLL
, "Poll" },
84 { LLC_GSAP
|LLC_IS_POLL
, "Final" },
89 static const struct tok llc_ig_flag_values
[] = {
96 static const struct tok llc_supervisory_values
[] = {
97 { 0, "Receiver Ready" },
98 { 1, "Receiver not Ready" },
104 static const struct tok cisco_values
[] = {
105 { PID_CISCO_CDP
, "CDP" },
106 { PID_CISCO_VTP
, "VTP" },
107 { PID_CISCO_DTP
, "DTP" },
108 { PID_CISCO_UDLD
, "UDLD" },
112 static const struct tok bridged_values
[] = {
113 { PID_RFC2684_ETH_FCS
, "Ethernet + FCS" },
114 { PID_RFC2684_ETH_NOFCS
, "Ethernet w/o FCS" },
115 { PID_RFC2684_802_4_FCS
, "802.4 + FCS" },
116 { PID_RFC2684_802_4_NOFCS
, "802.4 w/o FCS" },
117 { PID_RFC2684_802_5_FCS
, "Token Ring + FCS" },
118 { PID_RFC2684_802_5_NOFCS
, "Token Ring w/o FCS" },
119 { PID_RFC2684_FDDI_FCS
, "FDDI + FCS" },
120 { PID_RFC2684_FDDI_NOFCS
, "FDDI w/o FCS" },
121 { PID_RFC2684_802_6_FCS
, "802.6 + FCS" },
122 { PID_RFC2684_802_6_NOFCS
, "802.6 w/o FCS" },
123 { PID_RFC2684_BPDU
, "BPDU" },
127 static const struct tok null_values
[] = {
133 const struct tok
*tok
;
136 static const struct oui_tok oui_to_tok
[] = {
137 { OUI_ENCAP_ETHER
, ethertype_values
},
138 { OUI_CISCO_90
, ethertype_values
}, /* uses some Ethertype values */
139 { OUI_APPLETALK
, ethertype_values
}, /* uses some Ethertype values */
140 { OUI_CISCO
, cisco_values
},
141 { OUI_RFC2684
, bridged_values
}, /* bridged, RFC 2427 FR or RFC 2864 ATM */
146 * Returns non-zero IFF it succeeds in printing the header
149 llc_print(const u_char
*p
, u_int length
, u_int caplen
,
150 const u_char
*esrc
, const u_char
*edst
, u_short
*extracted_ethertype
)
152 u_int8_t dsap_field
, dsap
, ssap_field
, ssap
;
157 *extracted_ethertype
= 0;
160 (void)printf("[|llc]");
161 default_print((u_char
*)p
, caplen
);
166 ssap_field
= *(p
+ 1);
169 * OK, what type of LLC frame is this? The length
170 * of the control field depends on that - I frames
171 * have a two-byte control field, and U frames have
172 * a one-byte control field.
175 if ((control
& LLC_U_FMT
) == LLC_U_FMT
) {
182 * The control field in I and S frames is
186 (void)printf("[|llc]");
187 default_print((u_char
*)p
, caplen
);
192 * ...and is little-endian.
194 control
= EXTRACT_LE_16BITS(p
+ 2);
198 if (ssap_field
== LLCSAP_GLOBAL
&& dsap_field
== LLCSAP_GLOBAL
) {
200 * This is an Ethernet_802.3 IPX frame; it has an
201 * 802.3 header (i.e., an Ethernet header where the
202 * type/length field is <= ETHERMTU, i.e. it's a length
203 * field, not a type field), but has no 802.2 header -
204 * the IPX packet starts right after the Ethernet header,
205 * with a signature of two bytes of 0xFF (which is
208 * (It might also have been an Ethernet_802.3 IPX at
209 * one time, but got bridged onto another network,
210 * such as an 802.11 network; this has appeared in at
211 * least one capture file.)
215 printf("IPX 802.3: ");
217 ipx_print(p
, length
);
221 dsap
= dsap_field
& ~LLC_IG
;
222 ssap
= ssap_field
& ~LLC_GSAP
;
225 printf("LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
226 tok2str(llc_values
, "Unknown", dsap
),
228 tok2str(llc_ig_flag_values
, "Unknown", dsap_field
& LLC_IG
),
229 tok2str(llc_values
, "Unknown", ssap
),
231 tok2str(llc_flag_values
, "Unknown", ssap_field
& LLC_GSAP
));
234 printf(", ctrl 0x%02x: ", control
);
236 printf(", ctrl 0x%04x: ", control
);
240 if (ssap
== LLCSAP_8021D
&& dsap
== LLCSAP_8021D
&&
242 stp_print(p
+3, length
-3);
246 if (ssap
== LLCSAP_IP
&& dsap
== LLCSAP_IP
&&
248 ip_print(gndo
, p
+4, length
-4);
252 if (ssap
== LLCSAP_IPX
&& dsap
== LLCSAP_IPX
&&
255 * This is an Ethernet_802.2 IPX frame, with an 802.3
256 * header and an 802.2 LLC header with the source and
257 * destination SAPs being the IPX SAP.
259 * Skip DSAP, LSAP, and control field.
262 printf("IPX 802.2: ");
264 ipx_print(p
+3, length
-3);
268 #ifdef TCPDUMP_DO_SMB
269 if (ssap
== LLCSAP_NETBEUI
&& dsap
== LLCSAP_NETBEUI
270 && (!(control
& LLC_S_FMT
) || control
== LLC_U_FMT
)) {
272 * we don't actually have a full netbeui parser yet, but the
273 * smb parser can handle many smb-in-netbeui packets, which
274 * is very useful, so we call that
276 * We don't call it for S frames, however, just I frames
277 * (which are frames that don't have the low-order bit,
278 * LLC_S_FMT, set in the first byte of the control field)
279 * and UI frames (whose control field is just 3, LLC_U_FMT).
283 * Skip the LLC header.
294 netbeui_print(control
, p
, length
);
298 if (ssap
== LLCSAP_ISONS
&& dsap
== LLCSAP_ISONS
299 && control
== LLC_UI
) {
300 isoclns_print(p
+ 3, length
- 3, caplen
- 3);
304 if (ssap
== LLCSAP_SNAP
&& dsap
== LLCSAP_SNAP
305 && control
== LLC_UI
) {
307 * XXX - what *is* the right bridge pad value here?
308 * Does anybody ever bridge one form of LAN traffic
309 * over a networking type that uses 802.2 LLC?
311 ret
= snap_print(p
+3, length
-3, caplen
-3, extracted_ethertype
,
319 if (esrc
== NULL
|| edst
== NULL
)
320 (void)printf("%s ", tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
322 (void)printf("%s > %s %s ",
323 etheraddr_string(esrc
),
324 etheraddr_string(edst
),
325 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
327 if (esrc
== NULL
|| edst
== NULL
)
328 (void)printf("%s > %s ",
329 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
330 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
332 (void)printf("%s %s > %s %s ",
333 etheraddr_string(esrc
),
334 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
335 etheraddr_string(edst
),
336 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
341 printf("Unnumbered, %s, Flags [%s], length %u",
342 tok2str(llc_cmd_values
, "%02x", LLC_U_CMD(control
)),
343 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_U_POLL
)),
350 if ((control
& ~LLC_U_POLL
) == LLC_XID
) {
351 if (*p
== LLC_XID_FI
) {
352 printf(": %02x %02x", p
[1], p
[2]);
359 if ((control
& LLC_S_FMT
) == LLC_S_FMT
) {
360 (void)printf("Supervisory, %s, rcv seq %u, Flags [%s], length %u",
361 tok2str(llc_supervisory_values
,"?",LLC_S_CMD(control
)),
363 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
366 (void)printf("Information, send seq %u, rcv seq %u, Flags [%s], length %u",
369 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
380 snap_print(const u_char
*p
, u_int length
, u_int caplen
,
381 u_short
*extracted_ethertype
, u_int bridge_pad
)
388 orgcode
= EXTRACT_24BITS(p
);
389 et
= EXTRACT_16BITS(p
+ 3);
392 const struct tok
*tok
= null_values
;
393 const struct oui_tok
*otp
;
395 for (otp
= &oui_to_tok
[0]; otp
->tok
!= NULL
; otp
++) {
396 if (otp
->oui
== orgcode
) {
401 (void)printf("oui %s (0x%06x), %s %s (0x%04x): ",
402 tok2str(oui_values
, "Unknown", orgcode
),
404 (orgcode
== 0x000000 ? "ethertype" : "pid"),
405 tok2str(tok
, "Unknown", et
),
413 case OUI_ENCAP_ETHER
:
416 * This is an encapsulated Ethernet packet,
417 * or a packet bridged by some piece of
418 * Cisco hardware; the protocol ID is
419 * an Ethernet protocol type.
421 ret
= ether_encap_print(et
, p
, length
, caplen
,
422 extracted_ethertype
);
428 if (et
== ETHERTYPE_ATALK
) {
430 * No, I have no idea why Apple used one
431 * of their own OUIs, rather than
432 * 0x000000, and an Ethernet packet
433 * type, for Appletalk data packets,
434 * but used 0x000000 and an Ethernet
435 * packet type for AARP packets.
437 ret
= ether_encap_print(et
, p
, length
, caplen
,
438 extracted_ethertype
);
447 cdp_print(p
, length
, caplen
);
450 udld_print(p
, length
);
459 case PID_RFC2684_ETH_FCS
:
460 case PID_RFC2684_ETH_NOFCS
:
462 * XXX - remove the last two bytes for
463 * PID_RFC2684_ETH_FCS?
468 TCHECK2(*p
, bridge_pad
);
469 caplen
-= bridge_pad
;
470 length
-= bridge_pad
;
474 * What remains is an Ethernet packet.
476 ether_print(p
, length
, caplen
);
479 case PID_RFC2684_802_5_FCS
:
480 case PID_RFC2684_802_5_NOFCS
:
482 * XXX - remove the last two bytes for
483 * PID_RFC2684_ETH_FCS?
486 * Skip the padding, but not the Access
489 TCHECK2(*p
, bridge_pad
);
490 caplen
-= bridge_pad
;
491 length
-= bridge_pad
;
495 * What remains is an 802.5 Token Ring
498 token_print(p
, length
, caplen
);
501 case PID_RFC2684_FDDI_FCS
:
502 case PID_RFC2684_FDDI_NOFCS
:
504 * XXX - remove the last two bytes for
505 * PID_RFC2684_ETH_FCS?
510 TCHECK2(*p
, bridge_pad
+ 1);
511 caplen
-= bridge_pad
+ 1;
512 length
-= bridge_pad
+ 1;
516 * What remains is an FDDI packet.
518 fddi_print(p
, length
, caplen
);
521 case PID_RFC2684_BPDU
:
522 stp_print(p
, length
);
529 (void)printf("[|snap]");
536 * c-style: whitesmith