]>
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.20 2000-10-06 04:23:12 guy Exp $ (LBL)";
33 #include <sys/types.h>
35 #include <sys/socket.h>
37 #include <netinet/in.h>
41 #include "interface.h"
42 #include "addrtoname.h"
43 #include "ethertype.h"
50 static int osi_cksum(const u_char
*, u_int
, const u_char
*, u_char
*, u_char
*);
51 static void esis_print(const u_char
*, u_int
);
54 isoclns_print(const u_char
*p
, u_int length
, u_int caplen
,
55 const u_char
*esrc
, const u_char
*edst
)
58 printf("[|iso-clns] ");
61 etheraddr_string(esrc
),
62 etheraddr_string(edst
));
69 /* esis_print(&p, &length); */
72 (void)printf(" %s > %s",
73 etheraddr_string(esrc
),
74 etheraddr_string(edst
));
80 (void)printf(" %s > %s",
81 etheraddr_string(esrc
),
82 etheraddr_string(edst
));
83 esis_print(p
, length
);
89 (void)printf(" %s > %s",
90 etheraddr_string(esrc
),
91 etheraddr_string(edst
));
92 /* isis_print(&p, &length); */
93 (void)printf(" len=%d ", length
);
95 default_print_unaligned(p
, caplen
);
101 (void)printf(" %s > %s",
102 etheraddr_string(esrc
),
103 etheraddr_string(edst
));
107 printf("iso-clns %02x", p
[0]);
109 (void)printf(" %s > %s",
110 etheraddr_string(esrc
),
111 etheraddr_string(edst
));
112 (void)printf(" len=%d ", length
);
114 default_print_unaligned(p
, caplen
);
119 #define ESIS_REDIRECT 6
132 esis_print(const u_char
*p
, u_int length
)
136 const struct esis_hdr
*eh
= (const struct esis_hdr
*) &p
[2];
144 printf(" no header at all!");
152 printf(" LI(%d) > PDU size (%d)!", li
, length
);
155 if (li
< sizeof(struct esis_hdr
) + 2) {
159 printf(" too short for esis header %d:", li
);
160 while (--length
!= 0)
161 printf("%02X", *p
++);
165 switch (eh
->type
& 0x1f) {
180 printf(" type %d", eh
->type
& 0x1f);
183 off
[0] = eh
->cksum
[0];
184 off
[1] = eh
->cksum
[1];
185 if (vflag
&& osi_cksum(p
, li
, eh
->cksum
, cksum
, off
)) {
186 printf(" bad cksum (got %02x%02x want %02x%02x)",
187 eh
->cksum
[1], eh
->cksum
[0], cksum
[1], cksum
[0]);
190 if (eh
->version
!= 1) {
191 printf(" unsupported version %d", eh
->version
);
194 p
+= sizeof(*eh
) + 2;
195 li
-= sizeof(*eh
) + 2; /* protoid * li */
197 switch (eh
->type
& 0x1f) {
198 case ESIS_REDIRECT
: {
199 const u_char
*dst
, *snpa
, *is
;
201 dst
= p
; p
+= *p
+ 1;
204 printf(" %s", isonsap_string(dst
));
205 snpa
= p
; p
+= *p
+ 1;
214 printf(" > %s", etheraddr_string(&snpa
[1]));
216 printf(" > %s", isonsap_string(is
));
235 printf(" %s", isonsap_string(is
));
241 (void)printf(" len=%d", length
);
242 if (length
&& p
< snapend
) {
243 length
= snapend
- p
;
244 default_print(p
, length
);
249 while (p
< ep
&& li
) {
256 printf(" bad opts/li");
263 printf(" opt (%d) too long", op
);
271 if (op
== 198 && opli
== 2) {
272 printf(" tmo=%d", q
[0] * 256 + q
[1]);
275 printf (" %d:<", op
);
277 printf("%02x", *q
++);
283 osi_cksum(register const u_char
*p
, register u_int len
,
284 const u_char
*toff
, u_char
*cksum
, u_char
*off
)
286 int x
, y
, f
= (len
- ((toff
- p
) + 1));
287 int32_t c0
= 0, c1
= 0;
289 if ((cksum
[0] = off
[0]) == 0 && (cksum
[1] = off
[1]) == 0)
293 while ((int)--len
>= 0) {
301 x
= 255 - (-x
% 255);
306 y
= 255 - (-y
% 255);
313 return (off
[0] != cksum
[0] || off
[1] != cksum
[1]);