1 /* 2 * socktoa - return a numeric host name from a sockaddr_storage structure 3 */ 4 5 #include <config.h> 6 7 #include <sys/types.h> 8 #include <sys/socket.h> 9 #include <netinet/in.h> 10 11 #include <arpa/inet.h> 12 13 #ifdef ISC_PLATFORM_NEEDNTOP 14 #include <isc/net.h> 15 #endif 16 17 #include <stdio.h> 18 19 #include "ntp_fp.h" 20 #include "lib_strbuf.h" 21 #include "ntp_stdlib.h" 22 #include "ntp.h" 23 24 char * 25 socktoa( 26 struct sockaddr_storage* sock 27 ) 28 { 29 register char *buffer; 30 31 LIB_GETBUF(buffer); 32 33 if (sock == NULL) 34 strcpy(buffer, "null"); 35 else 36 { 37 38 switch(sock->ss_family) { 39 40 default: 41 case AF_INET : 42 inet_ntop(AF_INET, &GET_INADDR(*sock), buffer, 43 LIB_BUFLENGTH); 44 break; 45 46 case AF_INET6 : 47 inet_ntop(AF_INET6, &GET_INADDR6(*sock), buffer, 48 LIB_BUFLENGTH); 49 #if 0 50 default: 51 strcpy(buffer, "unknown"); 52 #endif 53 } 54 } 55 return buffer; 56 } 57