PageRenderTime 5ms CodeModel.GetById 1ms app.highlight 2ms RepoModel.GetById 1ms app.codeStats 0ms

/contrib/ntp/libntp/socktoa.c

https://bitbucket.org/freebsd/freebsd-head/
C | 56 lines | 41 code | 12 blank | 3 comment | 2 complexity | 74c0c7445f0f90f3e7db6c80b1f476a2 MD5 | raw file
 1/*
 2 * socktoa - return a numeric host name from a sockaddr_storage structure
 3 */
 4
 5#include <config.h>
 6
 7#include <sys/types.h>
 8#include <sys/socket.h>
 9#include <netinet/in.h>
10
11#include <arpa/inet.h>
12
13#ifdef ISC_PLATFORM_NEEDNTOP
14#include <isc/net.h>
15#endif
16
17#include <stdio.h>
18
19#include "ntp_fp.h"
20#include "lib_strbuf.h"
21#include "ntp_stdlib.h"
22#include "ntp.h"
23
24char *
25socktoa(
26	struct sockaddr_storage* sock
27	)
28{
29	register char *buffer;
30
31	LIB_GETBUF(buffer);
32
33	if (sock == NULL)
34		strcpy(buffer, "null");
35	else
36	{
37
38		switch(sock->ss_family) {
39
40		default:
41		case AF_INET :
42			inet_ntop(AF_INET, &GET_INADDR(*sock), buffer,
43			    LIB_BUFLENGTH);
44			break;
45
46		case AF_INET6 :
47			inet_ntop(AF_INET6, &GET_INADDR6(*sock), buffer,
48			    LIB_BUFLENGTH);
49#if 0
50		default:
51			strcpy(buffer, "unknown");
52#endif
53		}
54	}
55  	return buffer;
56}