xref: /freebsd/contrib/ntp/libntp/socktohost.c (revision 1e413cf93298b5b97441a21d9a50fdcd0ee9945e)
1 /*
2  * socktoa - return a numeric host name from a sockaddr_storage structure
3  */
4 #include <sys/types.h>
5 #include <sys/socket.h>
6 #include <netdb.h>
7 #include <netinet/in.h>
8 
9 #include <arpa/inet.h>
10 
11 #include <stdio.h>
12 
13 #include "ntp_fp.h"
14 #include "lib_strbuf.h"
15 #include "ntp_stdlib.h"
16 #include "ntp.h"
17 
18 
19 char *
20 socktohost(
21 	struct sockaddr_storage* sock
22 	)
23 {
24 	register char *buffer;
25 
26 	LIB_GETBUF(buffer);
27 	if (getnameinfo((struct sockaddr *)sock, SOCKLEN(sock), buffer,
28 	    LIB_BUFLENGTH /* NI_MAXHOST*/, NULL, 0, 0))
29 		return stoa(sock);
30 
31   	return buffer;
32 }
33