inet_cksum: big-endian fix

Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
This commit is contained in:
Denys Vlasenko 2011-09-08 10:59:26 +02:00
parent 9289935cfd
commit 0d0260fd1e

View File

@ -21,8 +21,12 @@ uint16_t FAST_FUNC inet_cksum(uint16_t *addr, int nleft)
} }
/* Mop up an odd byte, if necessary */ /* Mop up an odd byte, if necessary */
if (nleft) if (nleft == 1) {
sum += *(uint8_t*)addr; if (BB_LITTLE_ENDIAN)
sum += *(uint8_t*)addr;
else
sum += *(uint8_t*)addr << 8;
}
/* 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 */