I have a problem witch calculating TCP or UDP checksum.
This is what I found:
u16 in_cksum(u16 *addr,int count)
{
register long sum = 0;
/* add 16-bit words */
while (count > 1) {
/* this is the inner loop */
sum += * (unsigned short*)addr++;
count -= 2;
}
/* add leftover byte, if any */
if (count > 0)
#if BIG_ENDIAN
sum += (*(unsigned char *)addr) << 8;
#else
sum += *(unsigned char *)addr;
#endif
/* Fold 32-bit sum to 16-bit */
while (sum >> 16)
sum = (sum & 0xffff) + (sum >> 16);
sum = ~sum;
/*
* Return one's compliment of final sum.
*/
return (u16) sum;
}
But it doesn't work. I think that the problem is in the last while, when I
change 32-bit sum to 16-bit. But I didn't find anything else.
Please help me. (I use C not C++)
--
--
--------------------------------------
Pozdrawiam WILK
--------------------------------------