]> The Tcpdump Group git mirrors - tcpdump/blob - print-llc.c
Handle IPX socket 0x553, which is some kind of NetBIOS-over-IPX socket.
[tcpdump] / print-llc.c
1 /*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996, 1997
3 * The Regents of the University of California. All rights reserved.
4 *
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
16 * written permission.
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.
20 *
21 * Code by Matt Thomas, Digital Equipment Corporation
22 * with an awful lot of hacking by Jeffrey Mogul, DECWRL
23 */
24
25 #ifndef lint
26 static const char rcsid[] =
27 "@(#) $Header: /tcpdump/master/tcpdump/print-llc.c,v 1.34 2001-01-15 03:24:00 guy Exp $";
28 #endif
29
30 #ifdef HAVE_CONFIG_H
31 #include "config.h"
32 #endif
33
34 #include <sys/param.h>
35 #include <sys/time.h>
36
37 #include <netinet/in.h>
38
39 #include <ctype.h>
40 #include <netdb.h>
41 #include <stdio.h>
42 #include <string.h>
43
44 #include "interface.h"
45 #include "addrtoname.h"
46 #include "extract.h" /* must come after interface.h */
47
48 #include "llc.h"
49
50 static struct tok cmd2str[] = {
51 { LLC_UI, "ui" },
52 { LLC_TEST, "test" },
53 { LLC_XID, "xid" },
54 { LLC_UA, "ua" },
55 { LLC_DISC, "disc" },
56 { LLC_DM, "dm" },
57 { LLC_SABME, "sabme" },
58 { LLC_FRMR, "frmr" },
59 { 0, NULL }
60 };
61
62 /*
63 * Returns non-zero IFF it succeeds in printing the header
64 */
65 int
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)
68 {
69 struct llc llc;
70 register u_short et;
71 u_int16_t control;
72 register int ret;
73
74 if (caplen < 3) {
75 (void)printf("[|llc]");
76 default_print((u_char *)p, caplen);
77 return(0);
78 }
79
80 /* Watch out for possible alignment problems */
81 memcpy((char *)&llc, (char *)p, min(caplen, sizeof(llc)));
82
83 if (llc.ssap == LLCSAP_GLOBAL && llc.dsap == LLCSAP_GLOBAL) {
84 /*
85 * This is an Ethernet_802.3 IPX frame; it has an
86 * 802.3 header (i.e., an Ethernet header where the
87 * type/length field is <= ETHERMTU, i.e. it's a length
88 * field, not a type field), but has no 802.2 header -
89 * the IPX packet starts right after the Ethernet header,
90 * with a signature of two bytes of 0xFF (which is
91 * LLCSAP_GLOBAL).
92 */
93 ipx_print(p, length);
94 return (1);
95 }
96
97 /* Cisco Discovery Protocol - SNAP & ether type 0x2000 */
98 if(llc.ssap == LLCSAP_SNAP && llc.dsap == LLCSAP_SNAP &&
99 llc.llcui == LLC_UI &&
100 llc.ethertype[0] == 0x20 && llc.ethertype[1] == 0x00 ) {
101 cdp_print( p, length, caplen, esrc, edst);
102 return (1);
103 }
104
105 if (llc.ssap == LLCSAP_8021D && llc.dsap == LLCSAP_8021D) {
106 stp_print(p, length);
107 return (1);
108 }
109
110 if (llc.ssap == LLCSAP_IPX && llc.dsap == LLCSAP_IPX &&
111 llc.llcui == LLC_UI) {
112 /*
113 * This is an Ethernet_802.2 IPX frame, with an 802.3
114 * header and an 802.2 LLC header with the source and
115 * destination SAPs being the IPX SAP.
116 *
117 * Skip DSAP, LSAP, and control field.
118 */
119 p += 3;
120 length -= 3;
121 caplen -= 3;
122 ipx_print(p, length);
123 return (1);
124 }
125
126 if (llc.ssap == 0xf0 && llc.dsap == 0xf0
127 && (!(llc.llcu & LLC_S_FMT) || llc.llcu == LLC_U_FMT)) {
128 /*
129 * we don't actually have a full netbeui parser yet, but the
130 * smb parser can handle many smb-in-netbeui packets, which
131 * is very useful, so we call that
132 *
133 * We don't call it for S frames, however, just I frames
134 * (which are frames that don't have the low-order bit,
135 * LLC_S_FMT, set in the first byte of the control field)
136 * and UI frames (whose control field is just 3, LLC_U_FMT).
137 */
138
139 /*
140 * Skip the DSAP and LSAP.
141 */
142 p += 2;
143 length -= 2;
144 caplen -= 2;
145
146 /*
147 * OK, what type of LLC frame is this? The length
148 * of the control field depends on that - I frames
149 * have a two-byte control field, and U frames have
150 * a one-byte control field.
151 */
152 if (llc.llcu == LLC_U_FMT) {
153 control = llc.llcu;
154 p += 1;
155 length -= 1;
156 caplen -= 1;
157 } else {
158 /*
159 * The control field in I and S frames is
160 * little-endian.
161 */
162 control = EXTRACT_LE_16BITS(&llc.llcu);
163 p += 2;
164 length -= 2;
165 caplen -= 2;
166 }
167 netbeui_print(control, p, p + min(caplen, length));
168 return (1);
169 }
170 if (llc.ssap == LLCSAP_ISONS && llc.dsap == LLCSAP_ISONS
171 && llc.llcui == LLC_UI) {
172 isoclns_print(p + 3, length - 3, caplen - 3, esrc, edst);
173 return (1);
174 }
175
176 if (llc.ssap == LLCSAP_SNAP && llc.dsap == LLCSAP_SNAP
177 && llc.llcui == LLC_UI) {
178 if (caplen < sizeof(llc)) {
179 (void)printf("[|llc-snap]");
180 default_print((u_char *)p, caplen);
181 return (0);
182 }
183 if (vflag)
184 (void)printf("snap %s ", protoid_string(llc.llcpi));
185
186 caplen -= sizeof(llc);
187 length -= sizeof(llc);
188 p += sizeof(llc);
189
190 /* This is an encapsulated Ethernet packet */
191 et = EXTRACT_16BITS(&llc.ethertype[0]);
192 ret = ether_encap_print(et, p, length, caplen,
193 extracted_ethertype);
194 if (ret)
195 return (ret);
196 }
197
198 if ((llc.ssap & ~LLC_GSAP) == llc.dsap) {
199 if (eflag)
200 (void)printf("%s ", llcsap_string(llc.dsap));
201 else
202 (void)printf("%s > %s %s ",
203 etheraddr_string(esrc),
204 etheraddr_string(edst),
205 llcsap_string(llc.dsap));
206 } else {
207 if (eflag)
208 (void)printf("%s > %s ",
209 llcsap_string(llc.ssap & ~LLC_GSAP),
210 llcsap_string(llc.dsap));
211 else
212 (void)printf("%s %s > %s %s ",
213 etheraddr_string(esrc),
214 llcsap_string(llc.ssap & ~LLC_GSAP),
215 etheraddr_string(edst),
216 llcsap_string(llc.dsap));
217 }
218
219 if ((llc.llcu & LLC_U_FMT) == LLC_U_FMT) {
220 u_int16_t cmd;
221 const char *m;
222 char f;
223
224 cmd = LLC_U_CMD(llc.llcu);
225 m = tok2str(cmd2str, "%02x", cmd);
226 switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) {
227 case 0: f = 'C'; break;
228 case LLC_GSAP: f = 'R'; break;
229 case LLC_U_POLL: f = 'P'; break;
230 case LLC_GSAP|LLC_U_POLL: f = 'F'; break;
231 default: f = '?'; break;
232 }
233
234 printf("%s/%c", m, f);
235
236 p += 3;
237 length -= 3;
238 caplen -= 3;
239
240 if ((llc.llcu & ~LLC_U_POLL) == LLC_XID) {
241 if (*p == LLC_XID_FI) {
242 printf(": %02x %02x", p[1], p[2]);
243 p += 3;
244 length -= 3;
245 caplen -= 3;
246 }
247 }
248 } else {
249 char f;
250
251 /*
252 * The control field in I and S frames is little-endian.
253 */
254 control = EXTRACT_LE_16BITS(&llc.llcu);
255 switch ((llc.ssap & LLC_GSAP) | (control & LLC_IS_POLL)) {
256 case 0: f = 'C'; break;
257 case LLC_GSAP: f = 'R'; break;
258 case LLC_IS_POLL: f = 'P'; break;
259 case LLC_GSAP|LLC_IS_POLL: f = 'F'; break;
260 default: f = '?'; break;
261 }
262
263 if ((control & LLC_S_FMT) == LLC_S_FMT) {
264 static char *llc_s[] = { "rr", "rej", "rnr", "03" };
265 (void)printf("%s (r=%d,%c)",
266 llc_s[LLC_S_CMD(control)],
267 LLC_IS_NR(control),
268 f);
269 } else {
270 (void)printf("I (s=%d,r=%d,%c)",
271 LLC_I_NS(control),
272 LLC_IS_NR(control),
273 f);
274 }
275 p += 4;
276 length -= 4;
277 caplen -= 4;
278 }
279 (void)printf(" len=%d", length);
280 return(1);
281 }