Added LWIP_PLATFORM_BYTESWAP optimalisation flag and macro glue.

This commit is contained in:
christiaans 2006-03-29 10:15:43 +00:00
parent d9b4ab1658
commit 94abf9d935
3 changed files with 31 additions and 4 deletions

View File

@ -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)

View File

@ -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) <your_htons>
* #define LWIP_PLATFORM_HTONL(x) <your_htonl>
*
* 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) */

View File

@ -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__ */