]>
The Tcpdump Group git mirrors - tcpdump/blob - print-llc.c
280ea88a906a98606cd027d6c28c60d449cd47df
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
[] =
27 "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.40 2001-07-21 23:14:23 guy Exp $";
34 #include <sys/param.h>
37 #include <netinet/in.h>
44 #include "interface.h"
45 #include "addrtoname.h"
46 #include "extract.h" /* must come after interface.h */
49 #include "ethertype.h"
51 static struct tok cmd2str
[] = {
58 { LLC_SABME
, "sabme" },
64 * Returns non-zero IFF it succeeds in printing the header
67 llc_print(const u_char
*p
, u_int length
, u_int caplen
,
68 const u_char
*esrc
, const u_char
*edst
, u_short
*extracted_ethertype
)
76 (void)printf("[|llc]");
77 default_print((u_char
*)p
, caplen
);
81 /* Watch out for possible alignment problems */
82 memcpy((char *)&llc
, (char *)p
, min(caplen
, sizeof(llc
)));
84 if (llc
.ssap
== LLCSAP_GLOBAL
&& llc
.dsap
== LLCSAP_GLOBAL
) {
86 * This is an Ethernet_802.3 IPX frame; it has an
87 * 802.3 header (i.e., an Ethernet header where the
88 * type/length field is <= ETHERMTU, i.e. it's a length
89 * field, not a type field), but has no 802.2 header -
90 * the IPX packet starts right after the Ethernet header,
91 * with a signature of two bytes of 0xFF (which is
94 * (It might also have been an Ethernet_802.3 IPX at
95 * one time, but got bridged onto another network,
96 * such as an 802.11 network; this has appeared in at
97 * least one capture file.)
103 if (llc
.ssap
== LLCSAP_8021D
&& llc
.dsap
== LLCSAP_8021D
) {
104 stp_print(p
, length
);
108 if (llc
.ssap
== LLCSAP_IPX
&& llc
.dsap
== LLCSAP_IPX
&&
109 llc
.llcui
== LLC_UI
) {
111 * This is an Ethernet_802.2 IPX frame, with an 802.3
112 * header and an 802.2 LLC header with the source and
113 * destination SAPs being the IPX SAP.
115 * Skip DSAP, LSAP, and control field.
120 ipx_print(p
, length
);
124 if (llc
.ssap
== LLCSAP_NETBEUI
&& llc
.dsap
== LLCSAP_NETBEUI
125 && (!(llc
.llcu
& LLC_S_FMT
) || llc
.llcu
== LLC_U_FMT
)) {
127 * we don't actually have a full netbeui parser yet, but the
128 * smb parser can handle many smb-in-netbeui packets, which
129 * is very useful, so we call that
131 * We don't call it for S frames, however, just I frames
132 * (which are frames that don't have the low-order bit,
133 * LLC_S_FMT, set in the first byte of the control field)
134 * and UI frames (whose control field is just 3, LLC_U_FMT).
138 * Skip the DSAP and LSAP.
145 * OK, what type of LLC frame is this? The length
146 * of the control field depends on that - I frames
147 * have a two-byte control field, and U frames have
148 * a one-byte control field.
150 if (llc
.llcu
== LLC_U_FMT
) {
157 * The control field in I and S frames is
160 control
= EXTRACT_LE_16BITS(&llc
.llcu
);
165 netbeui_print(control
, p
, length
);
168 if (llc
.ssap
== LLCSAP_ISONS
&& llc
.dsap
== LLCSAP_ISONS
169 && llc
.llcui
== LLC_UI
) {
170 isoclns_print(p
+ 3, length
- 3, caplen
- 3, esrc
, edst
);
174 if (llc
.ssap
== LLCSAP_SNAP
&& llc
.dsap
== LLCSAP_SNAP
175 && llc
.llcui
== LLC_UI
) {
178 if (caplen
< sizeof(llc
)) {
179 (void)printf("[|llc-snap]");
180 default_print((u_char
*)p
, caplen
);
184 (void)printf("snap %s ", protoid_string(llc
.llcpi
));
186 caplen
-= sizeof(llc
);
187 length
-= sizeof(llc
);
190 orgcode
= EXTRACT_24BITS(&llc
.llc_orgcode
[0]);
191 et
= EXTRACT_16BITS(&llc
.llc_ethertype
[0]);
193 case OUI_ENCAP_ETHER
:
196 * This is an encapsulated Ethernet packet,
197 * or a packet bridged by some piece of
198 * Cisco hardware; the protocol ID is
199 * an Ethernet protocol type.
201 ret
= ether_encap_print(et
, p
, length
, caplen
,
202 extracted_ethertype
);
208 if (et
== ETHERTYPE_ATALK
) {
210 * No, I have no idea why Apple used one
211 * of their own OUIs, rather than
212 * 0x000000, and an Ethernet packet
213 * type, for Appletalk data packets,
214 * but used 0x000000 and an Ethernet
215 * packet type for AARP packets.
217 ret
= ether_encap_print(et
, p
, length
, caplen
,
218 extracted_ethertype
);
225 if (et
== ETHERTYPE_CISCO_CDP
) {
226 cdp_print(p
, length
, caplen
, esrc
, edst
);
233 if ((llc
.ssap
& ~LLC_GSAP
) == llc
.dsap
) {
235 (void)printf("%s ", llcsap_string(llc
.dsap
));
237 (void)printf("%s > %s %s ",
238 etheraddr_string(esrc
),
239 etheraddr_string(edst
),
240 llcsap_string(llc
.dsap
));
243 (void)printf("%s > %s ",
244 llcsap_string(llc
.ssap
& ~LLC_GSAP
),
245 llcsap_string(llc
.dsap
));
247 (void)printf("%s %s > %s %s ",
248 etheraddr_string(esrc
),
249 llcsap_string(llc
.ssap
& ~LLC_GSAP
),
250 etheraddr_string(edst
),
251 llcsap_string(llc
.dsap
));
254 if ((llc
.llcu
& LLC_U_FMT
) == LLC_U_FMT
) {
259 cmd
= LLC_U_CMD(llc
.llcu
);
260 m
= tok2str(cmd2str
, "%02x", cmd
);
261 switch ((llc
.ssap
& LLC_GSAP
) | (llc
.llcu
& LLC_U_POLL
)) {
262 case 0: f
= 'C'; break;
263 case LLC_GSAP
: f
= 'R'; break;
264 case LLC_U_POLL
: f
= 'P'; break;
265 case LLC_GSAP
|LLC_U_POLL
: f
= 'F'; break;
266 default: f
= '?'; break;
269 printf("%s/%c", m
, f
);
275 if ((llc
.llcu
& ~LLC_U_POLL
) == LLC_XID
) {
276 if (*p
== LLC_XID_FI
) {
277 printf(": %02x %02x", p
[1], p
[2]);
287 * The control field in I and S frames is little-endian.
289 control
= EXTRACT_LE_16BITS(&llc
.llcu
);
290 switch ((llc
.ssap
& LLC_GSAP
) | (control
& LLC_IS_POLL
)) {
291 case 0: f
= 'C'; break;
292 case LLC_GSAP
: f
= 'R'; break;
293 case LLC_IS_POLL
: f
= 'P'; break;
294 case LLC_GSAP
|LLC_IS_POLL
: f
= 'F'; break;
295 default: f
= '?'; break;
298 if ((control
& LLC_S_FMT
) == LLC_S_FMT
) {
299 static char *llc_s
[] = { "rr", "rej", "rnr", "03" };
300 (void)printf("%s (r=%d,%c)",
301 llc_s
[LLC_S_CMD(control
)],
305 (void)printf("I (s=%d,r=%d,%c)",
314 (void)printf(" len=%d", length
);