[git commit] inet_cksum: big-endian fix

Denys Vlasenko vda.linux at googlemail.com
Thu Sep 8 08:59:26 UTC 2011


commit: http://git.busybox.net/busybox/commit/?id=0d0260fd1e55c39525660370094d090bc5412fe5
branch: http://git.busybox.net/busybox/commit/?id=refs/heads/master

Signed-off-by: Denys Vlasenko <vda.linux at googlemail.com>
---
 libbb/inet_cksum.c |    8 ++++++--
 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 */
-- 
1.7.3.4



More information about the busybox-cvs mailing list