66 const ip_addr_t ip_addr_any = IPADDR4_INIT(IPADDR_ANY);
67 const ip_addr_t ip_addr_broadcast = IPADDR4_INIT(IPADDR_BROADCAST);
77 ip4_addr_isbroadcast_u32(u32_t addr,
const struct netif *
netif)
80 ip4_addr_set_u32(&ipaddr, addr);
83 if ((~addr == IPADDR_ANY) ||
84 (addr == IPADDR_ANY)) {
92 }
else if (addr == ip4_addr_get_u32(netif_ip4_addr(netif))) {
95 }
else if (ip4_addr_netcmp(&ipaddr, netif_ip4_addr(netif), netif_ip4_netmask(netif))
97 && ((addr & ~ip4_addr_get_u32(netif_ip4_netmask(netif))) ==
98 (IPADDR_BROADCAST & ~ip4_addr_get_u32(netif_ip4_netmask(netif))))) {
112 ip4_addr_netmask_valid(u32_t netmask)
115 u32_t nm_hostorder = lwip_htonl(netmask);
118 for (mask = 1UL << 31 ; mask != 0; mask >>= 1) {
119 if ((nm_hostorder & mask) == 0) {
124 for (; mask != 0; mask >>= 1) {
125 if ((nm_hostorder & mask) != 0) {
136 #define in_range(c, lo, up) ((u8_t)c >= lo && (u8_t)c <= up) 137 #define isprint(c) in_range(c, 0x20, 0x7f) 138 #define isdigit(c) in_range(c, '0', '9') 139 #define isxdigit(c) (isdigit(c) || in_range(c, 'a', 'f') || in_range(c, 'A', 'F')) 140 #define islower(c) in_range(c, 'a', 'z') 141 #define isspace(c) (c == ' ' || c == '\f' || c == '\n' || c == '\r' || c == '\t' || c == '\v') 152 ipaddr_addr(
const char *cp)
156 if (ip4addr_aton(cp, &val)) {
157 return ip4_addr_get_u32(&val);
159 return (IPADDR_NONE);
174 ip4addr_aton(
const char *cp, ip4_addr_t *addr)
196 if (c ==
'x' || c ==
'X') {
205 val = (val * base) + (u32_t)(c -
'0');
207 }
else if (base == 16 && isxdigit(c)) {
208 val = (val << 4) | (u32_t)(c + 10 - (islower(c) ?
'a' :
'A'));
221 if (pp >= parts + 3) {
233 if (c !=
'\0' && !isspace(c)) {
240 switch (pp - parts + 1) {
249 if (val > 0xffffffUL) {
252 if (parts[0] > 0xff) {
255 val |= parts[0] << 24;
262 if ((parts[0] > 0xff) || (parts[1] > 0xff)) {
265 val |= (parts[0] << 24) | (parts[1] << 16);
272 if ((parts[0] > 0xff) || (parts[1] > 0xff) || (parts[2] > 0xff)) {
275 val |= (parts[0] << 24) | (parts[1] << 16) | (parts[2] << 8);
278 LWIP_ASSERT(
"unhandled", 0);
282 ip4_addr_set_u32(addr, lwip_htonl(val));
296 ip4addr_ntoa(
const ip4_addr_t *addr)
298 static char str[IP4ADDR_STRLEN_MAX];
299 return ip4addr_ntoa_r(addr, str, IP4ADDR_STRLEN_MAX);
312 ip4addr_ntoa_r(
const ip4_addr_t *addr,
char *buf,
int buflen)
323 s_addr = ip4_addr_get_u32(addr);
326 ap = (u8_t *)&s_addr;
327 for (n = 0; n < 4; n++) {
330 rem = *ap % (u8_t)10;
332 inv[i++] = (char)(
'0' + rem);
335 if (len++ >= buflen) {
340 if (len++ >= buflen) {
#define NETIF_FLAG_BROADCAST