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
28 static const char rcsid[] _U_ =
29 "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.61.2.4 2005/04/26 07:27:16 guy Exp $";
36 #include <tcpdump-stdinc.h>
41 #include "interface.h"
42 #include "addrtoname.h"
43 #include "extract.h" /* must come after interface.h */
46 #include "ethertype.h"
49 static struct tok llc_values[] = {
50 { LLCSAP_NULL, "Null" },
51 { LLCSAP_GLOBAL, "Global" },
52 { LLCSAP_8021B_I, "802.1B I" },
53 { LLCSAP_8021B_G, "802.1B G" },
55 { LLCSAP_PROWAYNM, "ProWay NM" },
56 { LLCSAP_8021D, "STP" },
57 { LLCSAP_RS511, "RS511" },
58 { LLCSAP_ISO8208, "ISO8208" },
59 { LLCSAP_PROWAY, "ProWay" },
60 { LLCSAP_SNAP, "SNAP" },
61 { LLCSAP_IPX, "IPX" },
62 { LLCSAP_NETBEUI, "NetBeui" },
63 { LLCSAP_ISONS, "OSI" },
67 static struct tok cmd2str[] = {
74 { LLC_SABME, "sabme" },
79 static const struct tok cisco_values[] = {
80 { PID_CISCO_CDP, "CDP" },
84 static const struct tok bridged_values[] = {
85 { PID_RFC2684_ETH_FCS, "Ethernet + FCS" },
86 { PID_RFC2684_ETH_NOFCS, "Ethernet w/o FCS" },
87 { PID_RFC2684_802_4_FCS, "802.4 + FCS" },
88 { PID_RFC2684_802_4_NOFCS, "802.4 w/o FCS" },
89 { PID_RFC2684_802_5_FCS, "Token Ring + FCS" },
90 { PID_RFC2684_802_5_NOFCS, "Token Ring w/o FCS" },
91 { PID_RFC2684_FDDI_FCS, "FDDI + FCS" },
92 { PID_RFC2684_FDDI_NOFCS, "FDDI w/o FCS" },
93 { PID_RFC2684_802_6_FCS, "802.6 + FCS" },
94 { PID_RFC2684_802_6_NOFCS, "802.6 w/o FCS" },
95 { PID_RFC2684_BPDU, "BPDU" },
101 const struct tok *tok;
104 static const struct oui_tok oui_to_tok[] = {
105 { OUI_ENCAP_ETHER, ethertype_values },
106 { OUI_CISCO_90, ethertype_values }, /* uses some Ethertype values */
107 { OUI_APPLETALK, ethertype_values }, /* uses some Ethertype values */
108 { OUI_CISCO, cisco_values },
109 { OUI_RFC2684, bridged_values }, /* bridged, RFC 2427 FR or RFC 2864 ATM */
114 * Returns non-zero IFF it succeeds in printing the header
117 llc_print(const u_char *p, u_int length, u_int caplen,
118 const u_char *esrc, const u_char *edst, u_short *extracted_ethertype)
126 (void)printf("[|llc]");
127 default_print((u_char *)p, caplen);
135 * OK, what type of LLC frame is this? The length
136 * of the control field depends on that - I frames
137 * have a two-byte control field, and U frames have
138 * a one-byte control field.
141 if ((control & LLC_U_FMT) == LLC_U_FMT) {
148 * The control field in I and S frames is
152 (void)printf("[|llc]");
153 default_print((u_char *)p, caplen);
158 * ...and is little-endian.
160 control = EXTRACT_LE_16BITS(p + 2);
164 if (ssap == LLCSAP_GLOBAL && dsap == LLCSAP_GLOBAL) {
166 * This is an Ethernet_802.3 IPX frame; it has an
167 * 802.3 header (i.e., an Ethernet header where the
168 * type/length field is <= ETHERMTU, i.e. it's a length
169 * field, not a type field), but has no 802.2 header -
170 * the IPX packet starts right after the Ethernet header,
171 * with a signature of two bytes of 0xFF (which is
174 * (It might also have been an Ethernet_802.3 IPX at
175 * one time, but got bridged onto another network,
176 * such as an 802.11 network; this has appeared in at
177 * least one capture file.)
181 printf("IPX-802.3: ");
183 ipx_print(p, length);
189 printf("LLC, dsap %s (0x%02x), ssap %s (0x%02x), cmd 0x%02x: ",
190 tok2str(llc_values, "Unknown", dsap),
192 tok2str(llc_values, "Unknown", ssap),
196 printf("LLC, dsap %s (0x%02x), ssap %s (0x%02x), cmd 0x%04x: ",
197 tok2str(llc_values, "Unknown", dsap),
199 tok2str(llc_values, "Unknown", ssap),
205 if (ssap == LLCSAP_8021D && dsap == LLCSAP_8021D &&
207 stp_print(p+3, length-3);
211 if (ssap == LLCSAP_IP && dsap == LLCSAP_IP &&
213 ip_print(gndo, p+4, length-4);
217 if (ssap == LLCSAP_IPX && dsap == LLCSAP_IPX &&
220 * This is an Ethernet_802.2 IPX frame, with an 802.3
221 * header and an 802.2 LLC header with the source and
222 * destination SAPs being the IPX SAP.
224 * Skip DSAP, LSAP, and control field.
226 printf("(NOV-802.2) ");
227 ipx_print(p+3, length-3);
231 #ifdef TCPDUMP_DO_SMB
232 if (ssap == LLCSAP_NETBEUI && dsap == LLCSAP_NETBEUI
233 && (!(control & LLC_S_FMT) || control == LLC_U_FMT)) {
235 * we don't actually have a full netbeui parser yet, but the
236 * smb parser can handle many smb-in-netbeui packets, which
237 * is very useful, so we call that
239 * We don't call it for S frames, however, just I frames
240 * (which are frames that don't have the low-order bit,
241 * LLC_S_FMT, set in the first byte of the control field)
242 * and UI frames (whose control field is just 3, LLC_U_FMT).
246 * Skip the LLC header.
257 netbeui_print(control, p, length);
261 if (ssap == LLCSAP_ISONS && dsap == LLCSAP_ISONS
262 && control == LLC_UI) {
263 isoclns_print(p + 3, length - 3, caplen - 3);
267 if (ssap == LLCSAP_SNAP && dsap == LLCSAP_SNAP
268 && control == LLC_UI) {
270 * XXX - what *is* the right bridge pad value here?
271 * Does anybody ever bridge one form of LAN traffic
272 * over a networking type that uses 802.2 LLC?
274 ret = snap_print(p+3, length-3, caplen-3, extracted_ethertype,
281 if ((ssap & ~LLC_GSAP) == dsap) {
282 if (esrc == NULL || edst == NULL)
283 (void)printf("%s ", llcsap_string(dsap));
285 (void)printf("%s > %s %s ",
286 etheraddr_string(esrc),
287 etheraddr_string(edst),
288 llcsap_string(dsap));
290 if (esrc == NULL || edst == NULL)
291 (void)printf("%s > %s ",
292 llcsap_string(ssap & ~LLC_GSAP),
293 llcsap_string(dsap));
295 (void)printf("%s %s > %s %s ",
296 etheraddr_string(esrc),
297 llcsap_string(ssap & ~LLC_GSAP),
298 etheraddr_string(edst),
299 llcsap_string(dsap));
307 m = tok2str(cmd2str, "%02x", LLC_U_CMD(control));
308 switch ((ssap & LLC_GSAP) | (control & LLC_U_POLL)) {
309 case 0: f = 'C'; break;
310 case LLC_GSAP: f = 'R'; break;
311 case LLC_U_POLL: f = 'P'; break;
312 case LLC_GSAP|LLC_U_POLL: f = 'F'; break;
313 default: f = '?'; break;
316 printf("%s/%c", m, f);
322 if ((control & ~LLC_U_POLL) == LLC_XID) {
323 if (*p == LLC_XID_FI) {
324 printf(": %02x %02x", p[1], p[2]);
333 switch ((ssap & LLC_GSAP) | (control & LLC_IS_POLL)) {
334 case 0: f = 'C'; break;
335 case LLC_GSAP: f = 'R'; break;
336 case LLC_IS_POLL: f = 'P'; break;
337 case LLC_GSAP|LLC_IS_POLL: f = 'F'; break;
338 default: f = '?'; break;
341 if ((control & LLC_S_FMT) == LLC_S_FMT) {
342 static const char *llc_s[] = { "rr", "rej", "rnr", "03" };
343 (void)printf("%s (r=%d,%c)",
344 llc_s[LLC_S_CMD(control)],
348 (void)printf("I (s=%d,r=%d,%c)",
361 snap_print(const u_char *p, u_int length, u_int caplen,
362 u_short *extracted_ethertype, u_int bridge_pad)
369 orgcode = EXTRACT_24BITS(p);
370 et = EXTRACT_16BITS(p + 3);
373 const struct tok *tok = NULL;
374 const struct oui_tok *otp;
376 for (otp = &oui_to_tok[0]; otp->tok != NULL; otp++) {
377 if (otp->oui == orgcode) {
382 (void)printf("oui %s (0x%06x), %s %s (0x%04x): ",
383 tok2str(oui_values, "Unknown", orgcode),
385 (orgcode == 0x000000 ? "ethertype" : "pid"),
386 tok2str(tok, "Unknown", et),
394 case OUI_ENCAP_ETHER:
397 * This is an encapsulated Ethernet packet,
398 * or a packet bridged by some piece of
399 * Cisco hardware; the protocol ID is
400 * an Ethernet protocol type.
402 ret = ether_encap_print(et, p, length, caplen,
403 extracted_ethertype);
409 if (et == ETHERTYPE_ATALK) {
411 * No, I have no idea why Apple used one
412 * of their own OUIs, rather than
413 * 0x000000, and an Ethernet packet
414 * type, for Appletalk data packets,
415 * but used 0x000000 and an Ethernet
416 * packet type for AARP packets.
418 ret = ether_encap_print(et, p, length, caplen,
419 extracted_ethertype);
426 if (et == PID_CISCO_CDP) {
427 cdp_print(p, length, caplen);
435 case PID_RFC2684_ETH_FCS:
436 case PID_RFC2684_ETH_NOFCS:
438 * XXX - remove the last two bytes for
439 * PID_RFC2684_ETH_FCS?
444 TCHECK2(*p, bridge_pad);
445 caplen -= bridge_pad;
446 length -= bridge_pad;
450 * What remains is an Ethernet packet.
452 ether_print(p, length, caplen);
455 case PID_RFC2684_802_5_FCS:
456 case PID_RFC2684_802_5_NOFCS:
458 * XXX - remove the last two bytes for
459 * PID_RFC2684_ETH_FCS?
462 * Skip the padding, but not the Access
465 TCHECK2(*p, bridge_pad);
466 caplen -= bridge_pad;
467 length -= bridge_pad;
471 * What remains is an 802.5 Token Ring
474 token_print(p, length, caplen);
477 case PID_RFC2684_FDDI_FCS:
478 case PID_RFC2684_FDDI_NOFCS:
480 * XXX - remove the last two bytes for
481 * PID_RFC2684_ETH_FCS?
486 TCHECK2(*p, bridge_pad + 1);
487 caplen -= bridge_pad + 1;
488 length -= bridge_pad + 1;
492 * What remains is an FDDI packet.
494 fddi_print(p, length, caplen);
497 case PID_RFC2684_BPDU:
498 stp_print(p, length);
505 (void)printf("[|snap]");
512 * c-style: whitesmith