diff --git a/src/include/lwip/def.h b/src/include/lwip/def.h index befc4fb7..f3cfccae 100644 --- a/src/include/lwip/def.h +++ b/src/include/lwip/def.h @@ -57,6 +57,12 @@ extern "C" { /* Get the number of entries in an array ('x' must NOT be a pointer!) */ #define LWIP_ARRAYSIZE(x) (sizeof(x)/sizeof((x)[0])) +/** Create u32_t value from bytes */ +#define LWIP_MAKEU32(a,b,c,d) (((u32_t)((a) & 0xff) << 24) | \ + ((u32_t)((b) & 0xff) << 16) | \ + ((u32_t)((c) & 0xff) << 8) | \ + (u32_t)((d) & 0xff)) + #ifndef NULL #ifdef __cplusplus #define NULL 0 diff --git a/src/include/lwip/ip4_addr.h b/src/include/lwip/ip4_addr.h index a53257fe..51b46b8d 100644 --- a/src/include/lwip/ip4_addr.h +++ b/src/include/lwip/ip4_addr.h @@ -116,24 +116,8 @@ struct netif; #define IP_LOOPBACKNET 127 /* official! */ - -#if BYTE_ORDER == BIG_ENDIAN -/** Convert IP address given by the four byte-parts to an u32_t. */ -#define IP4_ADDR_MAKEU32(a,b,c,d) (((u32_t)((a) & 0xff) << 24) | \ - ((u32_t)((b) & 0xff) << 16) | \ - ((u32_t)((c) & 0xff) << 8) | \ - (u32_t)((d) & 0xff)) -#else -/** Convert IP address given by the four byte-parts to an u32_t. - Little-endian version that prevents the use of lwip_htonl. */ -#define IP4_ADDR_MAKEU32(a,b,c,d) (((u32_t)((d) & 0xff) << 24) | \ - ((u32_t)((c) & 0xff) << 16) | \ - ((u32_t)((b) & 0xff) << 8) | \ - (u32_t)((a) & 0xff)) -#endif - /** Set an IP address given by the four byte-parts */ -#define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = IP4_ADDR_MAKEU32(a,b,c,d) +#define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = PP_HTONL(LWIP_MAKEU32(a,b,c,d)) /** MEMCPY-like copying of IP addresses where addresses are known to be * 16-bit-aligned if the port is correctly configured (so a port could define diff --git a/src/include/lwip/ip6_addr.h b/src/include/lwip/ip6_addr.h index 1171df9e..d04472c3 100644 --- a/src/include/lwip/ip6_addr.h +++ b/src/include/lwip/ip6_addr.h @@ -43,6 +43,7 @@ #define LWIP_HDR_IP6_ADDR_H #include "lwip/opt.h" +#include "def.h" #if LWIP_IPV6 /* don't build if not configured for use in lwipopts.h */ @@ -61,23 +62,9 @@ struct ip6_addr { /** IPv6 address */ typedef struct ip6_addr ip6_addr_t; - -#if BYTE_ORDER == BIG_ENDIAN -/** Set an IPv6 partial address given by byte-parts. */ +/** Set an IPv6 partial address given by byte-parts */ #define IP6_ADDR_PART(ip6addr, index, a,b,c,d) \ - (ip6addr)->addr[index] = ((u32_t)((a) & 0xff) << 24) | \ - ((u32_t)((b) & 0xff) << 16) | \ - ((u32_t)((c) & 0xff) << 8) | \ - (u32_t)((d) & 0xff) -#else -/** Set an IPv6 partial address given by byte-parts. -Little-endian version, stored in network order (no lwip_htonl). */ -#define IP6_ADDR_PART(ip6addr, index, a,b,c,d) \ - (ip6addr)->addr[index] = ((u32_t)((d) & 0xff) << 24) | \ - ((u32_t)((c) & 0xff) << 16) | \ - ((u32_t)((b) & 0xff) << 8) | \ - (u32_t)((a) & 0xff) -#endif + (ip6addr)->addr[index] = PP_HTONL(LWIP_MAKEU32(a,b,c,d)) /** Set a full IPv6 address by passing the 4 u32_t indices in network byte order (use PP_HTONL() for constants) */ diff --git a/src/include/lwip/ip_addr.h b/src/include/lwip/ip_addr.h index 855c9788..419cc424 100644 --- a/src/include/lwip/ip_addr.h +++ b/src/include/lwip/ip_addr.h @@ -80,7 +80,7 @@ extern const ip_addr_t ip_addr_any_type; /** @ingroup ip4addr */ #define IPADDR4_INIT(u32val) { { { { u32val, 0ul, 0ul, 0ul } } }, IPADDR_TYPE_V4 } /** @ingroup ip4addr */ -#define IPADDR4_INIT_BYTES(a,b,c,d) IPADDR4_INIT(IP4_ADDR_MAKEU32(a,b,c,d)) +#define IPADDR4_INIT_BYTES(a,b,c,d) IPADDR4_INIT(PP_HTONL(LWIP_MAKEU32(a,b,c,d))) /** @ingroup ip6addr */ #define IPADDR6_INIT(a, b, c, d) { { { { a, b, c, d } } }, IPADDR_TYPE_V6 } /** @ingroup ip6addr */ @@ -241,7 +241,7 @@ int ipaddr_aton(const char *cp, ip_addr_t *addr); typedef ip4_addr_t ip_addr_t; #define IPADDR4_INIT(u32val) { u32val } -#define IPADDR4_INIT_BYTES(a,b,c,d) IPADDR4_INIT(IP4_ADDR_MAKEU32(a,b,c,d)) +#define IPADDR4_INIT_BYTES(a,b,c,d) IPADDR4_INIT(PP_HTONL(LWIP_MAKEU32(a,b,c,d))) #define IP_IS_V4_VAL(ipaddr) 1 #define IP_IS_V6_VAL(ipaddr) 0 #define IP_IS_V4(ipaddr) 1