Sync usage with man page.
[netbsd-mini2440.git] / external / bsd / ntp / dist / libntp / socktoa.c
blobe1060e10ffa45a8f5b28bb9e4d6d50fccf264aa6
1 /* $NetBSD$ */
3 /*
4 * socktoa - return a numeric host name from a sockaddr_storage structure
5 */
7 #ifdef HAVE_CONFIG_H
8 #include <config.h>
9 #endif
11 #include <sys/types.h>
12 #ifdef HAVE_SYS_SOCKET_H
13 #include <sys/socket.h>
14 #endif
15 #ifdef HAVE_NETINET_IN_H
16 #include <netinet/in.h>
17 #endif
19 #include <arpa/inet.h>
21 #ifdef ISC_PLATFORM_NEEDNTOP
22 #include <isc/net.h>
23 #endif
25 #include <stdio.h>
27 #include "ntp_fp.h"
28 #include "lib_strbuf.h"
29 #include "ntp_stdlib.h"
30 #include "ntp.h"
32 char *
33 socktoa(
34 sockaddr_u *sock
37 register char *buffer;
39 LIB_GETBUF(buffer);
41 if (NULL == sock)
42 strncpy(buffer, "(null)", LIB_BUFLENGTH);
43 else {
44 switch(AF(sock)) {
46 case AF_INET:
47 case AF_UNSPEC:
48 inet_ntop(AF_INET, PSOCK_ADDR4(sock), buffer,
49 LIB_BUFLENGTH);
50 break;
52 case AF_INET6:
53 inet_ntop(AF_INET6, PSOCK_ADDR6(sock), buffer,
54 LIB_BUFLENGTH);
55 break;
57 default:
58 snprintf(buffer, LIB_BUFLENGTH,
59 "(socktoa unknown family %d)",
60 AF(sock));
63 return buffer;