remap: *actually* build, and fix masked logic errors
[tftp-hpa.git] / lib / inet_ntop.c
blobfe8e560d6e1af97b8f557a9d35aa40be7f03fd1a
1 /*
2 * inet_ntop.c
4 * Simple version of inet_ntop()
6 */
8 #include "config.h"
10 extern int errno;
12 const char *inet_ntop(int af, const void *src,
13 char *dst, socklen_t cnt)
15 char *p;
17 switch(af) {
18 case AF_INET:
19 p = inet_ntoa(*((struct in_addr *)src));
20 if (p) {
21 if (cnt <= strlen(p)) {
22 errno = ENOSPC;
23 dst = NULL;
24 } else
25 strcpy(dst, p);
26 } else
27 dst = NULL;
28 break;
29 #ifdef HAVE_IPV6
30 case AF_INET6:
31 if (cnt < 40) {
32 errno = ENOSPC;
33 dst = NULL;
34 } else {
35 struct in6_addr *a = src;
36 int i;
38 p = (char *)dst;
39 /* we do not compress :0: to :: */
40 for (i = 0; i < 8; i++)
41 p += sprintf(p, "%x:", ntohs(a->s6_addr16[i]));
42 p--;
43 *p = 0;
45 break;
46 #endif
47 default:
48 errno = EAFNOSUPPORT;
49 dst = NULL;
51 return dst;