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.61.2.10 2007/02/08 07:07:51 guy 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" },
111 static const struct tok bridged_values
[] = {
112 { PID_RFC2684_ETH_FCS
, "Ethernet + FCS" },
113 { PID_RFC2684_ETH_NOFCS
, "Ethernet w/o FCS" },
114 { PID_RFC2684_802_4_FCS
, "802.4 + FCS" },
115 { PID_RFC2684_802_4_NOFCS
, "802.4 w/o FCS" },
116 { PID_RFC2684_802_5_FCS
, "Token Ring + FCS" },
117 { PID_RFC2684_802_5_NOFCS
, "Token Ring w/o FCS" },
118 { PID_RFC2684_FDDI_FCS
, "FDDI + FCS" },
119 { PID_RFC2684_FDDI_NOFCS
, "FDDI w/o FCS" },
120 { PID_RFC2684_802_6_FCS
, "802.6 + FCS" },
121 { PID_RFC2684_802_6_NOFCS
, "802.6 w/o FCS" },
122 { PID_RFC2684_BPDU
, "BPDU" },
126 static const struct tok null_values
[] = {
132 const struct tok
*tok
;
135 static const struct oui_tok oui_to_tok
[] = {
136 { OUI_ENCAP_ETHER
, ethertype_values
},
137 { OUI_CISCO_90
, ethertype_values
}, /* uses some Ethertype values */
138 { OUI_APPLETALK
, ethertype_values
}, /* uses some Ethertype values */
139 { OUI_CISCO
, cisco_values
},
140 { OUI_RFC2684
, bridged_values
}, /* bridged, RFC 2427 FR or RFC 2864 ATM */
145 * Returns non-zero IFF it succeeds in printing the header
148 llc_print(const u_char
*p
, u_int length
, u_int caplen
,
149 const u_char
*esrc
, const u_char
*edst
, u_short
*extracted_ethertype
)
151 u_int8_t dsap_field
, dsap
, ssap_field
, ssap
;
156 *extracted_ethertype
= 0;
159 (void)printf("[|llc]");
160 default_print((u_char
*)p
, caplen
);
165 ssap_field
= *(p
+ 1);
168 * OK, what type of LLC frame is this? The length
169 * of the control field depends on that - I frames
170 * have a two-byte control field, and U frames have
171 * a one-byte control field.
174 if ((control
& LLC_U_FMT
) == LLC_U_FMT
) {
181 * The control field in I and S frames is
185 (void)printf("[|llc]");
186 default_print((u_char
*)p
, caplen
);
191 * ...and is little-endian.
193 control
= EXTRACT_LE_16BITS(p
+ 2);
197 if (ssap_field
== LLCSAP_GLOBAL
&& dsap_field
== LLCSAP_GLOBAL
) {
199 * This is an Ethernet_802.3 IPX frame; it has an
200 * 802.3 header (i.e., an Ethernet header where the
201 * type/length field is <= ETHERMTU, i.e. it's a length
202 * field, not a type field), but has no 802.2 header -
203 * the IPX packet starts right after the Ethernet header,
204 * with a signature of two bytes of 0xFF (which is
207 * (It might also have been an Ethernet_802.3 IPX at
208 * one time, but got bridged onto another network,
209 * such as an 802.11 network; this has appeared in at
210 * least one capture file.)
214 printf("IPX 802.3: ");
216 ipx_print(p
, length
);
220 dsap
= dsap_field
& ~LLC_IG
;
221 ssap
= ssap_field
& ~LLC_GSAP
;
224 printf("LLC, dsap %s (0x%02x) %s, ssap %s (0x%02x) %s",
225 tok2str(llc_values
, "Unknown", dsap
),
227 tok2str(llc_ig_flag_values
, "Unknown", dsap_field
& LLC_IG
),
228 tok2str(llc_values
, "Unknown", ssap
),
230 tok2str(llc_flag_values
, "Unknown", ssap_field
& LLC_GSAP
));
233 printf(", ctrl 0x%02x: ", control
);
235 printf(", ctrl 0x%04x: ", control
);
239 if (ssap
== LLCSAP_8021D
&& dsap
== LLCSAP_8021D
&&
241 stp_print(p
+3, length
-3);
245 if (ssap
== LLCSAP_IP
&& dsap
== LLCSAP_IP
&&
247 ip_print(gndo
, p
+4, length
-4);
251 if (ssap
== LLCSAP_IPX
&& dsap
== LLCSAP_IPX
&&
254 * This is an Ethernet_802.2 IPX frame, with an 802.3
255 * header and an 802.2 LLC header with the source and
256 * destination SAPs being the IPX SAP.
258 * Skip DSAP, LSAP, and control field.
261 printf("IPX 802.2: ");
263 ipx_print(p
+3, length
-3);
267 #ifdef TCPDUMP_DO_SMB
268 if (ssap
== LLCSAP_NETBEUI
&& dsap
== LLCSAP_NETBEUI
269 && (!(control
& LLC_S_FMT
) || control
== LLC_U_FMT
)) {
271 * we don't actually have a full netbeui parser yet, but the
272 * smb parser can handle many smb-in-netbeui packets, which
273 * is very useful, so we call that
275 * We don't call it for S frames, however, just I frames
276 * (which are frames that don't have the low-order bit,
277 * LLC_S_FMT, set in the first byte of the control field)
278 * and UI frames (whose control field is just 3, LLC_U_FMT).
282 * Skip the LLC header.
293 netbeui_print(control
, p
, length
);
297 if (ssap
== LLCSAP_ISONS
&& dsap
== LLCSAP_ISONS
298 && control
== LLC_UI
) {
299 isoclns_print(p
+ 3, length
- 3, caplen
- 3);
303 if (ssap
== LLCSAP_SNAP
&& dsap
== LLCSAP_SNAP
304 && control
== LLC_UI
) {
306 * XXX - what *is* the right bridge pad value here?
307 * Does anybody ever bridge one form of LAN traffic
308 * over a networking type that uses 802.2 LLC?
310 ret
= snap_print(p
+3, length
-3, caplen
-3, extracted_ethertype
,
318 if (esrc
== NULL
|| edst
== NULL
)
319 (void)printf("%s ", tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
321 (void)printf("%s > %s %s ",
322 etheraddr_string(esrc
),
323 etheraddr_string(edst
),
324 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
326 if (esrc
== NULL
|| edst
== NULL
)
327 (void)printf("%s > %s ",
328 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
329 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
331 (void)printf("%s %s > %s %s ",
332 etheraddr_string(esrc
),
333 tok2str(llc_values
, "Unknown SSAP 0x%02x", ssap
),
334 etheraddr_string(edst
),
335 tok2str(llc_values
, "Unknown DSAP 0x%02x", dsap
));
340 printf("Unnumbered, %s, Flags [%s], length %u",
341 tok2str(llc_cmd_values
, "%02x", LLC_U_CMD(control
)),
342 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_U_POLL
)),
349 if ((control
& ~LLC_U_POLL
) == LLC_XID
) {
350 if (*p
== LLC_XID_FI
) {
351 printf(": %02x %02x", p
[1], p
[2]);
358 if ((control
& LLC_S_FMT
) == LLC_S_FMT
) {
359 (void)printf("Supervisory, %s, rcv seq %u, Flags [%s], length %u",
360 tok2str(llc_supervisory_values
,"?",LLC_S_CMD(control
)),
362 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
365 (void)printf("Information, send seq %u, rcv seq %u, Flags [%s], length %u",
368 tok2str(llc_flag_values
,"?",(ssap_field
& LLC_GSAP
) | (control
& LLC_IS_POLL
)),
379 snap_print(const u_char
*p
, u_int length
, u_int caplen
,
380 u_short
*extracted_ethertype
, u_int bridge_pad
)
387 orgcode
= EXTRACT_24BITS(p
);
388 et
= EXTRACT_16BITS(p
+ 3);
391 const struct tok
*tok
= null_values
;
392 const struct oui_tok
*otp
;
394 for (otp
= &oui_to_tok
[0]; otp
->tok
!= NULL
; otp
++) {
395 if (otp
->oui
== orgcode
) {
400 (void)printf("oui %s (0x%06x), %s %s (0x%04x): ",
401 tok2str(oui_values
, "Unknown", orgcode
),
403 (orgcode
== 0x000000 ? "ethertype" : "pid"),
404 tok2str(tok
, "Unknown", et
),
412 case OUI_ENCAP_ETHER
:
415 * This is an encapsulated Ethernet packet,
416 * or a packet bridged by some piece of
417 * Cisco hardware; the protocol ID is
418 * an Ethernet protocol type.
420 ret
= ether_encap_print(et
, p
, length
, caplen
,
421 extracted_ethertype
);
427 if (et
== ETHERTYPE_ATALK
) {
429 * No, I have no idea why Apple used one
430 * of their own OUIs, rather than
431 * 0x000000, and an Ethernet packet
432 * type, for Appletalk data packets,
433 * but used 0x000000 and an Ethernet
434 * packet type for AARP packets.
436 ret
= ether_encap_print(et
, p
, length
, caplen
,
437 extracted_ethertype
);
444 if (et
== PID_CISCO_CDP
) {
445 cdp_print(p
, length
, caplen
);
453 case PID_RFC2684_ETH_FCS
:
454 case PID_RFC2684_ETH_NOFCS
:
456 * XXX - remove the last two bytes for
457 * PID_RFC2684_ETH_FCS?
462 TCHECK2(*p
, bridge_pad
);
463 caplen
-= bridge_pad
;
464 length
-= bridge_pad
;
468 * What remains is an Ethernet packet.
470 ether_print(p
, length
, caplen
);
473 case PID_RFC2684_802_5_FCS
:
474 case PID_RFC2684_802_5_NOFCS
:
476 * XXX - remove the last two bytes for
477 * PID_RFC2684_ETH_FCS?
480 * Skip the padding, but not the Access
483 TCHECK2(*p
, bridge_pad
);
484 caplen
-= bridge_pad
;
485 length
-= bridge_pad
;
489 * What remains is an 802.5 Token Ring
492 token_print(p
, length
, caplen
);
495 case PID_RFC2684_FDDI_FCS
:
496 case PID_RFC2684_FDDI_NOFCS
:
498 * XXX - remove the last two bytes for
499 * PID_RFC2684_ETH_FCS?
504 TCHECK2(*p
, bridge_pad
+ 1);
505 caplen
-= bridge_pad
+ 1;
506 length
-= bridge_pad
+ 1;
510 * What remains is an FDDI packet.
512 fddi_print(p
, length
, caplen
);
515 case PID_RFC2684_BPDU
:
516 stp_print(p
, length
);
523 (void)printf("[|snap]");
530 * c-style: whitesmith