From owner-freebsd-net Mon Mar 11 15:59:15 2002 Delivered-To: freebsd-net@freebsd.org Received: from rwcrmhc54.attbi.com (rwcrmhc54.attbi.com [216.148.227.87]) by hub.freebsd.org (Postfix) with ESMTP id AB33937B400 for ; Mon, 11 Mar 2002 15:59:08 -0800 (PST) Received: from blossom.cjclark.org ([12.234.91.48]) by rwcrmhc54.attbi.com (InterMail vM.4.01.03.27 201-229-121-127-20010626) with ESMTP id <20020311235908.JCPV1214.rwcrmhc54.attbi.com@blossom.cjclark.org>; Mon, 11 Mar 2002 23:59:08 +0000 Received: (from cjc@localhost) by blossom.cjclark.org (8.11.6/8.11.6) id g2BNx7330730; Mon, 11 Mar 2002 15:59:07 -0800 (PST) (envelope-from cjc) Date: Mon, 11 Mar 2002 15:59:07 -0800 From: "Crist J. Clark" To: alpha Cc: FreeBSD Subject: Re: help with tcp checksum Message-ID: <20020311155906.B29705@blossom.cjclark.org> References: <00bd01c1c906$72f7be30$fb1b3bd4@alpha> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline User-Agent: Mutt/1.2.5i In-Reply-To: <00bd01c1c906$72f7be30$fb1b3bd4@alpha>; from alpha_byte@centras.lt on Mon, Mar 11, 2002 at 04:10:02PM +0200 X-URL: http://people.freebsd.org/~cjc/ Sender: owner-freebsd-net@FreeBSD.ORG Precedence: bulk List-ID: List-Archive: (Web Archive) List-Help: (List Instructions) List-Subscribe: List-Unsubscribe: X-Loop: FreeBSD.org On Mon, Mar 11, 2002 at 04:10:02PM +0200, alpha wrote: > hi, > > nobody wants to help me with checksum. so i decided to ask very simply. > here's my generated all packet from david c. witt site's example code: > > 0000 00 50 04 35 44 49 00 80 48 AF D8 3E 08 00 45 00 .P.5DI..H..>..E. > 0010 00 BC 49 00 00 00 FF 06 F0 E4 C0 A8 00 05 C0 A8 ..I............. > 0020 00 01 00 50 04 06 00 AA 00 5F 00 0C 50 62 50 11 ...P....._..PbP. > 0030 05 B4 CA CF 00 00 48 54 54 50 2F 31 2E 30 20 32 ......HTTP/1.0.2 > 0040 30 30 20 4F 4B 0D 0A 43 6F 6E 74 65 6E 74 2D 74 00.OK..Content-t > 0050 79 70 65 3A 20 74 65 78 74 2F 68 74 6D 6C 0D 0A ype:.text/html.. > 0060 0D 0A 3C 48 54 4D 4C 3E 3C 62 6F 64 79 3E 53 69 ..Si > 0070 6D 6D 53 74 69 63 6B 26 72 65 67 3B 20 57 65 62 mmStick®.Web > 0080 20 53 65 72 76 65 72 3C 62 72 3E 75 73 69 6E 67 .Server
using > 0090 20 61 20 50 49 43 20 31 36 46 38 37 34 3C 62 72 .a.PIC.16F874
00A0 3E 62 79 20 44 61 76 69 64 20 43 2E 20 57 69 74 >by.David.C..Wit > 00B0 74 20 28 31 32 2F 32 34 2F 30 30 29 3C 2F 62 6F t.(12/24/00) 00C0 64 79 3E 3C 2F 48 54 4D 4C 3E dy> > > TCP header begins at 0022h. as you can see checksum generated is CACFh. and > simple question: how to get this checksum? i know all algorithms, but they > show me CAE3h, but not CACFh. if you don't be lazy and try to calculate it, > you'll see that i'm right. but how computer accepts packet with this > checksum and rejects with correct - CAE3h. Well, I "did it by hand" and 0xcacf is correct. I took your datagram and using awk and manually building the pseudo-TCP header got it into a format like, C0A8 <---- 0005 C0A8 Pseudo-header 0001 0006 00a8 <---- 0050 <---- 0406 00AA 005F 000C TCP segment 5062 ... 544D 4C3E <--- And then ran it through this simple perl script, $ perl -ne 'chomp; $sum += hex($_); $sum = ( $sum > 65535 ) ? $sum -= 65535 : $sum; printf "0x%x\n", $sum;' And sure enough, the last sum comes out to, ... 0x5f74 0xb3c1 0xffff Which says it is correct. I can check the sender by zeroing the checksum in the input, and the same perl command gives, ... 0x94a4 0xe8f1 0x3530 Which is correct, the ones-complement of 0xcacf. Looks like your calculations are wrong. -- Crist J. Clark | cjclark@alum.mit.edu | cjclark@jhu.edu http://people.freebsd.org/~cjc/ | cjc@freebsd.org To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message