From owner-freebsd-net Mon Mar 11 7:31:11 2002 Delivered-To: freebsd-net@freebsd.org Received: from mail.takas.lt (mail-src.takas.lt [212.59.31.66]) by hub.freebsd.org (Postfix) with ESMTP id 5BA7C37B41C for ; Mon, 11 Mar 2002 07:30:46 -0800 (PST) Received: from alpha ([212.59.27.166]) by mail.takas.lt with Microsoft SMTPSVC(5.0.2195.2966); Mon, 11 Mar 2002 17:30:44 +0200 Message-ID: <003901c1c911$b5f90f30$a61b3bd4@alpha> From: "alpha" To: "Ryan Thompson" Cc: "FreeBSD" References: <20020311090940.B99093-100000@catalyst.sasknow.net> Subject: Re: help with tcp checksum Date: Mon, 11 Mar 2002 17:29:31 +0200 MIME-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: 7bit X-Priority: 3 X-MSMail-Priority: Normal X-Mailer: Microsoft Outlook Express 6.00.2600.0000 X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2600.0000 X-OriginalArrivalTime: 11 Mar 2002 15:30:45.0130 (UTC) FILETIME=[B62FD6A0:01C1C911] 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 hi, it the first place thanx for answering. i'm affraid i can't show my work becouse it's confidential. I'm working on one comercial project. > Well, honestly, I haven't had my coffee yet, so I'd probably screw it > up anyway. I haven't hand-calculated one of these this century, but > perhaps you are forgetting to take the checksum of the IP fields? In ?? you mean IP fields must be calculated in TCP header checksum too? > Maybe if you post some of your work, outline the steps (as opposed to > the wrong answer :-), someone can spot how you got that wrong answer. you know, i downloaded free example from internet, but text portion's checksum of TCP header was writed by hand. i relalculated it and i got wrong answer. and i don't know why. here a part from this example: load_TCP_header( 0x5000 | TCP_ACK | TCP_FIN, 0x07AC, 148); ^^^^^^ this is text portion's checksum, but i get 0798h checksum somehow // Number of bytes include in load_IP_header call printf(outdata,"HTTP/1.0 200 OK\r\n"); printf(outdata,"Content-type: text/html\r\n\r\n"); printf(outdata,"SimmStick® Web Server
"); printf(outdata,"using a PIC 16F874
"); printf(outdata,"by David C. Witt (12/24/00)"); ............................................................................ ................................... void load_TCP_header(long int data_flags, long int tcp_chksum, long int tcp_length) { long int prev_chksum; chksum = tcp_chksum; // calculate checksum of pseudo header prev_chksum = chksum; chksum += ((long)my_ip[0]<<8) + my_ip[1]; if (chksum < prev_chksum) chksum++; prev_chksum = chksum; chksum += ((long)my_ip[2]<<8) + my_ip[3]; if (chksum < prev_chksum) chksum++; prev_chksum = chksum; chksum += ((long)source_ip[0]<<8) + source_ip[1]; if (chksum < prev_chksum) chksum++; prev_chksum = chksum; chksum += ((long)source_ip[2]<<8) + source_ip[3]; if (chksum < prev_chksum) chksum++; prev_chksum = chksum; chksum += TCP; if (chksum < prev_chksum) chksum++; prev_chksum = chksum; chksum += tcp_length; if (chksum < prev_chksum) chksum++; // source port outportw(NIC_DATA, tcp_dest_port); // destination port outportw(NIC_DATA, tcp_source_port); // sequence number outportw(NIC_DATA, xm_seq[0]); outportw(NIC_DATA, xm_seq[1]); // acknowledment number outportw(NIC_DATA, xm_ack[0]); outportw(NIC_DATA, xm_ack[1]); // data offset and flags outportw(NIC_DATA, data_flags); // window outportw(NIC_DATA, 1460); // checksum outportw(NIC_DATA, ~chksum); // urgent pointer outportw(NIC_DATA, 0); ............................................................................ ............. be so kind to help me please. Darius To Unsubscribe: send mail to majordomo@FreeBSD.org with "unsubscribe freebsd-net" in the body of the message