diff --git a/make_tld_serv.pl b/make_tld_serv.pl index c962015..0734702 100755 --- a/make_tld_serv.pl +++ b/make_tld_serv.pl @@ -17,6 +17,7 @@ while (<>) { $b = "\\x03" if $b eq 'NONE'; $b = "\\x08" if $b eq 'AFILIAS'; $b = "\\x0C" if $b eq 'ARPA'; + $b = "\\x0D" if $b eq 'IP6'; print qq| "$a",\t"$b",\n|; } diff --git a/tld_serv_list b/tld_serv_list index 2018a62..787bc93 100644 --- a/tld_serv_list +++ b/tld_serv_list @@ -44,6 +44,7 @@ .e164.arpa whois.ripe.net .in-addr.arpa ARPA +.ip6.arpa IP6 .arpa whois.iana.org .aero whois.aero diff --git a/whois.c b/whois.c index 4dceec6..aff2c9c 100644 --- a/whois.c +++ b/whois.c @@ -368,6 +368,12 @@ int handle_query(const char *hserver, const char *hport, server = guess_server(p); free(p); goto retry; + case 0x0D: + p = convert_in6arpa(query); + free(server); + server = guess_server(p); + free(p); + goto retry; default: break; } @@ -1328,6 +1334,69 @@ char *convert_inaddr(const char *s) return new; } +char *convert_in6arpa(const char *s) +{ + char *ip, *p; + int character = 0; + int digits = 1; + + ip = malloc(40); + + p = strstr(s, ".ip6.arpa"); + if (!p || p == s) { + ip[character] = '\0'; + return ip; + } + + /* start from the first character before ".ip6.arpa" */ + p--; + + while (1) { + /* check that this is a valid digit for an IPv6 address */ + if (!((*p >= '0' && *p <= '9') || (*p >= 'a' && *p <= 'f') || + (*p >= 'A' && *p <= 'F'))) { + free(ip); + ip[character] = '\0'; + return ip; + } + + /* copy the digit to the IP address */ + ip[character++] = *p; + + /* stop if we have reached the beginning of the string */ + if (p == s) + break; + + /* stop if we have parsed a complete address */ + if (character == 39) + break; + + /* add the colon separator every four digits */ + if ((digits++ % 4) == 0) + ip[character++] = ':'; + + /* go to the precedent character and abort if it is not a dot */ + p--; + if (*p != '.') { + ip[character] = '\0'; + return ip; + } + + /* abort if the string starts with the dot */ + if (p == s) { + ip[character] = '\0'; + return ip; + } + + /* go to the precedent character and continue */ + p--; + } + + /* terminate the string */ + ip[character] = '\0'; + return ip; +} + unsigned long myinet_aton(const char *s) { unsigned long a, b, c, d; diff --git a/whois.h b/whois.h index a33a241..353d667 100644 --- a/whois.h +++ b/whois.h @@ -38,6 +38,7 @@ char *normalize_domain(const char *); char *convert_6to4(const char *); char *convert_teredo(const char *); char *convert_inaddr(const char *); +char *convert_in6arpa(const char *); int handle_query(const char *server, const char *port, const char *qstring, const char *fstring); void split_server_port(const char *const input, char **server, char **port);