Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Oct 2000 09:29:40 -0700 (PDT)
From:      Archie Cobbs <archie@packetdesign.com>
To:        freebsd-net@freebsd.org
Subject:   tcpdump patch
Message-ID:  <200010241629.e9OGTe426654@bubba.packetdesign.com>

next in thread | raw e-mail | index | archive | help
Anyone care to review this patch? It prints a message if
a TCP packet with a bad checksum is seen.

Thanks,
-Archie

__________________________________________________________________________
Archie Cobbs    *    Packet Design, Inc.   *   http://www.packetdesign.com

Index: src/contrib/tcpdump/interface.h
===================================================================
RCS file: /home/ncvs/src/contrib/tcpdump/interface.h,v
retrieving revision 1.4
diff -u -r1.4 interface.h
--- interface.h	2000/01/30 01:00:50	1.4
+++ interface.h	2000/07/20 00:03:17
@@ -263,4 +263,4 @@
 extern void ospf6_print(const u_char *, u_int);
 extern void dhcp6_print(const u_char *, u_int, u_short, u_short);
 #endif /*INET6*/
-extern u_short in_cksum(const u_short *addr, register int len, u_short csum);
+extern u_short in_cksum(const u_short *addr, register int len, u_int csum);
Index: src/contrib/tcpdump/print-ip.c
===================================================================
RCS file: /home/ncvs/src/contrib/tcpdump/print-ip.c,v
retrieving revision 1.7
diff -u -r1.7 print-ip.c
--- print-ip.c	2000/01/30 01:00:53	1.7
+++ print-ip.c	2000/07/20 00:03:18
@@ -379,12 +379,11 @@
  * don't modifiy the packet.
  */
 u_short
-in_cksum(const u_short *addr, register int len, u_short csum)
+in_cksum(const u_short *addr, register int len, u_int sum)
 {
 	int nleft = len;
 	const u_short *w = addr;
 	u_short answer;
-	int sum = csum;
 
  	/*
 	 *  Our algorithm is simple, using a 32 bit accumulator (sum),
Index: src/contrib/tcpdump/print-tcp.c
===================================================================
RCS file: /home/ncvs/src/contrib/tcpdump/print-tcp.c,v
retrieving revision 1.1.1.4
diff -u -r1.1.1.4 print-tcp.c
--- print-tcp.c	2000/01/30 00:45:48	1.1.1.4
+++ print-tcp.c	2000/07/20 00:03:18
@@ -494,6 +494,25 @@
 	 * Decode payload if necessary.
 	 */
 	bp += (tp->th_off * 4);
+
+	/*       
+	 * Verify the checksum if the full packet was captured
+	 */     
+	if (vflag && TTEST2(*bp, length)) {
+		u_short tlen = (tp->th_off * 4) + length;
+		u_int sum = 0;
+
+		sum += ((u_short *)&ip->ip_src)[0];
+		sum += ((u_short *)&ip->ip_src)[1];
+		sum += ((u_short *)&ip->ip_src)[2];
+		sum += ((u_short *)&ip->ip_src)[3];
+		sum += htons(IPPROTO_TCP);
+		sum += (u_short)htons(tlen);
+		sum = in_cksum((u_short *)tp, tlen, sum);
+		if (sum != 0)
+			(void)printf(" bad tcp cksum %x!", ntohs(tp->th_sum));  
+	}
+
 	if (!qflag && vflag && length > 0
 	 && (sport == TELNET_PORT || dport == TELNET_PORT))
 		telnet_print(bp, length);


To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-net" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200010241629.e9OGTe426654>