summaryrefslogtreecommitdiff
path: root/whois.c
diff options
context:
space:
mode:
authorMarco d'Itri <md@linux.it>2008-03-23 19:18:34 +0100
committerMarco d'Itri <md@linux.it>2013-03-30 02:31:36 +0100
commitd0c35c4219530ba3cc323ce6a781a3ba58baf872 (patch)
treea05e3a6f97c816a3d793b087041e6ee1bec7ff5a /whois.c
parent2551e961c2d9be50c9787a18a0772dff558d9a03 (diff)
downloadwhois-d0c35c4219530ba3cc323ce6a781a3ba58baf872.tar.gz
Imported Debian version 4.7.25v4.7.25
Diffstat (limited to 'whois.c')
-rw-r--r--whois.c62
1 files changed, 58 insertions, 4 deletions
diff --git a/whois.c b/whois.c
index 235f179..5396538 100644
--- a/whois.c
+++ b/whois.c
@@ -1,4 +1,4 @@
-/* Copyright 1999-2007 by Marco d'Itri <md@linux.it>.
+/* Copyright 1999-2008 by Marco d'Itri <md@linux.it>.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License version 2 as
@@ -224,19 +224,26 @@ const char *handle_query(const char *hserver, const char *hport,
return NULL;
case 4:
if (verb)
- puts(_("Connecting to whois.crsnic.net."));
+ printf(_("Using server %s.\n"), "whois.crsnic.net");
sockfd = openconn("whois.crsnic.net", NULL);
server = query_crsnic(sockfd, qstring);
break;
case 7:
if (verb)
- puts(_("Connecting to whois.publicinterestregistry.net."));
+ printf(_("Using server %s.\n"),
+ "whois.publicinterestregistry.net");
sockfd = openconn("whois.publicinterestregistry.net", NULL);
server = query_pir(sockfd, qstring);
break;
+ case 8:
+ if (verb)
+ printf(_("Using server %s.\n"), "whois.afilias-grs.info");
+ sockfd = openconn("whois.afilias-grs.info", NULL);
+ server = query_afilias(sockfd, qstring);
+ break;
case 9:
if (verb)
- puts(_("Connecting to whois.nic.cc."));
+ printf(_("Using server %s.\n"), "whois.nic.cc");
sockfd = openconn("whois.nic.cc", NULL);
server = query_crsnic(sockfd, qstring);
break;
@@ -703,6 +710,53 @@ const char *query_pir(const int sock, const char *query)
return ret;
}
+const char *query_afilias(const int sock, const char *query)
+{
+ char *temp, buf[2000], *p, *ret = NULL;
+ FILE *fi;
+ int hide = hide_discl;
+ int state = 0;
+
+ temp = malloc(strlen(query) + 2 + 1);
+ strcpy(temp, query);
+ strcat(temp, "\r\n");
+
+ fi = fdopen(sock, "r");
+ if (write(sock, temp, strlen(temp)) < 0)
+ err_sys("write");
+
+ while (fgets(buf, sizeof(buf), fi)) {
+ if (state == 0 && strneq(buf, "Domain Name:", 12))
+ state = 1;
+ if (state == 1 && strneq(buf, "Whois Server:", 13)) {
+ char *p, *q;
+
+ for (p = buf; *p != ':'; p++); /* skip until colon */
+ for (p++; *p == ' '; p++); /* skip colon and spaces */
+ ret = malloc(strlen(p) + 1);
+ for (q = ret; *p != '\n' && *p != '\r' && *p != ' '; *q++ = *p++)
+ ; /*copy data*/
+ *q = '\0';
+ }
+
+ if (hide_line(&hide, buf))
+ continue;
+
+ for (p = buf; *p && *p != '\r' && *p != '\n'; p++);
+ *p = '\0';
+ fprintf(stdout, "%s\n", buf);
+ }
+ if (ferror(fi))
+ err_sys("fgets");
+ fclose(fi);
+
+ if (hide > HIDE_UNSTARTED)
+ err_quit(_("Catastrophic error: disclaimer text has been changed.\n"
+ "Please upgrade this program.\n"));
+
+ return ret;
+}
+
int openconn(const char *server, const char *port)
{
int fd = -1;