This is an optional patch which removes duplicated code 
from tcp6_cksum: comparison shows that the code of in_cksum
re-appears in that function.

In addition, it fixes a typo in printing invalid checksums:
        * previously: "cksum xDEAD (incorrect (-> xBEEF)"
        * now:        "cksum xDEAD (incorrect -> xBEEF)"


Regards
Gerrit Renker
---
 print-tcp.c |   20 +++-----------------
 1 file changed, 3 insertions(+), 17 deletions(-)
diff --git a/print-tcp.c b/print-tcp.c
index 11bd6b7..a988c52 100644
--- a/print-tcp.c
+++ b/print-tcp.c
@@ -147,8 +147,7 @@ static int tcp6_cksum(const struct ip6_h
 	u_int len)
 {
 	size_t i;
-	register const u_int16_t *sp;
-	u_int32_t sum;
+	u_int32_t sum = 0;
 	union {
 		struct {
 			struct in6_addr ph_src;
@@ -167,23 +166,10 @@ static int tcp6_cksum(const struct ip6_h
 	phu.ph.ph_len = htonl(len);
 	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 < (len & ~1); i += 2)
-		sum += *sp++;
-
-	if (len & 1)
-		sum += htons((*(const u_int8_t *)sp) << 8);
-
-	while (sum > 0xffff)
-		sum = (sum & 0xffff) + (sum >> 16);
-	sum = ~sum & 0xffff;
-
-	return (sum);
+	return in_cksum((u_short *)tp, len, sum);
 }
 #endif
 
@@ -428,7 +414,7 @@ #endif
                         (void)printf(", cksum 0x%04x",EXTRACT_16BITS(&tp->th_sum));
 			if (sum != 0) {
 				tcp_sum = EXTRACT_16BITS(&tp->th_sum);
-				(void)printf(" (incorrect (-> 0x%04x),",in_cksum_shouldbe(tcp_sum, sum));
+				(void)printf(" (incorrect -> 0x%04x),",in_cksum_shouldbe(tcp_sum, sum));
 			} else
 				(void)printf(" (correct),");
 		}
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.

Reply via email to