]>
The Tcpdump Group git mirrors - tcpdump/blob - print-llc.c
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.65 2005-04-26 07:26:34 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_PROWAYNM
, "ProWay NM" },
54 { LLCSAP_8021D
, "STP" },
55 { LLCSAP_RS511
, "RS511" },
56 { LLCSAP_ISO8208
, "ISO8208" },
57 { LLCSAP_PROWAY
, "ProWay" },
58 { LLCSAP_SNAP
, "SNAP" },
59 { LLCSAP_IPX
, "IPX" },
60 { LLCSAP_NETBEUI
, "NetBeui" },
61 { LLCSAP_ISONS
, "OSI" },
65 static struct tok cmd2str
[] = {
72 { LLC_SABME
, "sabme" },
77 static const struct tok cisco_values
[] = {
78 { PID_CISCO_CDP
, "CDP" },
82 static const struct tok bridged_values
[] = {
83 { PID_RFC2684_ETH_FCS
, "Ethernet + FCS" },
84 { PID_RFC2684_ETH_NOFCS
, "Ethernet w/o FCS" },
85 { PID_RFC2684_802_4_FCS
, "802.4 + FCS" },
86 { PID_RFC2684_802_4_NOFCS
, "802.4 w/o FCS" },
87 { PID_RFC2684_802_5_FCS
, "Token Ring + FCS" },
88 { PID_RFC2684_802_5_NOFCS
, "Token Ring w/o FCS" },
89 { PID_RFC2684_FDDI_FCS
, "FDDI + FCS" },
90 { PID_RFC2684_FDDI_NOFCS
, "FDDI w/o FCS" },
91 { PID_RFC2684_802_6_FCS
, "802.6 + FCS" },
92 { PID_RFC2684_802_6_NOFCS
, "802.6 w/o FCS" },
93 { PID_RFC2684_BPDU
, "BPDU" },
99 const struct tok
*tok
;
102 static const struct oui_tok oui_to_tok
[] = {
103 { OUI_ENCAP_ETHER
, ethertype_values
},
104 { OUI_CISCO_90
, ethertype_values
}, /* uses some Ethertype values */
105 { OUI_APPLETALK
, ethertype_values
}, /* uses some Ethertype values */
106 { OUI_CISCO
, cisco_values
},
107 { OUI_RFC2684
, bridged_values
}, /* bridged, RFC 2427 FR or RFC 2864 ATM */
112 * Returns non-zero IFF it succeeds in printing the header
115 llc_print(const u_char
*p
, u_int length
, u_int caplen
,
116 const u_char
*esrc
, const u_char
*edst
, u_short
*extracted_ethertype
)
124 (void)printf("[|llc]");
125 default_print((u_char
*)p
, caplen
);
133 * OK, what type of LLC frame is this? The length
134 * of the control field depends on that - I frames
135 * have a two-byte control field, and U frames have
136 * a one-byte control field.
139 if ((control
& LLC_U_FMT
) == LLC_U_FMT
) {
146 * The control field in I and S frames is
150 (void)printf("[|llc]");
151 default_print((u_char
*)p
, caplen
);
156 * ...and is little-endian.
158 control
= EXTRACT_LE_16BITS(p
+ 2);
162 if (ssap
== LLCSAP_GLOBAL
&& dsap
== LLCSAP_GLOBAL
) {
164 * This is an Ethernet_802.3 IPX frame; it has an
165 * 802.3 header (i.e., an Ethernet header where the
166 * type/length field is <= ETHERMTU, i.e. it's a length
167 * field, not a type field), but has no 802.2 header -
168 * the IPX packet starts right after the Ethernet header,
169 * with a signature of two bytes of 0xFF (which is
172 * (It might also have been an Ethernet_802.3 IPX at
173 * one time, but got bridged onto another network,
174 * such as an 802.11 network; this has appeared in at
175 * least one capture file.)
179 printf("IPX-802.3: ");
181 ipx_print(p
, length
);
187 printf("LLC, dsap %s (0x%02x), ssap %s (0x%02x), cmd 0x%02x: ",
188 tok2str(llc_values
, "Unknown", dsap
),
190 tok2str(llc_values
, "Unknown", ssap
),
194 printf("LLC, dsap %s (0x%02x), ssap %s (0x%02x), cmd 0x%04x: ",
195 tok2str(llc_values
, "Unknown", dsap
),
197 tok2str(llc_values
, "Unknown", ssap
),
203 if (ssap
== LLCSAP_8021D
&& dsap
== LLCSAP_8021D
&&
205 stp_print(p
+3, length
-3);
209 if (ssap
== LLCSAP_IP
&& dsap
== LLCSAP_IP
&&
211 ip_print(gndo
, p
+4, length
-4);
215 if (ssap
== LLCSAP_IPX
&& dsap
== LLCSAP_IPX
&&
218 * This is an Ethernet_802.2 IPX frame, with an 802.3
219 * header and an 802.2 LLC header with the source and
220 * destination SAPs being the IPX SAP.
222 * Skip DSAP, LSAP, and control field.
224 printf("(NOV-802.2) ");
225 ipx_print(p
+3, length
-3);
229 #ifdef TCPDUMP_DO_SMB
230 if (ssap
== LLCSAP_NETBEUI
&& dsap
== LLCSAP_NETBEUI
231 && (!(control
& LLC_S_FMT
) || control
== LLC_U_FMT
)) {
233 * we don't actually have a full netbeui parser yet, but the
234 * smb parser can handle many smb-in-netbeui packets, which
235 * is very useful, so we call that
237 * We don't call it for S frames, however, just I frames
238 * (which are frames that don't have the low-order bit,
239 * LLC_S_FMT, set in the first byte of the control field)
240 * and UI frames (whose control field is just 3, LLC_U_FMT).
244 * Skip the LLC header.
255 netbeui_print(control
, p
, length
);
259 if (ssap
== LLCSAP_ISONS
&& dsap
== LLCSAP_ISONS
260 && control
== LLC_UI
) {
261 isoclns_print(p
+ 3, length
- 3, caplen
- 3);
265 if (ssap
== LLCSAP_SNAP
&& dsap
== LLCSAP_SNAP
266 && control
== LLC_UI
) {
268 * XXX - what *is* the right bridge pad value here?
269 * Does anybody ever bridge one form of LAN traffic
270 * over a networking type that uses 802.2 LLC?
272 ret
= snap_print(p
+3, length
-3, caplen
-3, extracted_ethertype
,
279 if ((ssap
& ~LLC_GSAP
) == dsap
) {
280 if (esrc
== NULL
|| edst
== NULL
)
281 (void)printf("%s ", llcsap_string(dsap
));
283 (void)printf("%s > %s %s ",
284 etheraddr_string(esrc
),
285 etheraddr_string(edst
),
286 llcsap_string(dsap
));
288 if (esrc
== NULL
|| edst
== NULL
)
289 (void)printf("%s > %s ",
290 llcsap_string(ssap
& ~LLC_GSAP
),
291 llcsap_string(dsap
));
293 (void)printf("%s %s > %s %s ",
294 etheraddr_string(esrc
),
295 llcsap_string(ssap
& ~LLC_GSAP
),
296 etheraddr_string(edst
),
297 llcsap_string(dsap
));
305 m
= tok2str(cmd2str
, "%02x", LLC_U_CMD(control
));
306 switch ((ssap
& LLC_GSAP
) | (control
& LLC_U_POLL
)) {
307 case 0: f
= 'C'; break;
308 case LLC_GSAP
: f
= 'R'; break;
309 case LLC_U_POLL
: f
= 'P'; break;
310 case LLC_GSAP
|LLC_U_POLL
: f
= 'F'; break;
311 default: f
= '?'; break;
314 printf("%s/%c", m
, f
);
320 if ((control
& ~LLC_U_POLL
) == LLC_XID
) {
321 if (*p
== LLC_XID_FI
) {
322 printf(": %02x %02x", p
[1], p
[2]);
331 switch ((ssap
& LLC_GSAP
) | (control
& LLC_IS_POLL
)) {
332 case 0: f
= 'C'; break;
333 case LLC_GSAP
: f
= 'R'; break;
334 case LLC_IS_POLL
: f
= 'P'; break;
335 case LLC_GSAP
|LLC_IS_POLL
: f
= 'F'; break;
336 default: f
= '?'; break;
339 if ((control
& LLC_S_FMT
) == LLC_S_FMT
) {
340 static const char *llc_s
[] = { "rr", "rej", "rnr", "03" };
341 (void)printf("%s (r=%d,%c)",
342 llc_s
[LLC_S_CMD(control
)],
346 (void)printf("I (s=%d,r=%d,%c)",
359 snap_print(const u_char
*p
, u_int length
, u_int caplen
,
360 u_short
*extracted_ethertype
, u_int bridge_pad
)
367 orgcode
= EXTRACT_24BITS(p
);
368 et
= EXTRACT_16BITS(p
+ 3);
371 const struct tok
*tok
= NULL
;
372 const struct oui_tok
*otp
;
374 for (otp
= &oui_to_tok
[0]; otp
->tok
!= NULL
; otp
++) {
375 if (otp
->oui
== orgcode
) {
380 (void)printf("oui %s (0x%06x), %s %s (0x%04x): ",
381 tok2str(oui_values
, "Unknown", orgcode
),
383 (orgcode
== 0x000000 ? "ethertype" : "pid"),
384 tok2str(tok
, "Unknown", et
),
392 case OUI_ENCAP_ETHER
:
395 * This is an encapsulated Ethernet packet,
396 * or a packet bridged by some piece of
397 * Cisco hardware; the protocol ID is
398 * an Ethernet protocol type.
400 ret
= ether_encap_print(et
, p
, length
, caplen
,
401 extracted_ethertype
);
407 if (et
== ETHERTYPE_ATALK
) {
409 * No, I have no idea why Apple used one
410 * of their own OUIs, rather than
411 * 0x000000, and an Ethernet packet
412 * type, for Appletalk data packets,
413 * but used 0x000000 and an Ethernet
414 * packet type for AARP packets.
416 ret
= ether_encap_print(et
, p
, length
, caplen
,
417 extracted_ethertype
);
424 if (et
== PID_CISCO_CDP
) {
425 cdp_print(p
, length
, caplen
);
433 case PID_RFC2684_ETH_FCS
:
434 case PID_RFC2684_ETH_NOFCS
:
436 * XXX - remove the last two bytes for
437 * PID_RFC2684_ETH_FCS?
442 TCHECK2(*p
, bridge_pad
);
443 caplen
-= bridge_pad
;
444 length
-= bridge_pad
;
448 * What remains is an Ethernet packet.
450 ether_print(p
, length
, caplen
);
453 case PID_RFC2684_802_5_FCS
:
454 case PID_RFC2684_802_5_NOFCS
:
456 * XXX - remove the last two bytes for
457 * PID_RFC2684_ETH_FCS?
460 * Skip the padding, but not the Access
463 TCHECK2(*p
, bridge_pad
);
464 caplen
-= bridge_pad
;
465 length
-= bridge_pad
;
469 * What remains is an 802.5 Token Ring
472 token_print(p
, length
, caplen
);
475 case PID_RFC2684_FDDI_FCS
:
476 case PID_RFC2684_FDDI_NOFCS
:
478 * XXX - remove the last two bytes for
479 * PID_RFC2684_ETH_FCS?
484 TCHECK2(*p
, bridge_pad
+ 1);
485 caplen
-= bridge_pad
+ 1;
486 length
-= bridge_pad
+ 1;
490 * What remains is an FDDI packet.
492 fddi_print(p
, length
, caplen
);
495 case PID_RFC2684_BPDU
:
496 stp_print(p
, length
);
503 (void)printf("[|snap]");
510 * c-style: whitesmith