summaryrefslogtreecommitdiffstats
path: root/usr.bin/whois
diff options
context:
space:
mode:
authordd <dd@FreeBSD.org>2001-06-27 23:06:47 +0000
committerdd <dd@FreeBSD.org>2001-06-27 23:06:47 +0000
commitc42db86ef37319ecbb7df5e2b083141ac39126d1 (patch)
treeb4f392be1dc278a9e43704c37ab140639d6e1974 /usr.bin/whois
parent7e4cb10f8be4f3c8ce3c90618e09bbc89d7ccef2 (diff)
downloadFreeBSD-src-c42db86ef37319ecbb7df5e2b083141ac39126d1.zip
FreeBSD-src-c42db86ef37319ecbb7df5e2b083141ac39126d1.tar.gz
Implement recursive IP address searches based on the results of a
query to ARIN. PR: 28426 Submitted by: Mike Barcroft <mike@q9media.com>
Diffstat (limited to 'usr.bin/whois')
-rw-r--r--usr.bin/whois/whois.19
-rw-r--r--usr.bin/whois/whois.c28
2 files changed, 29 insertions, 8 deletions
diff --git a/usr.bin/whois/whois.1 b/usr.bin/whois/whois.1
index debe3b1..31dd5c1 100644
--- a/usr.bin/whois/whois.1
+++ b/usr.bin/whois/whois.1
@@ -91,6 +91,15 @@ In the event that an IP
address is specified, the whois server will default to the American
Registry for Internet Numbers
.Pq Tn ARIN .
+If a query to
+.Tn ARIN
+references
+.Tn APNIC
+or
+.Tn RIPE ,
+that server will be queried also, provided that the
+.Fl Q
+option is not specified.
.Pp
If no required
.Pa whois-servers.net
diff --git a/usr.bin/whois/whois.c b/usr.bin/whois/whois.c
index d7508c9..ac2619b 100644
--- a/usr.bin/whois/whois.c
+++ b/usr.bin/whois/whois.c
@@ -77,6 +77,8 @@ static const char rcsid[] =
#define WHOIS_INIC_FALLBACK 0x02
#define WHOIS_QUICK 0x04
+const char *ip_whois[] = { RNICHOST, PNICHOST, NULL };
+
static void usage(void);
static void whois(char *, struct addrinfo *, int);
@@ -208,7 +210,7 @@ whois(char *name, struct addrinfo *res, int flags)
FILE *sfi, *sfo;
struct addrinfo hints, *res2;
char *buf, *nhost, *p;
- int nomatch, error, s;
+ int i, nomatch, error, s;
size_t len;
for (; res; res = res->ai_next) {
@@ -234,13 +236,23 @@ whois(char *name, struct addrinfo *res, int flags)
while (len && isspace(buf[len - 1]))
buf[--len] = '\0';
- if ((flags & WHOIS_RECURSE) && nhost == NULL &&
- (p = strstr(buf, WHOIS_SERVER_ID)) != NULL) {
- p += sizeof(WHOIS_SERVER_ID) - 1;
- if ((len = strcspn(p, " \t\n\r")) != 0) {
- asprintf(&nhost, "%s", p);
- if (nhost == NULL)
- err(1, "asprintf()");
+ if ((flags & WHOIS_RECURSE) && nhost == NULL) {
+ p = strstr(buf, WHOIS_SERVER_ID);
+ if (p != NULL) {
+ p += sizeof(WHOIS_SERVER_ID) - 1;
+ if ((len = strcspn(p, " \t\n\r")) != 0) {
+ asprintf(&nhost, "%s", p);
+ if (nhost == NULL)
+ err(1, "asprintf()");
+ }
+ } else {
+ for (i = 0; ip_whois[i] != NULL; i++) {
+ if (strstr(buf, ip_whois[i]) == NULL)
+ continue;
+ nhost = strdup(ip_whois[i]);
+ if (nhost == NULL)
+ err(1, "strdup()");
+ }
}
}
OpenPOWER on IntegriCloud