unsigned short
csum (unsigned short *buf, int nwords)
{
unsigned long sum;
for (sum = 0; nwords > 0; nwords--)
{
sum += *buf++;
}
sum = (sum >> 16) + (sum & 0xffff);
sum += (sum >> 16);
return ((unsigned short) ~sum);
}
- I accept nwords as 16-bit words, not 8-bit bytes (if there is an odd byte, nword is rounded to the next large), is this correct? Say ip_hdr has 27 bytes completely, then nword will be 14 instead of 13, right?
- Sum of line = (sum โ 16) + (sum and 0xffff) is to add a carry to create a 16-bit addition
- sum + = (sum โ 16); What is the purpose of this step? Add bytes on the left? But is the remaining byte already added to the loop?
Thank!
source
share