miniupnpd/upnputils.c: do something in case inet_ntop() fails
This commit is contained in:
parent
bedbf88fc6
commit
e810903443
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue