From mike@transient.lotterycanada.com  Tue Jun 26 14:06:37 2001
Return-Path: <mike@transient.lotterycanada.com>
Received: from transient.lotterycanada.com (transient.lotterycanada.com [216.95.203.30])
	by hub.freebsd.org (Postfix) with ESMTP
	id 41AD937B405; Tue, 26 Jun 2001 14:06:37 -0700 (PDT)
	(envelope-from mike@transient.lotterycanada.com)
Received: (from mike@localhost)
	by transient.lotterycanada.com (8.11.3/8.11.2) id f5QKvV995250;
	Tue, 26 Jun 2001 16:57:31 -0400 (EDT)
	(envelope-from mike)
Message-Id: <200106262057.f5QKvV995250@transient.lotterycanada.com>
Date: Tue, 26 Jun 2001 16:57:31 -0400 (EDT)
From: Mike Barcroft <mike@q9media.com>
Reply-To: Mike Barcroft <mike@q9media.com>
To: FreeBSD-gnats-submit@freebsd.org
Cc: phk@freebsd.org, joe@freebsd.org
Subject: [PATCH] whois(1) - Recursive IP Searches
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         28426
>Category:       bin
>Synopsis:       [PATCH] whois(1) - Recursive IP Searches
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mike
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Tue Jun 26 14:10:00 PDT 2001
>Closed-Date:    Thu Aug 2 07:40:55 PDT 2001
>Last-Modified:  Thu Aug 02 07:41:20 PDT 2001
>Originator:     Mike Barcroft
>Release:        FreeBSD 5.0-CURRENT i386
>Organization:
Q9 Media
>Environment:

$FreeBSD: src/usr.bin/whois/whois.1,v 1.18 2001/05/28 21:37:29 phk Exp $
$FreeBSD: src/usr.bin/whois/whois.c,v 1.19 2001/06/22 01:52:37 des Exp $

>Description:

o Implement recursive IP Address searches based on the results of
  a query to ARIN.  This allows a user to type 'whois 210.139.255.223'
  and get the expected results.
  [Requested by joe and phk]
o Update documentation to reflect this.
o Clean up some grammar nearby.

This was sent to -hackers.  There were no objections related
to this patch.

>How-To-Repeat:

	Apply patch below.

>Fix:

Index: whois/whois.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/whois/whois.1,v
retrieving revision 1.18
diff -u -r1.18 whois.1
--- whois/whois.1	2001/05/28 21:37:29	1.18
+++ whois/whois.1	2001/06/22 06:32:02
@@ -80,7 +80,7 @@
 .Pp
 By default
 .Nm
-construct the name of a whois server to use from the top-level domain
+constructs the name of a whois server to use from the top-level domain
 .Pq Tn TLD
 of the supplied (single) argument, and appending
 .Qq Li .whois-servers.net .
@@ -91,12 +91,20 @@
 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 query also, provided that the
+.Fl Q
+option isn't specified.
 .Pp
-If no required
-.Pa whois-servers.net
-subdomain found, fallback to
-.Pa whois.crsnic.net
-provided.
+If the query isn't a domain or IP address,
+.Nm
+will fallback to
+.Pa whois.crsnic.net .
 .It Fl i
 Use the Network Solutions Registry for Internet Numbers
 .Pq Pa whois.networksolutions.com
Index: whois/whois.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/whois/whois.c,v
retrieving revision 1.19
diff -u -r1.19 whois.c
--- whois/whois.c	2001/06/22 01:52:37	1.19
+++ whois/whois.c	2001/06/22 06:32:03
@@ -77,6 +77,8 @@
 #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 @@
 	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 @@
 		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()");
+				}
 			}
 		}
 
>Release-Note:
>Audit-Trail:

From: Peter Pentchev <roam@orbitel.bg>
To: Mike Barcroft <mike@q9media.com>
Cc: FreeBSD-gnats-submit@freebsd.org, phk@freebsd.org,
	joe@freebsd.org
