diff --git a/CHANGELOG b/CHANGELOG index 0bf28ac5..005109fc 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -19,7 +19,10 @@ HISTORY (CVS HEAD) - * [New changes go here] + 2006-03-29 Christiaan Simons + * inet.c, inet.h: Added platform byteswap support. + Added LWIP_PLATFORM_BYTESWAP define (defaults to 0) and + optional LWIP_PLATFORM_HTONS(), LWIP_PLATFORM_HTONL() macros. (STABLE-1_1_1) diff --git a/src/core/inet.c b/src/core/inet.c index 556cbeb5..24cdad39 100644 --- a/src/core/inet.c +++ b/src/core/inet.c @@ -489,11 +489,23 @@ char *inet_ntoa(struct in_addr addr) return str; } +/* + * These are reference implementations of the byte swapping functions. + * Again with the aim of being simple, correct and fully portable. + * Byte swapping is the second thing you would want to optimize. You will + * need to port it to your architecture and in your cc.h: + * + * #define LWIP_PLATFORM_BYTESWAP 1 + * #define LWIP_PLATFORM_HTONS(x) + * #define LWIP_PLATFORM_HTONL(x) + * + * Note ntohs() and ntohl() are merely references to the htonx counterparts. + */ #ifndef BYTE_ORDER #error BYTE_ORDER is not defined #endif -#if BYTE_ORDER == LITTLE_ENDIAN +#if (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) u16_t htons(u16_t n) @@ -522,4 +534,4 @@ ntohl(u32_t n) return htonl(n); } -#endif /* BYTE_ORDER == LITTLE_ENDIAN */ +#endif /* (LWIP_PLATFORM_BYTESWAP == 0) && (BYTE_ORDER == LITTLE_ENDIAN) */ diff --git a/src/include/ipv4/lwip/inet.h b/src/include/ipv4/lwip/inet.h index 6d79aab7..52c67dee 100644 --- a/src/include/ipv4/lwip/inet.h +++ b/src/include/ipv4/lwip/inet.h @@ -64,12 +64,16 @@ char *inet_ntoa(struct in_addr addr); /* returns ptr to static buffer; not reent #undef ntohl #endif /* ntohl */ +#ifndef LWIP_PLATFORM_BYTESWAP +#define LWIP_PLATFORM_BYTESWAP 0 +#endif + #if BYTE_ORDER == BIG_ENDIAN #define htons(x) (x) #define ntohs(x) (x) #define htonl(x) (x) #define ntohl(x) (x) -#else +#else /* BYTE_ORDER != BIG_ENDIAN */ #ifdef LWIP_PREFIX_BYTEORDER_FUNCS /* workaround for naming collisions on some platforms */ #define htons lwip_htons @@ -77,11 +81,19 @@ char *inet_ntoa(struct in_addr addr); /* returns ptr to static buffer; not reent #define htonl lwip_htonl #define ntohl lwip_ntohl #endif +#if LWIP_PLATFORM_BYTESWAP +#define htons(x) LWIP_PLATFORM_HTONS(x) +#define ntohs(x) LWIP_PLATFORM_HTONS(x) +#define htonl(x) LWIP_PLATFORM_HTONL(x) +#define ntohl(x) LWIP_PLATFORM_HTONL(x) +#else u16_t htons(u16_t x); u16_t ntohs(u16_t x); u32_t htonl(u32_t x); u32_t ntohl(u32_t x); #endif +#endif + #endif /* __LWIP_INET_H__ */