[BusyBox] udhcp patches/ endianess
Eric Lammerts
busybox at lists.lammerts.org
Tue Feb 1 14:13:12 UTC 2005
On Mon, 31 Jan 2005, Rainer Weikusat wrote:
> Compile-time support for different endianesses.
> +choice
> + prompt "Target byte order"
No need for a new config option...
#include <endian.h>
#if __BYTE_ORDER == __LITTLE_ENDIAN
But you shouldn't those defines anyway. Your stuff looks terribly
complicated, why not do something simple like this?
--- networking/udhcp/packet.c.orig 2005-02-01 09:04:03.000000000 -0500
+++ networking/udhcp/packet.c 2005-02-01 09:05:21.000000000 -0500
@@ -93,17 +93,14 @@
while (count > 1) {
/* This is the inner loop */
- sum += *source++;
+ sum += ntohs(*source);
+ source++;
count -= 2;
}
/* Add left-over byte, if any */
if (count > 0) {
- /* Make sure that the left-over byte is added correctly both
- * with little and big endian hosts */
- uint16_t tmp = 0;
- *(uint8_t *) (&tmp) = * (uint8_t *) source;
- sum += tmp;
+ sum += *(uint8_t *)source << 8;
}
/* Fold 32-bit sum to 16 bits */
while (sum >> 16)
More information about the busybox
mailing list