mirror of
https://github.com/lwip-tcpip/lwip.git
synced 2025-03-25 16:44:04 +00:00
Improved some defines working on ip addresses, added faster macro to copy addresses that cannot be NULL
This commit is contained in:
parent
dfb80c6b86
commit
7e0204bb7b
@ -19,6 +19,10 @@ HISTORY
|
|||||||
|
|
||||||
++ New features:
|
++ New features:
|
||||||
|
|
||||||
|
2010-02-14: Simon Goldschmidt/Stephane Lesage
|
||||||
|
* ip_addr.h: Improved some defines working on ip addresses, added faster
|
||||||
|
macro to copy addresses that cannot be NULL
|
||||||
|
|
||||||
2010-02-13: Simon Goldschmidt
|
2010-02-13: Simon Goldschmidt
|
||||||
* api.h, api_lib.c, api_msg.c, sockets.c: task #7865 (implement non-
|
* api.h, api_lib.c, api_msg.c, sockets.c: task #7865 (implement non-
|
||||||
blocking send operation)
|
blocking send operation)
|
||||||
|
@ -123,16 +123,29 @@ extern const ip_addr_t ip_addr_broadcast;
|
|||||||
#define IP_LOOPBACKNET 127 /* official! */
|
#define IP_LOOPBACKNET 127 /* official! */
|
||||||
|
|
||||||
|
|
||||||
|
#if BYTE_ORDER == BIG_ENDIAN
|
||||||
|
/** Set an IP address given by the four byte-parts */
|
||||||
#define IP4_ADDR(ipaddr, a,b,c,d) \
|
#define IP4_ADDR(ipaddr, a,b,c,d) \
|
||||||
(ipaddr)->addr = htonl(((u32_t)((a) & 0xff) << 24) | \
|
(ipaddr)->addr = ((u32_t)((a) & 0xff) << 24) | \
|
||||||
((u32_t)((b) & 0xff) << 16) | \
|
((u32_t)((b) & 0xff) << 16) | \
|
||||||
((u32_t)((c) & 0xff) << 8) | \
|
((u32_t)((c) & 0xff) << 8) | \
|
||||||
(u32_t)((d) & 0xff))
|
(u32_t)((d) & 0xff)
|
||||||
|
#else
|
||||||
|
/** Set an IP address given by the four byte-parts.
|
||||||
|
Little-endian version that prevents the use of 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)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
/** Copy IP address - faster than ip_addr_set: no NULL check */
|
||||||
|
#define ip_addr_copy(dest, src) ((dest).addr = (src).addr)
|
||||||
/** Safely copy one IP address to another (src may be NULL) */
|
/** Safely copy one IP address to another (src may be NULL) */
|
||||||
#define ip_addr_set(dest, src) ((dest)->addr = \
|
#define ip_addr_set(dest, src) ((dest)->addr = \
|
||||||
((src) == NULL ? 0:\
|
((src) == NULL ? 0 : \
|
||||||
(src)->addr))
|
(src)->addr))
|
||||||
/** Set complete address to zero */
|
/** Set complete address to zero */
|
||||||
#define ip_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
|
#define ip_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
|
||||||
/** Set address to IPADDR_ANY (no need for htonl()) */
|
/** Set address to IPADDR_ANY (no need for htonl()) */
|
||||||
@ -166,7 +179,7 @@ extern const ip_addr_t ip_addr_broadcast;
|
|||||||
(mask)->addr))
|
(mask)->addr))
|
||||||
#define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
|
#define ip_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
|
||||||
|
|
||||||
#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == 0)
|
#define ip_addr_isany(addr1) ((addr1) == NULL || (addr1)->addr == IPADDR_ANY)
|
||||||
|
|
||||||
u8_t ip_addr_isbroadcast(ip_addr_t *, struct netif *);
|
u8_t ip_addr_isbroadcast(ip_addr_t *, struct netif *);
|
||||||
|
|
||||||
@ -175,21 +188,17 @@ u8_t ip_addr_isbroadcast(ip_addr_t *, struct netif *);
|
|||||||
#define ip_addr_islinklocal(addr1) (((addr1)->addr & ntohl(0xffff0000UL)) == ntohl(0xa9fe0000UL))
|
#define ip_addr_islinklocal(addr1) (((addr1)->addr & ntohl(0xffff0000UL)) == ntohl(0xa9fe0000UL))
|
||||||
|
|
||||||
#define ip_addr_debug_print(debug, ipaddr) \
|
#define ip_addr_debug_print(debug, ipaddr) \
|
||||||
LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \
|
LWIP_DEBUGF(debug, ("%"U16_F".%"U16_F".%"U16_F".%"U16_F, \
|
||||||
ipaddr != NULL ? \
|
ipaddr != NULL ? ip4_addr1_16(ipaddr) : 0, \
|
||||||
(u16_t)(ntohl((ipaddr)->addr) >> 24) & 0xff : 0, \
|
ipaddr != NULL ? ip4_addr2_16(ipaddr) : 0, \
|
||||||
ipaddr != NULL ? \
|
ipaddr != NULL ? ip4_addr3_16(ipaddr) : 0, \
|
||||||
(u16_t)(ntohl((ipaddr)->addr) >> 16) & 0xff : 0, \
|
ipaddr != NULL ? ip4_addr4_16(ipaddr) : 0))
|
||||||
ipaddr != NULL ? \
|
|
||||||
(u16_t)(ntohl((ipaddr)->addr) >> 8) & 0xff : 0, \
|
|
||||||
ipaddr != NULL ? \
|
|
||||||
(u16_t)ntohl((ipaddr)->addr) & 0xff : 0))
|
|
||||||
|
|
||||||
/* Get one byte from the 4-byte address */
|
/* Get one byte from the 4-byte address */
|
||||||
#define ip4_addr1(ipaddr) ((u8_t)(ntohl((ipaddr)->addr) >> 24) & 0xff)
|
#define ip4_addr1(ipaddr) (((u8_t*)(ipaddr))[0])
|
||||||
#define ip4_addr2(ipaddr) ((u8_t)(ntohl((ipaddr)->addr) >> 16) & 0xff)
|
#define ip4_addr2(ipaddr) (((u8_t*)(ipaddr))[1])
|
||||||
#define ip4_addr3(ipaddr) ((u8_t)(ntohl((ipaddr)->addr) >> 8) & 0xff)
|
#define ip4_addr3(ipaddr) (((u8_t*)(ipaddr))[2])
|
||||||
#define ip4_addr4(ipaddr) ((u8_t)(ntohl((ipaddr)->addr)) & 0xff)
|
#define ip4_addr4(ipaddr) (((u8_t*)(ipaddr))[3])
|
||||||
/* These are cast to u16_t, with the intent that they are often arguments
|
/* These are cast to u16_t, with the intent that they are often arguments
|
||||||
* to printf using the U16_F format from cc.h. */
|
* to printf using the U16_F format from cc.h. */
|
||||||
#define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr))
|
#define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr))
|
||||||
|
Loading…
x
Reference in New Issue
Block a user