Use the passed in length instead of the IP header's length in the
 pseudo-header checksum, to allow for IPSEC or other encapsulations.
Use in_cksum() instead of private versions.
diff --git a/print-mobile.c b/print-mobile.c
index 8d93bbf..f217932 100644
--- a/print-mobile.c
+++ b/print-mobile.c
@@ -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 @@
 
 #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 @@
 		(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);
-}
-
diff --git a/print-tcp.c b/print-tcp.c
index ce1fc9a..54ae3d5 100644
--- a/print-tcp.c
+++ b/print-tcp.c
@@ -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 @@
 		     register const struct tcphdr *tp,
 		     register int len)
 {
-	int i, tlen;
 	union phu {
 		struct phdr {
 			u_int32_t src;
@@ -115,34 +114,18 @@
 		} 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
diff --git a/print-udp.c b/print-udp.c
index fde6aad..bf565a9 100644
--- a/print-udp.c
+++ b/print-udp.c
@@ -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 @@
 		     register const struct udphdr *up,
 		     register int len)
 {
-	int i, tlen;
 	union phu {
 		struct phdr {
 			u_int32_t src;
@@ -300,33 +299,17 @@
 		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 @@
 		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