aboutsummaryrefslogtreecommitdiff
path: root/libntp/socktohost.c
blob: 05bbdd64344cd57d7f04eb1ae08f482f8e28d12a (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
/*
 * socktoa - return a numeric host name from a sockaddr_storage structure
 */
#include <sys/types.h>
#ifdef HAVE_SYS_SOCKET_H
#include <sys/socket.h>
#endif
#ifdef HAVE_NETINET_IN_H
#include <netinet/in.h>
#endif

#include <arpa/inet.h>

#include <stdio.h>

#include "ntp_fp.h"
#include "lib_strbuf.h"
#include "ntp_stdlib.h"
#include "ntp.h"


char *
socktohost(
	const sockaddr_u *sock
	)
{
	register char *buffer;

	LIB_GETBUF(buffer);
	if (getnameinfo(&sock->sa, SOCKLEN(sock), buffer,
	    LIB_BUFLENGTH, NULL, 0, 0))
		return stoa(sock);

	return buffer;
}