Date: Mon, 11 Mar 2002 15:59:07 -0800 From: "Crist J. Clark" <cjc@FreeBSD.ORG> To: alpha <alpha_byte@centras.lt> Cc: FreeBSD <freebsd-net@FreeBSD.ORG> Subject: Re: help with tcp checksum Message-ID: <20020311155906.B29705@blossom.cjclark.org> In-Reply-To: <00bd01c1c906$72f7be30$fb1b3bd4@alpha>; from alpha_byte@centras.lt on Mon, Mar 11, 2002 at 04:10:02PM %2B0200 References: <00bd01c1c906$72f7be30$fb1b3bd4@alpha>
next in thread | previous in thread | raw e-mail | index | archive | help
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 ..<HTML><body>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<br>using > 0090 20 61 20 50 49 43 20 31 36 46 38 37 34 3C 62 72 .a.PIC.16F874<br > 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)</bo > 00C0 64 79 3E 3C 2F 48 54 4D 4C 3E dy></HTML> > > 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20020311155906.B29705>