37 #ifndef LWIP_HDR_IP4_ADDR_H
38 #define LWIP_HDR_IP4_ADDR_H
57 typedef struct ip4_addr ip4_addr_t;
63 #ifdef PACK_STRUCT_USE_INCLUDES
71 #ifdef PACK_STRUCT_USE_INCLUDES
79 #define IPADDR_NONE ((u32_t)0xffffffffUL)
81 #define IPADDR_LOOPBACK ((u32_t)0x7f000001UL)
83 #define IPADDR_ANY ((u32_t)0x00000000UL)
85 #define IPADDR_BROADCAST ((u32_t)0xffffffffUL)
91 #define IP_CLASSA(a) ((((u32_t)(a)) & 0x80000000UL) == 0)
92 #define IP_CLASSA_NET 0xff000000
93 #define IP_CLASSA_NSHIFT 24
94 #define IP_CLASSA_HOST (0xffffffff & ~IP_CLASSA_NET)
95 #define IP_CLASSA_MAX 128
97 #define IP_CLASSB(a) ((((u32_t)(a)) & 0xc0000000UL) == 0x80000000UL)
98 #define IP_CLASSB_NET 0xffff0000
99 #define IP_CLASSB_NSHIFT 16
100 #define IP_CLASSB_HOST (0xffffffff & ~IP_CLASSB_NET)
101 #define IP_CLASSB_MAX 65536
103 #define IP_CLASSC(a) ((((u32_t)(a)) & 0xe0000000UL) == 0xc0000000UL)
104 #define IP_CLASSC_NET 0xffffff00
105 #define IP_CLASSC_NSHIFT 8
106 #define IP_CLASSC_HOST (0xffffffff & ~IP_CLASSC_NET)
108 #define IP_CLASSD(a) (((u32_t)(a) & 0xf0000000UL) == 0xe0000000UL)
109 #define IP_CLASSD_NET 0xf0000000
110 #define IP_CLASSD_NSHIFT 28
111 #define IP_CLASSD_HOST 0x0fffffff
112 #define IP_MULTICAST(a) IP_CLASSD(a)
114 #define IP_EXPERIMENTAL(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
115 #define IP_BADCLASS(a) (((u32_t)(a) & 0xf0000000UL) == 0xf0000000UL)
117 #define IP_LOOPBACKNET 127
120 #define IP4_ADDR(ipaddr, a,b,c,d) (ipaddr)->addr = PP_HTONL(LWIP_MAKEU32(a,b,c,d))
126 #define IPADDR2_COPY(dest, src) SMEMCPY(dest, src, sizeof(ip4_addr_t))
130 #define ip4_addr_copy(dest, src) ((dest).addr = (src).addr)
132 #define ip4_addr_set(dest, src) ((dest)->addr = \
133 ((src) == NULL ? 0 : \
136 #define ip4_addr_set_zero(ipaddr) ((ipaddr)->addr = 0)
138 #define ip4_addr_set_any(ipaddr) ((ipaddr)->addr = IPADDR_ANY)
140 #define ip4_addr_set_loopback(ipaddr) ((ipaddr)->addr = PP_HTONL(IPADDR_LOOPBACK))
142 #define ip4_addr_isloopback(ipaddr) (((ipaddr)->addr & PP_HTONL(IP_CLASSA_NET)) == PP_HTONL(((u32_t)IP_LOOPBACKNET) << 24))
145 #define ip4_addr_set_hton(dest, src) ((dest)->addr = \
147 lwip_htonl((src)->addr)))
149 #define ip4_addr_set_u32(dest_ipaddr, src_u32) ((dest_ipaddr)->addr = (src_u32))
151 #define ip4_addr_get_u32(src_ipaddr) ((src_ipaddr)->addr)
154 #define ip4_addr_get_network(target, host, netmask) do { ((target)->addr = ((host)->addr) & ((netmask)->addr)); } while(0)
164 #define ip4_addr_netcmp(addr1, addr2, mask) (((addr1)->addr & \
168 #define ip4_addr_cmp(addr1, addr2) ((addr1)->addr == (addr2)->addr)
170 #define ip4_addr_isany_val(addr1) ((addr1).addr == IPADDR_ANY)
171 #define ip4_addr_isany(addr1) ((addr1) == NULL || ip4_addr_isany_val(*(addr1)))
173 #define ip4_addr_isbroadcast(addr1, netif) ip4_addr_isbroadcast_u32((addr1)->addr, netif)
176 #define ip_addr_netmask_valid(netmask) ip4_addr_netmask_valid((netmask)->addr)
179 #define ip4_addr_ismulticast(addr1) (((addr1)->addr & PP_HTONL(0xf0000000UL)) == PP_HTONL(0xe0000000UL))
181 #define ip4_addr_islinklocal(addr1) (((addr1)->addr & PP_HTONL(0xffff0000UL)) == PP_HTONL(0xa9fe0000UL))
183 #define ip4_addr_debug_print_parts(debug, a, b, c, d) \
184 LWIP_DEBUGF(debug, ("%" U16_F ".%" U16_F ".%" U16_F ".%" U16_F, a, b, c, d))
185 #define ip4_addr_debug_print(debug, ipaddr) \
186 ip4_addr_debug_print_parts(debug, \
187 (u16_t)((ipaddr) != NULL ? ip4_addr1_16(ipaddr) : 0), \
188 (u16_t)((ipaddr) != NULL ? ip4_addr2_16(ipaddr) : 0), \
189 (u16_t)((ipaddr) != NULL ? ip4_addr3_16(ipaddr) : 0), \
190 (u16_t)((ipaddr) != NULL ? ip4_addr4_16(ipaddr) : 0))
191 #define ip4_addr_debug_print_val(debug, ipaddr) \
192 ip4_addr_debug_print_parts(debug, \
193 ip4_addr1_16(&(ipaddr)), \
194 ip4_addr2_16(&(ipaddr)), \
195 ip4_addr3_16(&(ipaddr)), \
196 ip4_addr4_16(&(ipaddr)))
199 #define ip4_addr1(ipaddr) (((const u8_t*)(&(ipaddr)->addr))[0])
200 #define ip4_addr2(ipaddr) (((const u8_t*)(&(ipaddr)->addr))[1])
201 #define ip4_addr3(ipaddr) (((const u8_t*)(&(ipaddr)->addr))[2])
202 #define ip4_addr4(ipaddr) (((const u8_t*)(&(ipaddr)->addr))[3])
205 #define ip4_addr1_16(ipaddr) ((u16_t)ip4_addr1(ipaddr))
206 #define ip4_addr2_16(ipaddr) ((u16_t)ip4_addr2(ipaddr))
207 #define ip4_addr3_16(ipaddr) ((u16_t)ip4_addr3(ipaddr))
208 #define ip4_addr4_16(ipaddr) ((u16_t)ip4_addr4(ipaddr))
210 #define IP4ADDR_STRLEN_MAX 16
213 #define ip_ntoa(ipaddr) ipaddr_ntoa(ipaddr)
215 u32_t ipaddr_addr(
const char *cp);
216 int ip4addr_aton(
const char *cp, ip4_addr_t *addr);
218 char *ip4addr_ntoa(
const ip4_addr_t *addr);
219 char *ip4addr_ntoa_r(
const ip4_addr_t *addr,
char *buf,
int buflen);