mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2025-08-03 21:14:40 +08:00
Added improved macros for ip address initialization: IPADDR4_INIT_BYTES(), IPADDR6_INIT_HOST() and IP4_ADDR_MAKEU32()
This commit is contained in:
parent
b31b0c8148
commit
ff3656f4f5
@ -118,22 +118,23 @@ struct netif;
|
||||
|
||||
|
||||
#if BYTE_ORDER == BIG_ENDIAN
|
||||
/** Set an IP address given by the four byte-parts */
|
||||
#define IP4_ADDR(ipaddr, a,b,c,d) \
|
||||
(ipaddr)->addr = ((u32_t)((a) & 0xff) << 24) | \
|
||||
((u32_t)((b) & 0xff) << 16) | \
|
||||
((u32_t)((c) & 0xff) << 8) | \
|
||||
(u32_t)((d) & 0xff)
|
||||
/** 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
|
||||
/** Set an IP address given by the four byte-parts.
|
||||
/** 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(ipaddr, a,b,c,d) \
|
||||
(ipaddr)->addr = ((u32_t)((d) & 0xff) << 24) | \
|
||||
((u32_t)((c) & 0xff) << 16) | \
|
||||
((u32_t)((b) & 0xff) << 8) | \
|
||||
(u32_t)((a) & 0xff)
|
||||
#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)
|
||||
|
||||
/** 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
|
||||
* this to copying 2 u16_t's) - no NULL-pointer-checking needed. */
|
||||
|
@ -79,8 +79,12 @@ 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))
|
||||
/** @ingroup ip6addr */
|
||||
#define IPADDR6_INIT(a, b, c, d) { { { { a, b, c, d } } }, IPADDR_TYPE_V6 }
|
||||
/** @ingroup ip6addr */
|
||||
#define IPADDR6_INIT_HOST(a, b, c, d) { { { { PP_HTONL(a), PP_HTONL(b), PP_HTONL(c), PP_HTONL(d) } } }, IPADDR_TYPE_V6 }
|
||||
|
||||
/** @ingroup ipaddr */
|
||||
#define IP_IS_ANY_TYPE_VAL(ipaddr) (IP_GET_TYPE(&ipaddr) == IPADDR_TYPE_ANY)
|
||||
@ -237,6 +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 IP_IS_V4_VAL(ipaddr) 1
|
||||
#define IP_IS_V6_VAL(ipaddr) 0
|
||||
#define IP_IS_V4(ipaddr) 1
|
||||
@ -282,6 +287,7 @@ typedef ip4_addr_t ip_addr_t;
|
||||
|
||||
typedef ip6_addr_t ip_addr_t;
|
||||
#define IPADDR6_INIT(a, b, c, d) { { a, b, c, d } }
|
||||
#define IPADDR6_INIT_HOST(a, b, c, d) { { PP_HTONL(a), PP_HTONL(b), PP_HTONL(c), PP_HTONL(d) } }
|
||||
#define IP_IS_V4_VAL(ipaddr) 0
|
||||
#define IP_IS_V6_VAL(ipaddr) 1
|
||||
#define IP_IS_V4(ipaddr) 0
|
||||
|
Loading…
x
Reference in New Issue
Block a user