summaryrefslogtreecommitdiff
path: root/whois.c
diff options
context:
space:
mode:
authorMarco d'Itri <md@linux.it>2014-09-13 01:21:18 +0200
committerMarco d'Itri <md@linux.it>2014-09-13 02:42:29 +0200
commitc7769cbfdf68a122d5d4ebf587d1273bda060b57 (patch)
treeb2e96a97b4eabdc3f8f3cc6924359834efcd5908 /whois.c
parent512005132456507e1360d2d24478e75c4d2e6e9f (diff)
downloadwhois-c7769cbfdf68a122d5d4ebf587d1273bda060b57.tar.gz
make is_new_gtld() return the TLD
Diffstat (limited to 'whois.c')
-rw-r--r--whois.c19
1 files changed, 6 insertions, 13 deletions
diff --git a/whois.c b/whois.c
index 8097080..9248e5a 100644
--- a/whois.c
+++ b/whois.c
@@ -392,7 +392,7 @@ char *guess_server(const char *s)
{
unsigned long ip, as32;
unsigned int i;
- const char *colon;
+ const char *colon, *tld;
/* IPv6 address */
if ((colon = strchr(s, ':'))) {
@@ -460,16 +460,9 @@ char *guess_server(const char *s)
return strdup(tld_serv[i + 1]);
/* use the default server name for "new" gTLDs */
- if (is_new_gtld(s)) {
- char *server;
- const char *p, *tld = NULL;
-
- for (p = s; *p; p++) /* look for the TLD */
- if (*p == '.')
- tld = p;
-
- server = malloc(strlen("whois.nic") + strlen(tld) + 1);
- strcpy(server, "whois.nic");
+ if ((tld = is_new_gtld(s))) {
+ char *server = malloc(strlen("whois.nic.") + strlen(tld) + 1);
+ strcpy(server, "whois.nic.");
strcat(server, tld);
return(server);
}
@@ -983,13 +976,13 @@ int domcmp(const char *dom, const char *tld)
return 0;
}
-int is_new_gtld(const char *s)
+const char *is_new_gtld(const char *s)
{
int i;
for (i = 0; new_gtlds[i]; i++)
if (domcmp(s, new_gtlds[i]))
- return 1;
+ return new_gtlds[i] + 1;
return 0;
}