tftp-hpa-google/lib/inet_ntop.c
Karsten Keil 7fe0fb941c IPv6 infrastructure support
Add autoconf rules to detect IPv6 availability and some of the neeeded
support functions. Add stubs for getaddrinfo and inet_ntop.
You can disable IPv6 at compile time with
./configure --without-ipv6

Signed-off-by: Karsten Keil <kkeil@suse.de>
Signed-off-by: H. Peter Anvin <hpa@zytor.com>
2008-07-23 14:24:19 -04:00

52 lines
1 KiB
C

/*
* inet_ntop.c
*
* Simple version of inet_ntop()
*
*/
#include "config.h"
extern int errno;
const char *inet_ntop(int af, const void *src,
char *dst, socklen_t cnt)
{
char *p;
switch(af) {
case AF_INET:
p = inet_ntoa(*((struct in_addr *)src));
if (p) {
if (cnt <= strlen(p)) {
errno = ENOSPC;
dst = NULL;
} else
strcpy(dst, p);
} else
dst = NULL;
break;
#ifdef HAVE_IPV6
case AF_INET6:
if (cnt < 40) {
errno = ENOSPC;
dst = NULL;
} else {
struct in6_addr *a = src;
int i;
p = (char *)dst;
/* we do not compress :0: to :: */
for (i = 0; i < 8; i++)
p += sprintf(p, "%x:", ntohs(a->s6_addr16[i]));
p--;
*p = 0;
}
break;
#endif
default:
errno = EAFNOSUPPORT;
dst = NULL;
}
return dst;
}