summaryrefslogtreecommitdiff
path: root/libbb/inet_cksum.c
diff options
context:
space:
mode:
authorDenys Vlasenko2011-09-08 10:59:26 +0200
committerDenys Vlasenko2011-09-08 10:59:26 +0200
commit0d0260fd1e55c39525660370094d090bc5412fe5 (patch)
treeb9a29da16629928f441f9d7285f48e2fae609c6f /libbb/inet_cksum.c
parent9289935cfd44992be6e403efcccf2edf074d8cc9 (diff)
downloadbusybox-0d0260fd1e55c39525660370094d090bc5412fe5.zip
busybox-0d0260fd1e55c39525660370094d090bc5412fe5.tar.gz
inet_cksum: big-endian fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
Diffstat (limited to 'libbb/inet_cksum.c')
-rw-r--r--libbb/inet_cksum.c8
1 files changed, 6 insertions, 2 deletions
diff --git a/libbb/inet_cksum.c b/libbb/inet_cksum.c
index 31bf8c4..3d5dc3a 100644
--- a/libbb/inet_cksum.c
+++ b/libbb/inet_cksum.c
@@ -21,8 +21,12 @@ uint16_t FAST_FUNC inet_cksum(uint16_t *addr, int nleft)
}
/* Mop up an odd byte, if necessary */
- if (nleft)
- sum += *(uint8_t*)addr;
+ if (nleft == 1) {
+ 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 */
sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */