Date: Mon, 11 Mar 2002 17:29:31 +0200 From: "alpha" <alpha_byte@centras.lt> To: "Ryan Thompson" <ryan@sasknow.com> Cc: "FreeBSD" <freebsd-net@freebsd.org> Subject: Re: help with tcp checksum Message-ID: <003901c1c911$b5f90f30$a61b3bd4@alpha> References: <20020311090940.B99093-100000@catalyst.sasknow.net>
next in thread | previous in thread | raw e-mail | index | archive | help
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,"<HTML><body>SimmStick® Web Server<br>"); printf(outdata,"using a PIC 16F874<br>"); printf(outdata,"by David C. Witt (12/24/00)</body></HTML>"); ............................................................................ ................................... 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
Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?003901c1c911$b5f90f30$a61b3bd4>