diff --git a/src/core/ipv6/ip6_addr.c b/src/core/ipv6/ip6_addr.c index b3377d3e..67715131 100644 --- a/src/core/ipv6/ip6_addr.c +++ b/src/core/ipv6/ip6_addr.c @@ -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) diff --git a/src/include/lwip/inet.h b/src/include/lwip/inet.h index e7f976b4..33a9d3db 100644 --- a/src/include/lwip/inet.h +++ b/src/include/lwip/inet.h @@ -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 */ diff --git a/src/include/lwip/sockets.h b/src/include/lwip/sockets.h index 116d28ab..9a179745 100644 --- a/src/include/lwip/sockets.h +++ b/src/include/lwip/sockets.h @@ -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 */