File: socktoa.c

package info (click to toggle)
ntp 1%3A4.2.6.p5%2Bdfsg-7
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 22,056 kB
  • sloc: ansic: 144,116; sh: 12,381; perl: 1,401; makefile: 1,274; yacc: 1,034; awk: 417; asm: 37; sed: 7
file content (62 lines) | stat: -rw-r--r-- 981 bytes parent folder | download | duplicates (3)
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
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*
 * socktoa - return a numeric host name from a sockaddr_storage structure
 */

#ifdef HAVE_CONFIG_H
#include <config.h>
#endif

#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>

#ifdef ISC_PLATFORM_NEEDNTOP
#include <isc/net.h>
#endif

#include <stdio.h>

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

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

	LIB_GETBUF(buffer);

	if (NULL == sock)
		strncpy(buffer, "(null)", LIB_BUFLENGTH);
	else {
		switch(AF(sock)) {

		case AF_INET:
		case AF_UNSPEC:
			inet_ntop(AF_INET, PSOCK_ADDR4(sock), buffer,
				  LIB_BUFLENGTH);
			break;

		case AF_INET6:
			inet_ntop(AF_INET6, PSOCK_ADDR6(sock), buffer,
				  LIB_BUFLENGTH);
			break;

		default:
			snprintf(buffer, LIB_BUFLENGTH, 
				 "(socktoa unknown family %d)", 
				 AF(sock));
		}
	}
	return buffer;
}