]>
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.17 2000-07-01 03:39:06 assar Exp $ (LBL)";
33 #include <sys/types.h>
35 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <netinet/if_ether.h>
46 #include "interface.h"
47 #include "addrtoname.h"
48 #include "ethertype.h"
55 static int osi_cksum(const u_char
*, u_int
, const u_char
*, u_char
*, u_char
*);
56 static void esis_print(const u_char
*, u_int
);
59 isoclns_print(const u_char
*p
, u_int length
, u_int caplen
,
60 const u_char
*esrc
, const u_char
*edst
)
63 printf("[|iso-clns] ");
66 etheraddr_string(esrc
),
67 etheraddr_string(edst
));
74 /* esis_print(&p, &length); */
77 (void)printf(" %s > %s",
78 etheraddr_string(esrc
),
79 etheraddr_string(edst
));
85 (void)printf(" %s > %s",
86 etheraddr_string(esrc
),
87 etheraddr_string(edst
));
88 esis_print(p
, length
);
94 (void)printf(" %s > %s",
95 etheraddr_string(esrc
),
96 etheraddr_string(edst
));
97 /* isis_print(&p, &length); */
98 (void)printf(" len=%d ", length
);
100 default_print_unaligned(p
, caplen
);
104 printf("iso-nullns");
106 (void)printf(" %s > %s",
107 etheraddr_string(esrc
),
108 etheraddr_string(edst
));
112 printf("iso-clns %02x", p
[0]);
114 (void)printf(" %s > %s",
115 etheraddr_string(esrc
),
116 etheraddr_string(edst
));
117 (void)printf(" len=%d ", length
);
119 default_print_unaligned(p
, caplen
);
124 #define ESIS_REDIRECT 6
137 esis_print(const u_char
*p
, u_int length
)
141 const struct esis_hdr
*eh
= (const struct esis_hdr
*) &p
[2];
149 printf(" no header at all!");
157 printf(" LI(%d) > PDU size (%d)!", li
, length
);
160 if (li
< sizeof(struct esis_hdr
) + 2) {
164 printf(" too short for esis header %d:", li
);
165 while (--length
!= 0)
166 printf("%02X", *p
++);
170 switch (eh
->type
& 0x1f) {
185 printf(" type %d", eh
->type
& 0x1f);
188 off
[0] = eh
->cksum
[0];
189 off
[1] = eh
->cksum
[1];
190 if (vflag
&& osi_cksum(p
, li
, eh
->cksum
, cksum
, off
)) {
191 printf(" bad cksum (got %02x%02x want %02x%02x)",
192 eh
->cksum
[1], eh
->cksum
[0], cksum
[1], cksum
[0]);
195 if (eh
->version
!= 1) {
196 printf(" unsupported version %d", eh
->version
);
199 p
+= sizeof(*eh
) + 2;
200 li
-= sizeof(*eh
) + 2; /* protoid * li */
202 switch (eh
->type
& 0x1f) {
203 case ESIS_REDIRECT
: {
204 const u_char
*dst
, *snpa
, *is
;
206 dst
= p
; p
+= *p
+ 1;
209 printf(" %s", isonsap_string(dst
));
210 snpa
= p
; p
+= *p
+ 1;
219 printf(" > %s", etheraddr_string(&snpa
[1]));
221 printf(" > %s", isonsap_string(is
));
240 printf(" %s", isonsap_string(is
));
246 (void)printf(" len=%d", length
);
247 if (length
&& p
< snapend
) {
248 length
= snapend
- p
;
249 default_print(p
, length
);
254 while (p
< ep
&& li
) {
261 printf(" bad opts/li");
268 printf(" opt (%d) too long", op
);
276 if (op
== 198 && opli
== 2) {
277 printf(" tmo=%d", q
[0] * 256 + q
[1]);
280 printf (" %d:<", op
);
282 printf("%02x", *q
++);
288 osi_cksum(register const u_char
*p
, register u_int len
,
289 const u_char
*toff
, u_char
*cksum
, u_char
*off
)
291 int x
, y
, f
= (len
- ((toff
- p
) + 1));
292 int32_t c0
= 0, c1
= 0;
294 if ((cksum
[0] = off
[0]) == 0 && (cksum
[1] = off
[1]) == 0)
298 while ((int)--len
>= 0) {
306 x
= 255 - (-x
% 255);
311 y
= 255 - (-y
% 255);
318 return (off
[0] != cksum
[0] || off
[1] != cksum
[1]);