]>
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.16 1999-11-21 09:36:55 fenner Exp $ (LBL)";
33 #include <sys/types.h>
35 #include <sys/socket.h>
43 #include <netinet/in.h>
44 #include <netinet/if_ether.h>
48 #include "interface.h"
49 #include "addrtoname.h"
50 #include "ethertype.h"
57 static int osi_cksum(const u_char
*, u_int
, const u_char
*, u_char
*, u_char
*);
58 static void esis_print(const u_char
*, u_int
);
61 isoclns_print(const u_char
*p
, u_int length
, u_int caplen
,
62 const u_char
*esrc
, const u_char
*edst
)
65 printf("[|iso-clns] ");
68 etheraddr_string(esrc
),
69 etheraddr_string(edst
));
76 /* esis_print(&p, &length); */
79 (void)printf(" %s > %s",
80 etheraddr_string(esrc
),
81 etheraddr_string(edst
));
87 (void)printf(" %s > %s",
88 etheraddr_string(esrc
),
89 etheraddr_string(edst
));
90 esis_print(p
, length
);
96 (void)printf(" %s > %s",
97 etheraddr_string(esrc
),
98 etheraddr_string(edst
));
99 /* isis_print(&p, &length); */
100 (void)printf(" len=%d ", length
);
102 default_print_unaligned(p
, caplen
);
106 printf("iso-nullns");
108 (void)printf(" %s > %s",
109 etheraddr_string(esrc
),
110 etheraddr_string(edst
));
114 printf("iso-clns %02x", p
[0]);
116 (void)printf(" %s > %s",
117 etheraddr_string(esrc
),
118 etheraddr_string(edst
));
119 (void)printf(" len=%d ", length
);
121 default_print_unaligned(p
, caplen
);
126 #define ESIS_REDIRECT 6
139 esis_print(const u_char
*p
, u_int length
)
143 const struct esis_hdr
*eh
= (const struct esis_hdr
*) &p
[2];
151 printf(" no header at all!");
159 printf(" LI(%d) > PDU size (%d)!", li
, length
);
162 if (li
< sizeof(struct esis_hdr
) + 2) {
166 printf(" too short for esis header %d:", li
);
167 while (--length
!= 0)
168 printf("%02X", *p
++);
172 switch (eh
->type
& 0x1f) {
187 printf(" type %d", eh
->type
& 0x1f);
190 off
[0] = eh
->cksum
[0];
191 off
[1] = eh
->cksum
[1];
192 if (vflag
&& osi_cksum(p
, li
, eh
->cksum
, cksum
, off
)) {
193 printf(" bad cksum (got %02x%02x want %02x%02x)",
194 eh
->cksum
[1], eh
->cksum
[0], cksum
[1], cksum
[0]);
197 if (eh
->version
!= 1) {
198 printf(" unsupported version %d", eh
->version
);
201 p
+= sizeof(*eh
) + 2;
202 li
-= sizeof(*eh
) + 2; /* protoid * li */
204 switch (eh
->type
& 0x1f) {
205 case ESIS_REDIRECT
: {
206 const u_char
*dst
, *snpa
, *is
;
208 dst
= p
; p
+= *p
+ 1;
211 printf(" %s", isonsap_string(dst
));
212 snpa
= p
; p
+= *p
+ 1;
221 printf(" > %s", etheraddr_string(&snpa
[1]));
223 printf(" > %s", isonsap_string(is
));
242 printf(" %s", isonsap_string(is
));
248 (void)printf(" len=%d", length
);
249 if (length
&& p
< snapend
) {
250 length
= snapend
- p
;
251 default_print(p
, length
);
256 while (p
< ep
&& li
) {
263 printf(" bad opts/li");
270 printf(" opt (%d) too long", op
);
278 if (op
== 198 && opli
== 2) {
279 printf(" tmo=%d", q
[0] * 256 + q
[1]);
282 printf (" %d:<", op
);
284 printf("%02x", *q
++);
290 osi_cksum(register const u_char
*p
, register u_int len
,
291 const u_char
*toff
, u_char
*cksum
, u_char
*off
)
293 int x
, y
, f
= (len
- ((toff
- p
) + 1));
294 int32_t c0
= 0, c1
= 0;
296 if ((cksum
[0] = off
[0]) == 0 && (cksum
[1] = off
[1]) == 0)
300 while ((int)--len
>= 0) {
308 x
= 255 - (-x
% 255);
313 y
= 255 - (-y
% 255);
320 return (off
[0] != cksum
[0] || off
[1] != cksum
[1]);