PageRenderTime 47ms CodeModel.GetById 44ms app.highlight 1ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/ntp/libntp/socktohost.c

https://bitbucket.org/freebsd/freebsd-head/
C | 31 lines | 21 code | 7 blank | 3 comment | 1 complexity | fbab8167551fb67d8770b565e8c3e9f2 MD5 | raw file
 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
18char *
19socktohost(
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}