]>
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
[] =
27 "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.32 2000-12-18 07:55:36 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 */
50 static struct tok cmd2str
[] = {
57 { LLC_SABME
, "sabme" },
63 * Returns non-zero IFF it succeeds in printing the header
66 llc_print(const u_char
*p
, u_int length
, u_int caplen
,
67 const u_char
*esrc
, const u_char
*edst
, u_short
*extracted_ethertype
)
75 (void)printf("[|llc]");
76 default_print((u_char
*)p
, caplen
);
80 /* Watch out for possible alignment problems */
81 memcpy((char *)&llc
, (char *)p
, min(caplen
, sizeof(llc
)));
83 if (llc
.ssap
== LLCSAP_GLOBAL
&& llc
.dsap
== LLCSAP_GLOBAL
) {
88 /* Cisco Discovery Protocol - SNAP & ether type 0x2000 */
89 if(llc
.ssap
== LLCSAP_SNAP
&& llc
.dsap
== LLCSAP_SNAP
&&
90 llc
.llcui
== LLC_UI
&&
91 llc
.ethertype
[0] == 0x20 && llc
.ethertype
[1] == 0x00 ) {
92 cdp_print( p
, length
, caplen
, esrc
, edst
);
96 if (llc
.ssap
== LLCSAP_8021D
&& llc
.dsap
== LLCSAP_8021D
) {
100 if (llc
.ssap
== 0xf0 && llc
.dsap
== 0xf0
101 && (!(llc
.llcu
& LLC_S_FMT
) || llc
.llcu
== LLC_U_FMT
)) {
103 * we don't actually have a full netbeui parser yet, but the
104 * smb parser can handle many smb-in-netbeui packets, which
105 * is very useful, so we call that
107 * We don't call it for S frames, however, just I frames
108 * (which are frames that don't have the low-order bit,
109 * LLC_S_FMT, set in the first byte of the control field)
110 * and UI frames (whose control field is just 3, LLC_U_FMT).
114 * Skip the DSAP and LSAP.
121 * OK, what type of LLC frame is this? The length
122 * of the control field depends on that - I frames
123 * have a two-byte control field, and U frames have
124 * a one-byte control field.
126 if (llc
.llcu
== LLC_U_FMT
) {
133 * The control field in I and S frames is
136 control
= EXTRACT_LE_16BITS(&llc
.llcu
);
141 netbeui_print(control
, p
, p
+ min(caplen
, length
));
144 if (llc
.ssap
== LLCSAP_ISONS
&& llc
.dsap
== LLCSAP_ISONS
145 && llc
.llcui
== LLC_UI
) {
146 isoclns_print(p
+ 3, length
- 3, caplen
- 3, esrc
, edst
);
150 if (llc
.ssap
== LLCSAP_SNAP
&& llc
.dsap
== LLCSAP_SNAP
151 && llc
.llcui
== LLC_UI
) {
152 if (caplen
< sizeof(llc
)) {
153 (void)printf("[|llc-snap]");
154 default_print((u_char
*)p
, caplen
);
158 (void)printf("snap %s ", protoid_string(llc
.llcpi
));
160 caplen
-= sizeof(llc
);
161 length
-= sizeof(llc
);
164 /* This is an encapsulated Ethernet packet */
165 et
= EXTRACT_16BITS(&llc
.ethertype
[0]);
166 ret
= ether_encap_print(et
, p
, length
, caplen
,
167 extracted_ethertype
);
172 if ((llc
.ssap
& ~LLC_GSAP
) == llc
.dsap
) {
174 (void)printf("%s ", llcsap_string(llc
.dsap
));
176 (void)printf("%s > %s %s ",
177 etheraddr_string(esrc
),
178 etheraddr_string(edst
),
179 llcsap_string(llc
.dsap
));
182 (void)printf("%s > %s ",
183 llcsap_string(llc
.ssap
& ~LLC_GSAP
),
184 llcsap_string(llc
.dsap
));
186 (void)printf("%s %s > %s %s ",
187 etheraddr_string(esrc
),
188 llcsap_string(llc
.ssap
& ~LLC_GSAP
),
189 etheraddr_string(edst
),
190 llcsap_string(llc
.dsap
));
193 if ((llc
.llcu
& LLC_U_FMT
) == LLC_U_FMT
) {
198 cmd
= LLC_U_CMD(llc
.llcu
);
199 m
= tok2str(cmd2str
, "%02x", cmd
);
200 switch ((llc
.ssap
& LLC_GSAP
) | (llc
.llcu
& LLC_U_POLL
)) {
201 case 0: f
= 'C'; break;
202 case LLC_GSAP
: f
= 'R'; break;
203 case LLC_U_POLL
: f
= 'P'; break;
204 case LLC_GSAP
|LLC_U_POLL
: f
= 'F'; break;
205 default: f
= '?'; break;
208 printf("%s/%c", m
, f
);
214 if ((llc
.llcu
& ~LLC_U_POLL
) == LLC_XID
) {
215 if (*p
== LLC_XID_FI
) {
216 printf(": %02x %02x", p
[1], p
[2]);
223 if (cmd
== LLC_UI
&& f
== 'C') {
225 * we don't have a proper ipx decoder yet, but there
226 * is a partial one in the smb code
228 ipx_netbios_print(p
,p
+min(caplen
,length
));
234 * The control field in I and S frames is little-endian.
236 control
= EXTRACT_LE_16BITS(&llc
.llcu
);
237 switch ((llc
.ssap
& LLC_GSAP
) | (control
& LLC_IS_POLL
)) {
238 case 0: f
= 'C'; break;
239 case LLC_GSAP
: f
= 'R'; break;
240 case LLC_IS_POLL
: f
= 'P'; break;
241 case LLC_GSAP
|LLC_IS_POLL
: f
= 'F'; break;
242 default: f
= '?'; break;
245 if ((control
& LLC_S_FMT
) == LLC_S_FMT
) {
246 static char *llc_s
[] = { "rr", "rej", "rnr", "03" };
247 (void)printf("%s (r=%d,%c)",
248 llc_s
[LLC_S_CMD(control
)],
252 (void)printf("I (s=%d,r=%d,%c)",
261 (void)printf(" len=%d", length
);