23 #ifndef HAVE_INET_NTOP 25 #ifdef HAVE_SYS_PARAM_H 26 #include <sys/param.h> 28 #ifdef HAVE_NETINET_IN_H 29 #include <netinet/in.h> 31 #ifdef HAVE_ARPA_INET_H 32 #include <arpa/inet.h> 52 char tmp[
sizeof "255.255.255.255"];
58 (void)
snprintf(tmp,
sizeof(tmp),
"%d.%d.%d.%d",
59 ((int)((
unsigned char)src[0])) & 0xff,
60 ((int)((
unsigned char)src[1])) & 0xff,
61 ((int)((
unsigned char)src[2])) & 0xff,
62 ((int)((
unsigned char)src[3])) & 0xff);
65 if(len == 0 || len >= size) {
77 static char *inet_ntop6 (
const unsigned char *src,
char *dst,
size_t size)
86 char tmp[
sizeof(
"ffff:ffff:ffff:ffff:ffff:ffff:255.255.255.255")];
99 memset(words,
'\0',
sizeof(words));
101 words[i/2] |= (src[i] << ((1 - (i % 2)) << 3));
108 for(i = 0; i < (IN6ADDRSZ /
INT16SZ); i++) {
111 cur.base =
i, cur.len = 1;
115 else if(cur.base != -1) {
116 if(best.base == -1 || cur.len > best.len)
121 if((cur.base != -1) && (best.base == -1 || cur.len > best.len))
123 if(best.base != -1 && best.len < 2)
127 for(i = 0; i < (IN6ADDRSZ /
INT16SZ); i++) {
129 if(best.base != -1 && i >= best.base && i < (best.base + best.len)) {
142 if(i == 6 && best.base == 0 &&
143 (best.len == 6 || (best.len == 5 && words[5] == 0xffff))) {
144 if(!
inet_ntop4(src + 12, tp,
sizeof(tmp) - (tp - tmp))) {
151 tp +=
snprintf(tp, 5,
"%lx", words[i]);
156 if(best.base != -1 && (best.base + best.len) == (IN6ADDRSZ /
INT16SZ))
162 if((
size_t)(tp - tmp) > size) {
187 return inet_ntop4((
const unsigned char *)src, buf, size);
190 return inet_ntop6((
const unsigned char *)src, buf, size);
193 errno = EAFNOSUPPORT;
char * Curl_inet_ntop(int af, const void *src, char *buf, size_t size)
static char * inet_ntop4(const unsigned char *src, char *dst, size_t size)