Deleted Added
full compact
print-llc.c (26183) print-llc.c (39300)
1/*
1/*
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996
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
26static const char rcsid[] =
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
26static const char rcsid[] =
27 "@(#) $Header: print-llc.c,v 1.22 96/12/10 23:23:37 leres Exp $";
27 "@(#) $Header: print-llc.c,v 1.24 97/01/01 20:56:48 leres Exp $";
28#endif
29
30#include <sys/param.h>
31#include <sys/time.h>
32
33#include <netinet/in.h>
34
35#include <ctype.h>
36#include <netdb.h>
28#endif
29
30#include <sys/param.h>
31#include <sys/time.h>
32
33#include <netinet/in.h>
34
35#include <ctype.h>
36#include <netdb.h>
37#include <signal.h>
38#include <stdio.h>
39#include <string.h>
40
41#include "interface.h"
42#include "addrtoname.h"
43#include "extract.h" /* must come after interface.h */
44
45#include "llc.h"
46
47static struct tok cmd2str[] = {
48 { LLC_UI, "ui" },
49 { LLC_TEST, "test" },
50 { LLC_XID, "xid" },
51 { LLC_UA, "ua" },
52 { LLC_DISC, "disc" },
53 { LLC_DM, "dm" },
54 { LLC_SABME, "sabme" },
55 { LLC_FRMR, "frmr" },
56 { 0, NULL }
57};
58
59/*
60 * Returns non-zero IFF it succeeds in printing the header
61 */
62int
63llc_print(const u_char *p, u_int length, u_int caplen,
64 const u_char *esrc, const u_char *edst)
65{
66 struct llc llc;
67 register u_short et;
68 register int ret;
69
70 if (caplen < 3) {
71 (void)printf("[|llc]");
72 default_print((u_char *)p, caplen);
73 return(0);
74 }
75
76 /* Watch out for possible alignment problems */
77 memcpy((char *)&llc, (char *)p, min(caplen, sizeof(llc)));
78
79 if (llc.ssap == LLCSAP_GLOBAL && llc.dsap == LLCSAP_GLOBAL) {
80 ipx_print(p, length);
81 return (1);
82 }
83#ifdef notyet
84 else if (p[0] == 0xf0 && p[1] == 0xf0)
85 netbios_print(p, length);
86#endif
87 if (llc.ssap == LLCSAP_ISONS && llc.dsap == LLCSAP_ISONS
88 && llc.llcui == LLC_UI) {
89 isoclns_print(p + 3, length - 3, caplen - 3, esrc, edst);
90 return (1);
91 }
92
93 if (llc.ssap == LLCSAP_SNAP && llc.dsap == LLCSAP_SNAP
94 && llc.llcui == LLC_UI) {
95 if (caplen < sizeof(llc)) {
96 (void)printf("[|llc-snap]");
97 default_print((u_char *)p, caplen);
98 return (0);
99 }
100 if (vflag)
101 (void)printf("snap %s ", protoid_string(llc.llcpi));
102
103 caplen -= sizeof(llc);
104 length -= sizeof(llc);
105 p += sizeof(llc);
106
107 /* This is an encapsulated Ethernet packet */
108 et = EXTRACT_16BITS(&llc.ethertype[0]);
109 ret = ether_encap_print(et, p, length, caplen);
110 if (ret)
111 return (ret);
112 }
113
114 if ((llc.ssap & ~LLC_GSAP) == llc.dsap) {
115 if (eflag)
116 (void)printf("%s ", llcsap_string(llc.dsap));
117 else
118 (void)printf("%s > %s %s ",
119 etheraddr_string(esrc),
120 etheraddr_string(edst),
121 llcsap_string(llc.dsap));
122 } else {
123 if (eflag)
124 (void)printf("%s > %s ",
125 llcsap_string(llc.ssap & ~LLC_GSAP),
126 llcsap_string(llc.dsap));
127 else
128 (void)printf("%s %s > %s %s ",
129 etheraddr_string(esrc),
130 llcsap_string(llc.ssap & ~LLC_GSAP),
131 etheraddr_string(edst),
132 llcsap_string(llc.dsap));
133 }
134
135 if ((llc.llcu & LLC_U_FMT) == LLC_U_FMT) {
136 const char *m;
137 char f;
138 m = tok2str(cmd2str, "%02x", LLC_U_CMD(llc.llcu));
139 switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) {
140 case 0: f = 'C'; break;
141 case LLC_GSAP: f = 'R'; break;
142 case LLC_U_POLL: f = 'P'; break;
143 case LLC_GSAP|LLC_U_POLL: f = 'F'; break;
144 default: f = '?'; break;
145 }
146
147 printf("%s/%c", m, f);
148
149 p += 3;
150 length -= 3;
151 caplen -= 3;
152
153 if ((llc.llcu & ~LLC_U_POLL) == LLC_XID) {
154 if (*p == LLC_XID_FI) {
155 printf(": %02x %02x", p[1], p[2]);
156 p += 3;
157 length -= 3;
158 caplen -= 3;
159 }
160 }
161 } else {
162 char f;
163 llc.llcis = ntohs(llc.llcis);
164 switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) {
165 case 0: f = 'C'; break;
166 case LLC_GSAP: f = 'R'; break;
167 case LLC_U_POLL: f = 'P'; break;
168 case LLC_GSAP|LLC_U_POLL: f = 'F'; break;
169 default: f = '?'; break;
170 }
171
172 if ((llc.llcu & LLC_S_FMT) == LLC_S_FMT) {
173 static char *llc_s[] = { "rr", "rej", "rnr", "03" };
174 (void)printf("%s (r=%d,%c)",
175 llc_s[LLC_S_CMD(llc.llcis)],
176 LLC_IS_NR(llc.llcis),
177 f);
178 } else {
179 (void)printf("I (s=%d,r=%d,%c)",
180 LLC_I_NS(llc.llcis),
181 LLC_IS_NR(llc.llcis),
182 f);
183 }
184 p += 4;
185 length -= 4;
186 caplen -= 4;
187 }
188 (void)printf(" len=%d", length);
189 if (caplen > 0 && !qflag) {
190 default_print_unaligned(p, caplen);
191 }
192 return(1);
193}
37#include <stdio.h>
38#include <string.h>
39
40#include "interface.h"
41#include "addrtoname.h"
42#include "extract.h" /* must come after interface.h */
43
44#include "llc.h"
45
46static struct tok cmd2str[] = {
47 { LLC_UI, "ui" },
48 { LLC_TEST, "test" },
49 { LLC_XID, "xid" },
50 { LLC_UA, "ua" },
51 { LLC_DISC, "disc" },
52 { LLC_DM, "dm" },
53 { LLC_SABME, "sabme" },
54 { LLC_FRMR, "frmr" },
55 { 0, NULL }
56};
57
58/*
59 * Returns non-zero IFF it succeeds in printing the header
60 */
61int
62llc_print(const u_char *p, u_int length, u_int caplen,
63 const u_char *esrc, const u_char *edst)
64{
65 struct llc llc;
66 register u_short et;
67 register int ret;
68
69 if (caplen < 3) {
70 (void)printf("[|llc]");
71 default_print((u_char *)p, caplen);
72 return(0);
73 }
74
75 /* Watch out for possible alignment problems */
76 memcpy((char *)&llc, (char *)p, min(caplen, sizeof(llc)));
77
78 if (llc.ssap == LLCSAP_GLOBAL && llc.dsap == LLCSAP_GLOBAL) {
79 ipx_print(p, length);
80 return (1);
81 }
82#ifdef notyet
83 else if (p[0] == 0xf0 && p[1] == 0xf0)
84 netbios_print(p, length);
85#endif
86 if (llc.ssap == LLCSAP_ISONS && llc.dsap == LLCSAP_ISONS
87 && llc.llcui == LLC_UI) {
88 isoclns_print(p + 3, length - 3, caplen - 3, esrc, edst);
89 return (1);
90 }
91
92 if (llc.ssap == LLCSAP_SNAP && llc.dsap == LLCSAP_SNAP
93 && llc.llcui == LLC_UI) {
94 if (caplen < sizeof(llc)) {
95 (void)printf("[|llc-snap]");
96 default_print((u_char *)p, caplen);
97 return (0);
98 }
99 if (vflag)
100 (void)printf("snap %s ", protoid_string(llc.llcpi));
101
102 caplen -= sizeof(llc);
103 length -= sizeof(llc);
104 p += sizeof(llc);
105
106 /* This is an encapsulated Ethernet packet */
107 et = EXTRACT_16BITS(&llc.ethertype[0]);
108 ret = ether_encap_print(et, p, length, caplen);
109 if (ret)
110 return (ret);
111 }
112
113 if ((llc.ssap & ~LLC_GSAP) == llc.dsap) {
114 if (eflag)
115 (void)printf("%s ", llcsap_string(llc.dsap));
116 else
117 (void)printf("%s > %s %s ",
118 etheraddr_string(esrc),
119 etheraddr_string(edst),
120 llcsap_string(llc.dsap));
121 } else {
122 if (eflag)
123 (void)printf("%s > %s ",
124 llcsap_string(llc.ssap & ~LLC_GSAP),
125 llcsap_string(llc.dsap));
126 else
127 (void)printf("%s %s > %s %s ",
128 etheraddr_string(esrc),
129 llcsap_string(llc.ssap & ~LLC_GSAP),
130 etheraddr_string(edst),
131 llcsap_string(llc.dsap));
132 }
133
134 if ((llc.llcu & LLC_U_FMT) == LLC_U_FMT) {
135 const char *m;
136 char f;
137 m = tok2str(cmd2str, "%02x", LLC_U_CMD(llc.llcu));
138 switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) {
139 case 0: f = 'C'; break;
140 case LLC_GSAP: f = 'R'; break;
141 case LLC_U_POLL: f = 'P'; break;
142 case LLC_GSAP|LLC_U_POLL: f = 'F'; break;
143 default: f = '?'; break;
144 }
145
146 printf("%s/%c", m, f);
147
148 p += 3;
149 length -= 3;
150 caplen -= 3;
151
152 if ((llc.llcu & ~LLC_U_POLL) == LLC_XID) {
153 if (*p == LLC_XID_FI) {
154 printf(": %02x %02x", p[1], p[2]);
155 p += 3;
156 length -= 3;
157 caplen -= 3;
158 }
159 }
160 } else {
161 char f;
162 llc.llcis = ntohs(llc.llcis);
163 switch ((llc.ssap & LLC_GSAP) | (llc.llcu & LLC_U_POLL)) {
164 case 0: f = 'C'; break;
165 case LLC_GSAP: f = 'R'; break;
166 case LLC_U_POLL: f = 'P'; break;
167 case LLC_GSAP|LLC_U_POLL: f = 'F'; break;
168 default: f = '?'; break;
169 }
170
171 if ((llc.llcu & LLC_S_FMT) == LLC_S_FMT) {
172 static char *llc_s[] = { "rr", "rej", "rnr", "03" };
173 (void)printf("%s (r=%d,%c)",
174 llc_s[LLC_S_CMD(llc.llcis)],
175 LLC_IS_NR(llc.llcis),
176 f);
177 } else {
178 (void)printf("I (s=%d,r=%d,%c)",
179 LLC_I_NS(llc.llcis),
180 LLC_IS_NR(llc.llcis),
181 f);
182 }
183 p += 4;
184 length -= 4;
185 caplen -= 4;
186 }
187 (void)printf(" len=%d", length);
188 if (caplen > 0 && !qflag) {
189 default_print_unaligned(p, caplen);
190 }
191 return(1);
192}