miniupnpd/upnputils.c: do something in case inet_ntop() fails

This commit is contained in:
Thomas Bernard 2014-10-22 11:14:48 +02:00
parent bedbf88fc6
commit e810903443
1 changed files with 14 additions and 7 deletions

View File

@ -19,6 +19,7 @@
#ifdef AF_LINK
#include <net/if_dl.h>
#endif
#include <errno.h>
#include "upnputils.h"
#include "upnpglobalvars.h"
@ -35,17 +36,23 @@ sockaddr_to_string(const struct sockaddr * addr, char * str, size_t size)
switch(addr->sa_family)
{
#ifdef AF_INET6
case AF_INET6:
inet_ntop(addr->sa_family,
&((struct sockaddr_in6 *)addr)->sin6_addr,
buffer, sizeof(buffer));
if(inet_ntop(addr->sa_family,
&((struct sockaddr_in6 *)addr)->sin6_addr,
buffer, sizeof(buffer)) == NULL) {
snprintf(buffer, sizeof(buffer), "inet_ntop: %s", strerror(errno));
}
port = ntohs(((struct sockaddr_in6 *)addr)->sin6_port);
n = snprintf(str, size, "[%s]:%hu", buffer, port);
break;
#endif /* AF_INET6 */
case AF_INET:
inet_ntop(addr->sa_family,
&((struct sockaddr_in *)addr)->sin_addr,
buffer, sizeof(buffer));
if(inet_ntop(addr->sa_family,
&((struct sockaddr_in *)addr)->sin_addr,
buffer, sizeof(buffer)) == NULL) {
snprintf(buffer, sizeof(buffer), "inet_ntop: %s", strerror(errno));
}
port = ntohs(((struct sockaddr_in *)addr)->sin_port);
n = snprintf(str, size, "%s:%hu", buffer, port);
break;
@ -63,7 +70,7 @@ sockaddr_to_string(const struct sockaddr * addr, char * str, size_t size)
link_ntoa(sdl));
}
break;
#endif
#endif /* AF_LINK */
default:
n = snprintf(str, size, "unknown address family %d", addr->sa_family);
#if 0