Hi, i have a problem to calculate tcp checksums over XXX byte with 260 byte its no problem, but the following packet that i send has 386 byte and wireshark and other tools report that the checksum is incorrect does somebody have an idea what iam doing wrong with the checksum calculation? thanks for any ideas or some help code: ------------------------------------------------------------------------ USHORT TcpCheckSumCalcC(PIPHeader buffer) { unsigned short size, sizetemp; unsigned char * pSize; unsigned char tempchar; unsigned long cksum = 0; unsigned short * TempAddr; unsigned short * TempAddr1; int i = 0; unsigned short uIpLen; TempAddr = (unsigned short *)(&(buffer->ipSource)); for(i=0;i<4;i++) { cksum += *TempAddr; TempAddr++; } cksum += 0x0600; uIpLen = (buffer->ipLength >> 8) + ((buffer->ipLength & 0xff00) << 8); size = uIpLen - (buffer->iphVerLen&0x0f)*4; sizetemp = size ; pSize = (unsigned char *)(&sizetemp); tempchar = pSize[0]; pSize[0] = pSize[1]; pSize[1] = tempchar; cksum += sizetemp; *(TempAddr + 8) = 0; TempAddr1 = TempAddr; while (size > 1) { cksum = cksum + *TempAddr ; TempAddr = TempAddr + 1; size = size - sizeof(unsigned short); } if (size) cksum += *(unsigned char*)TempAddr; cksum = (cksum >> 16) + (cksum & 0xffff); cksum += (cksum >>16); return (unsigned short)(~cksum); }
Check that with standard func from ping example ( from SDK ) Arkady "fkhg1" wrote in message news:u7q84Wt8IHA.1200@TK2MSFTNGP04.phx.gbl... > Hi, > i have a problem to calculate tcp checksums over XXX byte > with 260 byte its no problem, but the following packet that i send has 386 > byte and wireshark and other tools report that the checksum is incorrect > does somebody have an idea what iam doing wrong with the checksum > calculation? > > thanks for any ideas or some help > > > code: > ------------------------------------------------------------------------ > USHORT TcpCheckSumCalcC(PIPHeader buffer) { > unsigned short size, sizetemp; > unsigned char * pSize; > unsigned char tempchar; > unsigned long cksum = 0; > unsigned short * TempAddr; > unsigned short * TempAddr1; > int i = 0; > unsigned short uIpLen; > > TempAddr = (unsigned short *)(&(buffer->ipSource)); > for(i=0;i<4;i++) { > cksum += *TempAddr; > TempAddr++; > } > cksum += 0x0600; > uIpLen = (buffer->ipLength >> 8) + ((buffer->ipLength & 0xff00) << 8); > size = uIpLen - (buffer->iphVerLen&0x0f)*4; > sizetemp = size ; > pSize = (unsigned char *)(&sizetemp); > tempchar = pSize[0]; > pSize[0] = pSize[1]; > pSize[1] = tempchar; > cksum += sizetemp; > *(TempAddr + 8) = 0; > > TempAddr1 = TempAddr; > while (size > 1) { > cksum = cksum + *TempAddr ; > TempAddr = TempAddr + 1; > size = size - sizeof(unsigned short); > } > if (size) > cksum += *(unsigned char*)TempAddr; > cksum = (cksum >> 16) + (cksum & 0xffff); > cksum += (cksum >>16); > return (unsigned short)(~cksum); > }