Fixed ntoa/aton/ntop/pton definitions after making IPv4 optional

This commit is contained in:
sg 2015-04-13 20:52:42 +02:00
parent bc99f75b53
commit 69c337b31d
3 changed files with 22 additions and 13 deletions

View File

@ -251,7 +251,7 @@ ip6addr_ntoa_r(const ip6_addr_t *addr, char *buf, int buflen)
#if LWIP_IPV4
/** Convert IPv6 address to generic IP address.
* Since source types do not contain the type field, a target storage need to be supplied.
* Since source types do not contain the type field, a target storage needs to be supplied.
*/
ip_addr_t*
ip6_2_ip(const ip6_addr_t *ip6addr, ip_addr_t* storage)
@ -266,6 +266,10 @@ ip6_2_ip(const ip6_addr_t *ip6addr, ip_addr_t* storage)
/** Convert IP address string (both versions) to numeric.
* The version is auto-detected from the string.
*
* @param cp IP address string to convert
* @param addr conversion result is stored here
* @return 1 on success, 0 on error
*/
int
ipaddr_aton(const char *cp, ip_addr_t *addr)

View File

@ -139,9 +139,9 @@ extern const struct in6_addr in6addr_any;
/* directly map this to the lwip internal functions */
#define inet_addr(cp) ipaddr_addr(cp)
#define inet_aton(cp, addr) ipaddr_aton(cp, (ip4_addr_t*)addr)
#define inet_ntoa(addr) ipaddr_ntoa((const ip4_addr_t*)&(addr))
#define inet_ntoa_r(addr, buf, buflen) ipaddr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
#define inet_aton(cp, addr) ip4addr_aton(cp, (ip4_addr_t*)addr)
#define inet_ntoa(addr) ip4addr_ntoa((const ip4_addr_t*)&(addr))
#define inet_ntoa_r(addr, buf, buflen) ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen)
#endif /* LWIP_IPV4 */

View File

@ -464,19 +464,24 @@ int lwip_fcntl(int s, int cmd, int val);
#define fcntl(a,b,c) lwip_fcntl(a,b,c)
#endif /* LWIP_POSIX_SOCKETS_IO_NAMES */
#if LWIP_IPV6
#if LWIP_IPV4 && LWIP_IPV6
#define inet_ntop(af,src,dst,size) \
(((af) == AF_INET6) ? ip6addr_ntoa_r((src),(dst),(size)) \
: (((af) == AF_INET) ? ipaddr_ntoa_r((src),(dst),(size)) : NULL))
(((af) == AF_INET6) ? ip6addr_ntoa_r((const ip6_addr_t*)(src),(dst),(size)) \
: (((af) == AF_INET) ? ip4addr_ntoa_r((const ip4_addr_t*)(src),(dst),(size)) : NULL))
#define inet_pton(af,src,dst) \
(((af) == AF_INET6) ? inet6_aton((src),(dst)) \
: (((af) == AF_INET) ? inet_aton((src),(dst)) : 0))
#else /* LWIP_IPV6 */
(((af) == AF_INET6) ? ip6addr_aton((src),(ip6_addr_t*)(dst)) \
: (((af) == AF_INET) ? ip4addr_aton((src),(ip4_addr_t*)(dst)) : 0))
#elif LWIP_IPV4 /* LWIP_IPV4 && LWIP_IPV6 */
#define inet_ntop(af,src,dst,size) \
(((af) == AF_INET) ? ipaddr_ntoa_r((src),(dst),(size)) : NULL)
(((af) == AF_INET) ? ip4addr_ntoa_r((const ip4_addr_t*)(src),(dst),(size)) : NULL)
#define inet_pton(af,src,dst) \
(((af) == AF_INET) ? inet_aton((src),(dst)) : 0)
#endif /* LWIP_IPV6 */
(((af) == AF_INET) ? ip4addr_aton((src),(ip4_addr_t*)(dst)) : 0)
#else /* LWIP_IPV4 && LWIP_IPV6 */
#define inet_ntop(af,src,dst,size) \
(((af) == AF_INET6) ? ip6addr_ntoa_r((const ip6_addr_t*)(src),(dst),(size)) : NULL)
#define inet_pton(af,src,dst) \
(((af) == AF_INET6) ? ip6addr_aton((src),(ip6_addr_t*)(dst)) : 0)
#endif /* LWIP_IPV4 && LWIP_IPV6 */
#endif /* LWIP_COMPAT_SOCKETS */