Subject: Re: bin/28426: [PATCH] whois(1) - Recursive IP Searches
Date: Wed, 27 Jun 2001 12:41:46 +0300

 On Tue, Jun 26, 2001 at 04:57:31PM -0400, Mike Barcroft wrote:
 > 
 > >Number:         28426
 > >Category:       bin
 > >Synopsis:       [PATCH] whois(1) - Recursive IP Searches
 > >Originator:     Mike Barcroft
 
 Just a couple of minor comments :)
 
 > +If a query to
 > +.Tn ARIN
 > +references
 > +.Tn APNIC
 > +or
 > +.Tn RIPE ,
 > +that server will be query also, provided that the
 
 ITYM "queried".
 
 > +.Fl Q
 > +option isn't specified.
 
 Ruslan says 'is not' should be spelled out in full :)
 
 >  .Pp
 > -If no required
 > -.Pa whois-servers.net
 > -subdomain found, fallback to
 > -.Pa whois.crsnic.net
 > -provided.
 > +If the query isn't a domain or IP address,
 
 Same, 'is not'.
 
 Other than that, looks good.
 
 G'luck,
 Peter
 
 -- 
 If you think this sentence is confusing, then change one pig.

From: Mike Barcroft <mike@q9media.com>
To: freebsd-gnats-submit@FreeBSD.org
Cc: Peter Pentchev <roam@orbitel.bg>, phk@FreeBSD.org,
	joe@FreeBSD.org
Subject: Re: bin/28426: [PATCH] whois(1) - Recursive IP Searches
Date: Wed, 27 Jun 2001 10:59:58 -0400 (EDT)

 At the end of this e-mail is an updated patch based on Peter's comments.
 
 
 Best regards,
 Mike Barcroft
 
 -----------------------------------------------------------------------
 
 whois.20010627.patch
 
 o Implement recursive IP Address searches based on the results of
   a query to ARIN.  This allows a user to type 'whois 210.139.255.223'
   and get the expected results.
   [Requested by joe and phk]
 o Update documentation to reflect this.
 o Clean up some grammar nearby.
 
 
 Index: whois/whois.1
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/whois/whois.1,v
 retrieving revision 1.18
 diff -u -r1.18 whois.1
 --- whois/whois.1	2001/05/28 21:37:29	1.18
 +++ whois/whois.1	2001/06/27 14:36:50
 @@ -80,7 +80,7 @@
  .Pp
  By default
  .Nm
 -construct the name of a whois server to use from the top-level domain
 +constructs the name of a whois server to use from the top-level domain
  .Pq Tn TLD
  of the supplied (single) argument, and appending
  .Qq Li .whois-servers.net .
 @@ -91,12 +91,20 @@
  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
 -subdomain found, fallback to
 -.Pa whois.crsnic.net
 -provided.
 +If the query is not a domain or IP address,
 +.Nm
 +will fallback to
 +.Pa whois.crsnic.net .
  .It Fl i
  Use the Network Solutions Registry for Internet Numbers
  .Pq Pa whois.networksolutions.com
 Index: whois/whois.c
 ===================================================================
 RCS file: /home/ncvs/src/usr.bin/whois/whois.c,v
 retrieving revision 1.19
 diff -u -r1.19 whois.c
 --- whois/whois.c	2001/06/22 01:52:37	1.19
 +++ whois/whois.c	2001/06/27 14:36:51
 @@ -77,6 +77,8 @@
  #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 @@
  	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 @@
  		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()");
 +				}
  			}
  		}
  
State-Changed-From-To: open->analyzed 
State-Changed-By: dd 
State-Changed-When: Wed Jun 27 16:09:01 PDT 2001 
State-Changed-Why:  
Committed, thanks! 


Responsible-Changed-From-To: freebsd-bugs->dd 
Responsible-Changed-By: dd 
Responsible-Changed-When: Wed Jun 27 16:09:01 PDT 2001 
Responsible-Changed-Why:  
My MFC reminder. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28426 
Responsible-Changed-From-To: dd->mike 
Responsible-Changed-By: dd 
Responsible-Changed-When: Wed Jul 18 23:01:28 PDT 2001 
Responsible-Changed-Why:  
Your PR. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28426 
State-Changed-From-To: analyzed->closed 
State-Changed-By: mike 
State-Changed-When: Thu Aug 2 07:40:55 PDT 2001 
State-Changed-Why:  

Committed to -CURRENT and -STABLE. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28426 
>Unformatted:
