xref: /freebsd/contrib/ntp/libntp/socktohost.c (revision 33644623554bb0fc57ed3c7d874193a498679b22)
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 <netinet/in.h>
7 
8 #include <arpa/inet.h>
9 
10 #include <stdio.h>
11 
12 #include "ntp_fp.h"
13 #include "lib_strbuf.h"
14 #include "ntp_stdlib.h"
15 #include "ntp.h"
16 
17 
18 char *
19 socktohost(
20 	struct sockaddr_storage* sock
21 	)
22 {
23 	register char *buffer;
24 
25 	LIB_GETBUF(buffer);
26 	if (getnameinfo((struct sockaddr *)sock, SOCKLEN(sock), buffer,
27 	    LIB_BUFLENGTH /* NI_MAXHOST*/, NULL, 0, 0))
28 		return stoa(sock);
29 
30   	return buffer;
31 }
32