]>
The Tcpdump Group git mirrors - tcpdump/blob - print-isoclns.c
2 * Copyright (c) 1992, 1993, 1994, 1995, 1996
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 * Original code by Matt Thomas, Digital Equipment Corporation
25 static const char rcsid
[] =
26 "@(#) $Header: /tcpdump/master/tcpdump/print-isoclns.c,v 1.19 2000-09-28 06:43:02 guy Exp $ (LBL)";
33 #include <sys/types.h>
35 #include <sys/socket.h>
40 #include <netinet/in.h>
44 #include "interface.h"
45 #include "addrtoname.h"
46 #include "ethertype.h"
53 static int osi_cksum(const u_char
*, u_int
, const u_char
*, u_char
*, u_char
*);
54 static void esis_print(const u_char
*, u_int
);
57 isoclns_print(const u_char
*p
, u_int length
, u_int caplen
,
58 const u_char
*esrc
, const u_char
*edst
)
61 printf("[|iso-clns] ");
64 etheraddr_string(esrc
),
65 etheraddr_string(edst
));
72 /* esis_print(&p, &length); */
75 (void)printf(" %s > %s",
76 etheraddr_string(esrc
),
77 etheraddr_string(edst
));
83 (void)printf(" %s > %s",
84 etheraddr_string(esrc
),
85 etheraddr_string(edst
));
86 esis_print(p
, length
);
92 (void)printf(" %s > %s",
93 etheraddr_string(esrc
),
94 etheraddr_string(edst
));
95 /* isis_print(&p, &length); */
96 (void)printf(" len=%d ", length
);
98 default_print_unaligned(p
, caplen
);
102 printf("iso-nullns");
104 (void)printf(" %s > %s",
105 etheraddr_string(esrc
),
106 etheraddr_string(edst
));
110 printf("iso-clns %02x", p
[0]);
112 (void)printf(" %s > %s",
113 etheraddr_string(esrc
),
114 etheraddr_string(edst
));
115 (void)printf(" len=%d ", length
);
117 default_print_unaligned(p
, caplen
);
122 #define ESIS_REDIRECT 6
135 esis_print(const u_char
*p
, u_int length
)
139 const struct esis_hdr
*eh
= (const struct esis_hdr
*) &p
[2];
147 printf(" no header at all!");
155 printf(" LI(%d) > PDU size (%d)!", li
, length
);
158 if (li
< sizeof(struct esis_hdr
) + 2) {
162 printf(" too short for esis header %d:", li
);
163 while (--length
!= 0)
164 printf("%02X", *p
++);
168 switch (eh
->type
& 0x1f) {
183 printf(" type %d", eh
->type
& 0x1f);
186 off
[0] = eh
->cksum
[0];
187 off
[1] = eh
->cksum
[1];
188 if (vflag
&& osi_cksum(p
, li
, eh
->cksum
, cksum
, off
)) {
189 printf(" bad cksum (got %02x%02x want %02x%02x)",
190 eh
->cksum
[1], eh
->cksum
[0], cksum
[1], cksum
[0]);
193 if (eh
->version
!= 1) {
194 printf(" unsupported version %d", eh
->version
);
197 p
+= sizeof(*eh
) + 2;
198 li
-= sizeof(*eh
) + 2; /* protoid * li */
200 switch (eh
->type
& 0x1f) {
201 case ESIS_REDIRECT
: {
202 const u_char
*dst
, *snpa
, *is
;
204 dst
= p
; p
+= *p
+ 1;
207 printf(" %s", isonsap_string(dst
));
208 snpa
= p
; p
+= *p
+ 1;
217 printf(" > %s", etheraddr_string(&snpa
[1]));
219 printf(" > %s", isonsap_string(is
));
238 printf(" %s", isonsap_string(is
));
244 (void)printf(" len=%d", length
);
245 if (length
&& p
< snapend
) {
246 length
= snapend
- p
;
247 default_print(p
, length
);
252 while (p
< ep
&& li
) {
259 printf(" bad opts/li");
266 printf(" opt (%d) too long", op
);
274 if (op
== 198 && opli
== 2) {
275 printf(" tmo=%d", q
[0] * 256 + q
[1]);
278 printf (" %d:<", op
);
280 printf("%02x", *q
++);
286 osi_cksum(register const u_char
*p
, register u_int len
,
287 const u_char
*toff
, u_char
*cksum
, u_char
*off
)
289 int x
, y
, f
= (len
- ((toff
- p
) + 1));
290 int32_t c0
= 0, c1
= 0;
292 if ((cksum
[0] = off
[0]) == 0 && (cksum
[1] = off
[1]) == 0)
296 while ((int)--len
>= 0) {
304 x
= 255 - (-x
% 255);
309 y
= 255 - (-y
% 255);
316 return (off
[0] != cksum
[0] || off
[1] != cksum
[1]);