lwip 2.0.3 IP address handling
/** * @file * IP address API (common IPv4 and IPv6) */
1、u32_t ipaddr_addr(const char *cp);
把一个 字符串的 IP 地址转换成 ip4_addr_t 类型的IP。
1 /** 2 * Ascii internet address interpretation routine. 3 * The value returned is in network order. 4 * 5 * @param cp IP address in ascii representation (e.g. "127.0.0.1") 6 * @return ip address in network order 7 */ 8 u32_t 9 ipaddr_addr(const char *cp) 10 { 11 ip4_addr_t val; 12 13 if (ip4addr_aton(cp, &val)) { 14 return ip4_addr_get_u32(&val); 15 } 16 return (IPADDR_NONE); 17 }
2、char *ip4addr_ntoa(const ip4_addr_t *addr);
把一个 ip4_addr_t 类型 的IP地址 转换 成 字符串形式!
1 /** 2 * Convert numeric IP address into decimal dotted ASCII representation. 3 * returns ptr to static buffer; not reentrant! 4 * 5 * @param addr ip address in network order to convert 6 * @return pointer to a global static (!) buffer that holds the ASCII 7 * representation of addr 8 */ 9 char* 10 ip4addr_ntoa(const ip4_addr_t *addr) 11 { 12 static char str[IP4ADDR_STRLEN_MAX]; 13 return ip4addr_ntoa_r(addr, str, IP4ADDR_STRLEN_MAX); 14 }