inet.c (mrouted-4.3) | : | inet.c (mrouted-4.4) | ||
---|---|---|---|---|
skipping to change at line 225 | skipping to change at line 225 | |||
* (ping.c) Status - | * (ping.c) Status - | |||
* Public Domain. Distribution Unlimited. | * Public Domain. Distribution Unlimited. | |||
* | * | |||
* I N _ C K S U M | * I N _ C K S U M | |||
* | * | |||
* Checksum routine for Internet Protocol family headers (C Version) | * Checksum routine for Internet Protocol family headers (C Version) | |||
* | * | |||
*/ | */ | |||
int inet_cksum(uint16_t *addr, uint32_t len) | int inet_cksum(uint16_t *addr, uint32_t len) | |||
{ | { | |||
int nleft = (int)len; | int nleft = (int)len; | |||
uint16_t *w = addr; | uint16_t *w = addr; | |||
uint16_t answer = 0; | uint16_t answer = 0; | |||
int32_t sum = 0; | int32_t sum = 0; | |||
/* | /* | |||
* Our algorithm is simple, using a 32 bit accumulator (sum), | * Our algorithm is simple, using a 32 bit accumulator (sum), | |||
* we add sequential 16 bit words to it, and at the end, fold | * we add sequential 16 bit words to it, and at the end, fold | |||
* back all the carry bits from the top 16 bits into the lower | * back all the carry bits from the top 16 bits into the lower | |||
* 16 bits. | * 16 bits. | |||
*/ | */ | |||
while (nleft > 1) { | while (nleft > 1) { | |||
sum += *w++; | sum += *w++; | |||
nleft -= 2; | nleft -= 2; | |||
} | } | |||
/* mop up an odd byte, if necessary */ | /* mop up an odd byte, if necessary */ | |||
if (nleft == 1) { | if (nleft == 1) { | |||
*(uint8_t *) (&answer) = *(uint8_t *)w ; | *(uint8_t *) (&answer) = *(uint8_t *)w ; | |||
sum += answer; | sum += answer; | |||
} | } | |||
/* | /* | |||
* add back carry outs from top 16 bits to low 16 bits | * add back carry outs from top 16 bits to low 16 bits | |||
*/ | */ | |||
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ | sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ | |||
sum += (sum >> 16); /* add carry */ | sum += (sum >> 16); /* add carry */ | |||
answer = ~sum; /* truncate to 16 bits */ | answer = ~sum; /* truncate to 16 bits */ | |||
return answer; | return answer; | |||
} | } | |||
/** | /** | |||
* Local Variables: | * Local Variables: | |||
* indent-tabs-mode: t | * indent-tabs-mode: t | |||
* c-file-style: "ellemtel" | * c-file-style: "cc-mode" | |||
* c-basic-offset: 4 | ||||
* End: | * End: | |||
*/ | */ | |||
End of changes. 6 change blocks. | ||||
28 lines changed or deleted | 27 lines changed or added |