aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDenys Vlasenko <vda.linux@googlemail.com>2011-09-08 10:59:26 +0200
committerDenys Vlasenko <vda.linux@googlemail.com>2011-09-08 10:59:26 +0200
commit0d0260fd1e55c39525660370094d090bc5412fe5 (patch)
treeb9a29da16629928f441f9d7285f48e2fae609c6f
parent9289935cfd44992be6e403efcccf2edf074d8cc9 (diff)
downloadbusybox-w32-0d0260fd1e55c39525660370094d090bc5412fe5.tar.gz
busybox-w32-0d0260fd1e55c39525660370094d090bc5412fe5.tar.bz2
busybox-w32-0d0260fd1e55c39525660370094d090bc5412fe5.zip
inet_cksum: big-endian fix
Signed-off-by: Denys Vlasenko <vda.linux@googlemail.com>
-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 31bf8c4d9..3d5dc3adf 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)
21 } 21 }
22 22
23 /* Mop up an odd byte, if necessary */ 23 /* Mop up an odd byte, if necessary */
24 if (nleft) 24 if (nleft == 1) {
25 sum += *(uint8_t*)addr; 25 if (BB_LITTLE_ENDIAN)
26 sum += *(uint8_t*)addr;
27 else
28 sum += *(uint8_t*)addr << 8;
29 }
26 30
27 /* Add back carry outs from top 16 bits to low 16 bits */ 31 /* Add back carry outs from top 16 bits to low 16 bits */
28 sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */ 32 sum = (sum >> 16) + (sum & 0xffff); /* add hi 16 to low 16 */