diff options
Diffstat (limited to 'libntp/socktoa.c')
-rw-r--r-- | libntp/socktoa.c | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/libntp/socktoa.c b/libntp/socktoa.c new file mode 100644 index 0000000..34de784 --- /dev/null +++ b/libntp/socktoa.c @@ -0,0 +1,48 @@ +/* + * socktoa - return a numeric host name from a sockaddr_storage structure + */ + +#include <config.h> + +#include <sys/types.h> +#include <sys/socket.h> +#include <netdb.h> +#include <netinet/in.h> + +#include <arpa/inet.h> + +#ifdef ISC_PLATFORM_NEEDNTOP +#include <isc/net.h> +#endif + +#include <stdio.h> + +#include "ntp_fp.h" +#include "lib_strbuf.h" +#include "ntp_stdlib.h" +#include "ntp.h" + +char * +socktoa( + struct sockaddr_storage* sock + ) +{ + register char *buffer; + + LIB_GETBUF(buffer); + + if (sock == NULL) printf("null"); + + switch(sock->ss_family) { + + case AF_INET : + inet_ntop(AF_INET, &GET_INADDR(*sock), buffer, + LIB_BUFLENGTH); + break; + + case AF_INET6 : + inet_ntop(AF_INET6, &GET_INADDR6(*sock), buffer, + LIB_BUFLENGTH); + } + return buffer; +} |