]> The Tcpdump Group git mirrors - tcpdump/commitdiff
Use the passed in length instead of the IP header's length in the
authorfenner <fenner>
Mon, 20 Aug 2001 17:53:53 +0000 (17:53 +0000)
committerfenner <fenner>
Mon, 20 Aug 2001 17:53:53 +0000 (17:53 +0000)
 pseudo-header checksum, to allow for IPSEC or other encapsulations.
Use in_cksum() instead of private versions.

print-mobile.c
print-tcp.c
print-udp.c

index 8d93bbf9cd247a9a636b868da389524ef4deb47b..f217932a4f9ae26b90dbe7d39c0dcfd84c0ac610 100644 (file)
@@ -42,7 +42,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-     "@(#) $Header: /tcpdump/master/tcpdump/print-mobile.c,v 1.6 2001-06-15 22:17:33 fenner Exp $";
+     "@(#) $Header: /tcpdump/master/tcpdump/print-mobile.c,v 1.7 2001-08-20 17:53:54 fenner Exp $";
 #endif
 
 #include <sys/param.h>
@@ -70,8 +70,6 @@ struct mobile_ip {
 
 #define OSRC_PRES      0x0080  /* old source is present */
 
-static u_int16_t mob_in_cksum(u_short *p, int len);
-
 /*
  * Deencapsulate and print a mobile-tunneled IP datagram
  */
@@ -109,34 +107,9 @@ mobile_print(const u_char *bp, u_int length)
                (void)printf("> %s ",ipaddr_string(&mob->odst));
                (void)printf("(oproto=%d)",proto>>8);
        }
-       if (mob_in_cksum((u_short *)mob, osp ? 12 : 8)!=0) {
+       if (in_cksum((u_short *)mob, osp ? 12 : 8, 0)!=0) {
                (void)printf(" (bad checksum %d)",crc);
        }
 
        return;
 }
-
-static u_int16_t mob_in_cksum(u_short *p, int len)
-{
-       u_int32_t sum = 0; 
-       int nwords = len >> 1;
-  
-       while (nwords-- != 0)
-               sum += *p++;
-  
-       if (len & 1) {
-               union {
-                       u_int16_t w;
-                       u_int8_t c[2]; 
-               } u;
-               u.c[0] = *(u_char *)p;
-               u.c[1] = 0;
-               sum += u.w;
-       } 
-
-       /* end-around-carry */
-       sum = (sum >> 16) + (sum & 0xffff);
-       sum += (sum >> 16);
-       return (~sum);
-}
-
index ce1fc9aaec75b2213fa3071ecce71dd3a020941d..54ae3d5571c6d7dff716625f0188baab98d009a5 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.87 2001-06-25 21:38:50 itojun Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-tcp.c,v 1.88 2001-08-20 17:53:53 fenner Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -104,7 +104,6 @@ static int tcp_cksum(register const struct ip *ip,
                     register const struct tcphdr *tp,
                     register int len)
 {
-       int i, tlen;
        union phu {
                struct phdr {
                        u_int32_t src;
@@ -115,34 +114,18 @@ static int tcp_cksum(register const struct ip *ip,
                } ph;
                u_int16_t pa[6];
        } phu;
-       register const u_int16_t *sp;
-       u_int32_t sum;
-       tlen = ntohs(ip->ip_len) - ((const char *)tp-(const char*)ip);
+       const u_int16_t *sp;
 
        /* pseudo-header.. */
-       phu.ph.len = htons(tlen);
+       phu.ph.len = htons(len);        /* XXX */
        phu.ph.mbz = 0;
        phu.ph.proto = IPPROTO_TCP;
        memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
        memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
 
        sp = &phu.pa[0];
-       sum = sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5];
-
-       sp = (const u_int16_t *)tp;
-
-       for (i=0; i<(tlen&~1); i+= 2)
-               sum += *sp++;
-
-       if (tlen & 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,
+                       sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]);
 }
 
 #ifdef INET6
index fde6aad68aa37044bdd95725fef66c9d42ed64da..bf565a9d2743cda343c4d11948db739696a56e75 100644 (file)
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.96 2001-06-26 06:19:06 guy Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/print-udp.c,v 1.97 2001-08-20 17:53:54 fenner Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -288,7 +288,6 @@ static int udp_cksum(register const struct ip *ip,
                     register const struct udphdr *up,
                     register int len)
 {
-       int i, tlen;
        union phu {
                struct phdr {
                        u_int32_t src;
@@ -300,33 +299,17 @@ static int udp_cksum(register const struct ip *ip,
                u_int16_t pa[6];
        } phu;
        register const u_int16_t *sp;
-       u_int32_t sum;
-       tlen = ntohs(ip->ip_len) - ((const char *)up-(const char*)ip);
 
        /* pseudo-header.. */
-       phu.ph.len = htons(tlen);
+       phu.ph.len = htons(len);
        phu.ph.mbz = 0;
        phu.ph.proto = IPPROTO_UDP;
        memcpy(&phu.ph.src, &ip->ip_src.s_addr, sizeof(u_int32_t));
        memcpy(&phu.ph.dst, &ip->ip_dst.s_addr, sizeof(u_int32_t));
 
        sp = &phu.pa[0];
-       sum = sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5];
-
-       sp = (const u_int16_t *)up;
-
-       for (i=0; i<(tlen&~1); i+= 2)
-               sum += *sp++;
-
-       if (tlen & 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 *)up, len,
+                       sp[0]+sp[1]+sp[2]+sp[3]+sp[4]+sp[5]);
 }
 
 #ifdef INET6
@@ -596,7 +579,7 @@ udp_print(register const u_char *bp, u_int length,
                if (sum == 0) {
                        (void)printf("[no cksum] ");
                } else if (TTEST2(cp[0], length)) {
-                       sum = udp_cksum(ip, up, length);
+                       sum = udp_cksum(ip, up, length + sizeof(struct udphdr));
                        if (sum != 0)
                                (void)printf("[bad udp cksum %x!] ", sum);
                        else