Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/usr.sbin/tcpdump implement tcp6 pseudo header cksum.
details: https://anonhg.NetBSD.org/src/rev/58ead8e1649e
branches: trunk
changeset: 495607:58ead8e1649e
user: itojun <itojun%NetBSD.org@localhost>
date: Tue Aug 01 17:24:40 2000 +0000
description:
implement tcp6 pseudo header cksum.
diffstat:
usr.sbin/tcpdump/print-tcp.c | 64 ++++++++++++++++++++++++++++++++++++++++++-
1 files changed, 62 insertions(+), 2 deletions(-)
diffs (92 lines):
diff -r 4cbbab2801d9 -r 58ead8e1649e usr.sbin/tcpdump/print-tcp.c
--- a/usr.sbin/tcpdump/print-tcp.c Tue Aug 01 16:49:47 2000 +0000
+++ b/usr.sbin/tcpdump/print-tcp.c Tue Aug 01 17:24:40 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: print-tcp.c,v 1.16 1999/12/10 05:45:08 itojun Exp $ */
+/* $NetBSD: print-tcp.c,v 1.17 2000/08/01 17:24:40 itojun Exp $ */
/*
* Copyright (c) 1988, 1989, 1990, 1991, 1992, 1993, 1994, 1995, 1996, 1997
@@ -27,7 +27,7 @@
static const char rcsid[] =
"@(#) Header: print-tcp.c,v 1.55 97/06/15 13:20:28 leres Exp (LBL)";
#else
-__RCSID("$NetBSD: print-tcp.c,v 1.16 1999/12/10 05:45:08 itojun Exp $");
+__RCSID("$NetBSD: print-tcp.c,v 1.17 2000/08/01 17:24:40 itojun Exp $");
#endif
#endif
@@ -159,6 +159,54 @@
return (sum);
}
+#ifdef INET6
+static int tcp6_cksum(const struct ip6_hdr *ip6, const struct tcphdr *tp,
+ int len)
+{
+ int i, tlen;
+ register const u_int16_t *sp;
+ u_int32_t sum;
+ union {
+ struct {
+ struct in6_addr ph_src;
+ struct in6_addr ph_dst;
+ u_int32_t ph_len;
+ u_int8_t ph_zero[3];
+ u_int8_t ph_nxt;
+ } ph;
+ u_int16_t pa[20];
+ } phu;
+
+ tlen = ntohs(ip6->ip6_plen) + sizeof(struct ip6_hdr) -
+ ((const char *)tp - (const char*)ip6);
+
+ /* pseudo-header */
+ memset(&phu, 0, sizeof(phu));
+ phu.ph.ph_src = ip6->ip6_src;
+ phu.ph.ph_dst = ip6->ip6_dst;
+ phu.ph.ph_len = htonl(tlen);
+ phu.ph.ph_nxt = IPPROTO_TCP;
+
+ sum = 0;
+ for (i = 0; i < sizeof(phu.pa) / sizeof(phu.pa[0]); i++)
+ sum += phu.pa[i];
+
+ sp = (const u_int16_t *)tp;
+
+ for (i = 0; i < (tlen & ~1); i += 2)
+ sum += *sp++;
+
+ if (tlen & 1)
+ sum += htons((*(const char *)sp) << 8);
+
+ while (sum > 0xffff)
+ sum = (sum & 0xffff) + (sum >> 16);
+ sum = ~sum & 0xffff;
+
+ return (sum);
+}
+#endif
+
void
tcp_print(register const u_char *bp, register u_int length,
@@ -379,6 +427,18 @@
(void)printf(" [tcp sum ok]");
}
}
+#ifdef INET6
+ if (ip->ip_v == 6 && ip6->ip6_plen && vflag) {
+ int sum;
+ if (TTEST2(tp->th_sport, length)) {
+ sum = tcp6_cksum(ip6, tp, length);
+ if (sum != 0)
+ (void)printf(" [bad tcp cksum %x!]", sum);
+ else
+ (void)printf(" [tcp sum ok]");
+ }
+ }
+#endif
length -= hlen;
if (length > 0 || flags & (TH_SYN | TH_FIN | TH_RST))
Home |
Main Index |
Thread Index |
Old Index