diff options
author | Marco d'Itri <md@linux.it> | 2010-04-11 04:17:33 +0200 |
---|---|---|
committer | Marco d'Itri <md@linux.it> | 2013-03-30 02:31:39 +0100 |
commit | 00a8697ca960ca65be8bf16b95c68dc42835645e (patch) | |
tree | 5266822bc6af45e99f2e03b24d1502e311c2bd40 /whois.c | |
parent | 9627a203ceda5b23fbdd0abd26268a9b6d34be22 (diff) | |
download | whois-00a8697ca960ca65be8bf16b95c68dc42835645e.tar.gz |
Imported Debian version 5.0.2v5.0.2
Diffstat (limited to 'whois.c')
-rw-r--r-- | whois.c | 39 |
1 files changed, 39 insertions, 0 deletions
@@ -34,6 +34,9 @@ #ifdef HAVE_LIBIDN #include <idna.h> #endif +#ifdef HAVE_INET_PTON +#include <arpa/inet.h> +#endif /* Application-specific */ #include "data.h" @@ -430,7 +433,12 @@ const char *guess_server(const char *s) return whereas32(as32); /* smells like an IP? */ +#ifdef HAVE_INET_PTON + if (inet_pton(AF_INET, s, &ip) > 0) { + ip = ntohl(ip); +#else if ((ip = myinet_aton(s))) { +#endif for (i = 0; ip_assign[i].serv; i++) if ((ip & ip_assign[i].mask) == ip_assign[i].net) return ip_assign[i].serv; @@ -1076,6 +1084,18 @@ void split_server_port(const char *const input, char *convert_6to4(const char *s) { char *new; + +#ifdef HAVE_INET_PTON + struct in6_addr ipaddr; + unsigned char *ip; + + if (inet_pton(AF_INET6, s, &ipaddr) <= 0) + return strdup("0.0.0.0"); + + ip = (unsigned char *)&ipaddr; + new = malloc(sizeof("255.255.255.255")); + sprintf(new, "%d.%d.%d.%d", *(ip + 2), *(ip + 3), *(ip + 4), *(ip + 5)); +#else unsigned int a, b; if (sscanf(s, "2002:%x:%x:", &a, &b) != 2) @@ -1083,12 +1103,27 @@ char *convert_6to4(const char *s) new = malloc(sizeof("255.255.255.255")); sprintf(new, "%d.%d.%d.%d", a >> 8, a & 0xff, b >> 8, b & 0xff); +#endif + return new; } char *convert_teredo(const char *s) { char *new; + +#ifdef HAVE_INET_PTON + struct in6_addr ipaddr; + unsigned char *ip; + + if (inet_pton(AF_INET6, s, &ipaddr) <= 0) + return strdup("0.0.0.0"); + + ip = (unsigned char *)&ipaddr; + new = malloc(sizeof("255.255.255.255")); + sprintf(new, "%d.%d.%d.%d", *(ip + 12) ^ 0xff, *(ip + 13) ^ 0xff, + *(ip + 14) ^ 0xff, *(ip + 15) ^ 0xff); +#else unsigned int a, b; if (sscanf(s, "2001:%*[^:]:%*[^:]:%*[^:]:%*[^:]:%*[^:]:%x:%x", &a, &b) != 2) @@ -1098,6 +1133,8 @@ char *convert_teredo(const char *s) b ^= 0xffff; new = malloc(sizeof("255.255.255.255")); sprintf(new, "%d.%d.%d.%d", a >> 8, a & 0xff, b >> 8, b & 0xff); +#endif + return new; } @@ -1133,6 +1170,7 @@ char *convert_inaddr(const char *s) return new; } +#ifndef HAVE_INET_PTON unsigned long myinet_aton(const char *s) { unsigned long a, b, c, d; @@ -1148,6 +1186,7 @@ unsigned long myinet_aton(const char *s) return 0; return (a << 24) + (b << 16) + (c << 8) + d; } +#endif unsigned long asn32_to_long(const char *s) { |