]> The Tcpdump Group git mirrors - tcpdump/commitdiff
When adding the last byte of an odd number of bytes to a TCP or UDP
authorguy <guy>
Sat, 23 Dec 2000 20:55:22 +0000 (20:55 +0000)
committerguy <guy>
Sat, 23 Dec 2000 20:55:22 +0000 (20:55 +0000)
checksum, fetch it by casting the pointer to "const u_int8_t *" rather
than "const char *" - casting it to "const char *" causes it to be
sign-extended, perhaps causing 16 1 bits to be added in at the top and,
at least on big-endian platforms (where "htons()" does nothing, meaning
it won't trim off the extra 16 bits) with signed "char"s (e.g., SPARC),
causing the checksum to be computed incorrectly and causing it to
incorrectly be reported as bad.

print-tcp.c
print-udp.c

index 852300ce51898114c89e589a56c8ebbaff1c9435..9cc707fc9297ae89745ef0b95c8fe6f494850386 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.80 2000-11-17 19:08:16 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.81 2000-12-23 20:55:22 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -169,7 +169,7 @@ static int tcp_cksum(register const struct ip *ip,
                sum += *sp++;
 
        if (tlen & 1) {
-               sum += htons( (*(const char *)sp) << 8);
+               sum += htons( (*(const u_int8_t *)sp) << 8);
        }
 
        while (sum > 0xffff)
@@ -217,7 +217,7 @@ static int tcp6_cksum(const struct ip6_hdr *ip6, const struct tcphdr *tp,
                sum += *sp++;
 
        if (tlen & 1)
-               sum += htons((*(const char *)sp) << 8);
+               sum += htons((*(const u_int8_t *)sp) << 8);
 
        while (sum > 0xffff)
                sum = (sum & 0xffff) + (sum >> 16);
index a95683ec45a48341d5567886b670850151ecc745..c53c319ceb1d7eebc69e9f11ffd0777c68a0d35f 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.89 2000-11-17 19:08:16 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.90 2000-12-23 20:55:22 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -325,7 +325,7 @@ static int udp_cksum(register const struct ip *ip,
                sum += *sp++;
 
        if (tlen & 1) {
-               sum += htons( (*(const char *)sp) << 8);
+               sum += htons( (*(const u_int8_t *)sp) << 8);
        }
 
        while (sum > 0xffff)
@@ -373,7 +373,7 @@ static int udp6_cksum(const struct ip6_hdr *ip6, const struct udphdr *up,
                sum += *sp++;
 
        if (tlen & 1)
-               sum += htons((*(const char *)sp) << 8);
+               sum += htons((*(const u_int8_t *)sp) << 8);
 
        while (sum > 0xffff)
                sum = (sum & 0xffff) + (sum >> 16);