diff options
Diffstat (limited to 'libntp/socktoa.c')
-rw-r--r-- | libntp/socktoa.c | 40 |
1 files changed, 23 insertions, 17 deletions
diff --git a/libntp/socktoa.c b/libntp/socktoa.c index fb41b22..62e4537 100644 --- a/libntp/socktoa.c +++ b/libntp/socktoa.c @@ -2,11 +2,17 @@ * socktoa - return a numeric host name from a sockaddr_storage structure */ +#ifdef HAVE_CONFIG_H #include <config.h> +#endif #include <sys/types.h> +#ifdef HAVE_SYS_SOCKET_H #include <sys/socket.h> +#endif +#ifdef HAVE_NETINET_IN_H #include <netinet/in.h> +#endif #include <arpa/inet.h> @@ -23,34 +29,34 @@ char * socktoa( - struct sockaddr_storage* sock + const sockaddr_u *sock ) { register char *buffer; LIB_GETBUF(buffer); - if (sock == NULL) - strcpy(buffer, "null"); - else - { + if (NULL == sock) + strncpy(buffer, "(null)", LIB_BUFLENGTH); + else { + switch(AF(sock)) { - switch(sock->ss_family) { + case AF_INET: + case AF_UNSPEC: + inet_ntop(AF_INET, PSOCK_ADDR4(sock), buffer, + LIB_BUFLENGTH); + break; - default: - case AF_INET : - inet_ntop(AF_INET, &GET_INADDR(*sock), buffer, - LIB_BUFLENGTH); + case AF_INET6: + inet_ntop(AF_INET6, PSOCK_ADDR6(sock), buffer, + LIB_BUFLENGTH); break; - case AF_INET6 : - inet_ntop(AF_INET6, &GET_INADDR6(*sock), buffer, - LIB_BUFLENGTH); -#if 0 default: - strcpy(buffer, "unknown"); -#endif + snprintf(buffer, LIB_BUFLENGTH, + "(socktoa unknown family %d)", + AF(sock)); } } - return buffer; + return buffer; } |