xref: /freebsd/contrib/ntp/libntp/socktoa.c (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
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 <netdb.h>
10 #include <netinet/in.h>
11 
12 #include <arpa/inet.h>
13 
14 #ifdef ISC_PLATFORM_NEEDNTOP
15 #include <isc/net.h>
16 #endif
17 
18 #include <stdio.h>
19 
20 #include "ntp_fp.h"
21 #include "lib_strbuf.h"
22 #include "ntp_stdlib.h"
23 #include "ntp.h"
24 
25 char *
26 socktoa(
27 	struct sockaddr_storage* sock
28 	)
29 {
30 	register char *buffer;
31 
32 	LIB_GETBUF(buffer);
33 
34 	if (sock == NULL) printf("null");
35 
36 	switch(sock->ss_family) {
37 
38 		case AF_INET :
39 			inet_ntop(AF_INET, &GET_INADDR(*sock), buffer,
40 			    LIB_BUFLENGTH);
41 			break;
42 
43 		case AF_INET6 :
44 			inet_ntop(AF_INET6, &GET_INADDR6(*sock), buffer,
45 			    LIB_BUFLENGTH);
46 	}
47   	return buffer;
48 }
49