Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/tcpdump fix the cksum routine and parse ESH packets.
details: https://anonhg.NetBSD.org/src/rev/15abed6badb1
branches: trunk
changeset: 471554:15abed6badb1
user: chopps <chopps%NetBSD.org@localhost>
date: Mon Apr 05 00:58:29 1999 +0000
description:
fix the cksum routine and parse ESH packets.
diffstat:
usr.sbin/tcpdump/print-isoclns.c | 70 +++++++++++++++++++++++++--------------
1 files changed, 44 insertions(+), 26 deletions(-)
diffs (113 lines):
diff -r 0ce8689459cf -r 15abed6badb1 usr.sbin/tcpdump/print-isoclns.c
--- a/usr.sbin/tcpdump/print-isoclns.c Mon Apr 05 00:22:47 1999 +0000
+++ b/usr.sbin/tcpdump/print-isoclns.c Mon Apr 05 00:58:29 1999 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: print-isoclns.c,v 1.4 1997/10/03 19:55:21 christos Exp $ */
+/* $NetBSD: print-isoclns.c,v 1.5 1999/04/05 00:58:29 chopps Exp $ */
/*
* Copyright (c) 1992, 1993, 1994, 1995, 1996
@@ -29,7 +29,7 @@
static const char rcsid[] =
"@(#) Header: print-isoclns.c,v 1.15 96/12/31 21:27:41 leres Exp (LBL)";
#else
-__RCSID("$NetBSD: print-isoclns.c,v 1.4 1997/10/03 19:55:21 christos Exp $");
+__RCSID("$NetBSD: print-isoclns.c,v 1.5 1999/04/05 00:58:29 chopps Exp $");
#endif
#endif
@@ -231,11 +231,27 @@
li = ep - p;
break;
}
-#if 0
- case ESIS_ESH:
- printf(" esh");
+ case ESIS_ESH: {
+ const u_char *nsap;
+ int i, nnsaps;
+
+ nnsaps = *p++;
+
+ /* print NSAPs */
+ for (i = 0; i < nnsaps; i++) {
+ nsap = p;
+ p += *p + 1;
+ if (p > ep) {
+ printf(" [bad li]");
+ return;
+ }
+ if (p > snapend)
+ return;
+ printf(" nsap %s", isonsap_string(nsap));
+ }
+ li = ep - p;
break;
-#endif
+ }
case ESIS_ISH: {
const u_char *is;
@@ -246,7 +262,7 @@
}
if (p > snapend)
return;
- printf(" %s", isonsap_string(is));
+ printf(" net %s", isonsap_string(is));
li = ep - p;
break;
}
@@ -297,32 +313,34 @@
osi_cksum(register const u_char *p, register u_int len,
const u_char *toff, u_char *cksum, u_char *off)
{
- int x, y, f = (len - ((toff - p) + 1));
- int32_t c0 = 0, c1 = 0;
+ const u_char *ep;
+ int c0, c1;
+ int n;
if ((cksum[0] = off[0]) == 0 && (cksum[1] = off[1]) == 0)
return 0;
- off[0] = off[1] = 0;
- while ((int)--len >= 0) {
- c0 += *p++;
+ n = toff - p + 1;
+ c0 = c1 = 0;
+ ep = p + len;
+ for (; p < toff; p++) {
+ c0 = (c0 + *p);
c1 += c0;
- c0 %= 255;
- c1 %= 255;
}
- x = (c0 * f - c1);
- if (x < 0)
- x = 255 - (-x % 255);
- else
- x %= 255;
- y = -1 * (x + c0);
- if (y < 0)
- y = 255 - (-y % 255);
- else
- y %= 255;
+
+ /* skip cksum bytes */
+ p += 2;
+ c1 += c0; c1 += c0;
- off[0] = x;
- off[1] = y;
+ for (; p < ep; p++) {
+ c0 = (c0 + *p);
+ c1 += c0;
+ }
+
+ c1 = (((c0 * (len - n)) - c1) % 255);
+ cksum[0] = (u_char) ((c1 < 0) ? c1 + 255 : c1);
+ c1 = (-(int) (c1 + c0)) % 255;
+ cksum[1] = (u_char) (c1 < 0 ? c1 + 255 : c1);
return (off[0] != cksum[0] || off[1] != cksum[1]);
}
Home |
Main Index |
Thread Index |
Old Index