From wcampbel@botbay.net  Sat Jul  7 10:20:29 2001
Return-Path: <wcampbel@botbay.net>
Received: from botbay.net (botbay.net [151.197.159.116])
	by hub.freebsd.org (Postfix) with ESMTP id CF4E337B401
	for <FreeBSD-gnats-submit@freebsd.org>; Sat,  7 Jul 2001 10:20:28 -0700 (PDT)
	(envelope-from wcampbel@botbay.net)
Received: (from wcampbel@localhost)
	by botbay.net (8.11.3/8.11.3) id f67HKSW47305;
	Sat, 7 Jul 2001 13:20:28 -0400 (EDT)
	(envelope-from wcampbel)
Message-Id: <200107071720.f67HKSW47305@botbay.net>
Date: Sat, 7 Jul 2001 13:20:28 -0400 (EDT)
From: Walter Campbell <wcampbel@botbay.net>
Reply-To: wcampbel@botbay.net
To: FreeBSD-gnats-submit@freebsd.org
Cc:
Subject: [PATCH] whois: AUNIC fix, Add an option to connect to a specific port
X-Send-Pr-Version: 3.113
X-GNATS-Notify:

>Number:         28790
>Category:       bin
>Synopsis:       [PATCH] whois: AUNIC fix, Add an option to connect to a specific port
>Confidential:   no
>Severity:       non-critical
>Priority:       low
>Responsible:    mike
>State:          closed
>Quarter:        
>Keywords:       
>Date-Required:  
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 07 10:30:01 PDT 2001
>Closed-Date:    Sat Oct 20 20:21:09 PDT 2001
>Last-Modified:  Sat Oct 20 20:22:58 PDT 2001
>Originator:     Walter Campbell
>Release:        FreeBSD 4.3-STABLE i386
>Organization:
BotBay.net
>Environment:
System: FreeBSD botbay.net 4.3-STABLE FreeBSD 4.3-STABLE #1: Tue May 1 08:58:41 EDT 2001 root@botbay.net:/usr/obj/usr/src/sys/KABEL i386


	
>Description:
	The base whois client does not include the option to connect to a
	specific port on a whois server, which makes it difficult to provide
	abuse reports for certain large ISP's that run their own rwhois
	servers.  This patch adds -P to specify a port to connect to.

	The base whois client also only contains an option to connect to the
	APNIC whois database, which used to server Australia.  Now, AUNIC
	runs their own, so a small addition for -u was added for them.

	This pr takes the place of misc/26521.
	
>How-To-Repeat:
	
>Fix:


diff -u whois.dist/whois.1 whois/whois.1
--- whois.dist/whois.1	Sat Jul  7 12:31:15 2001
+++ whois/whois.1	Sat Jul  7 12:25:30 2001
@@ -40,8 +40,9 @@
 .Nd Internet domain name and network number directory service
 .Sh SYNOPSIS
 .Nm
-.Op Fl adgimpQrR6
+.Op Fl adgimpQrRu6
 .Op Fl h Ar host
+.Op Fl P Ar port
 .Ar name ...
 .Sh DESCRIPTION
 .Nm Whois
@@ -114,11 +115,13 @@
 database.
 It contains route policy specifications for a large
 number of operators' networks.
+.It Fl P Ar port
+Specify a port to query.  The default is 43
 .It Fl p
 Use the Asia/Pacific Network Information Center
 .Pq Tn APNIC
-database.  It contains network numbers used in East Asia, Australia,
-New Zealand, and the Pacific islands.
+database.  It contains network numbers used in East Asia, New Zealand,
+and the Pacific islands.
 .It Fl Q
 Do a quick lookup.  This means that
 .Nm
@@ -136,6 +139,10 @@
 database.  It contains network numbers and domain contact information
 for subdomains of
 .Tn \&.RU .
+.It Fl u
+Use the Australia Network Information Center
+.Pq Tn AUNIC
+database.  It contains network numbers used in Australia
 .It Fl 6
 Use the IPv6 Resource Center
 .Pq Tn 6bone
diff -u whois.dist/whois.c whois/whois.c
--- whois.dist/whois.c	Sat Jul  7 12:31:15 2001
+++ whois/whois.c	Sat Jul  7 12:18:41 2001
@@ -56,12 +56,14 @@
 #include <string.h>
 #include <sysexits.h>
 #include <unistd.h>
+#include <ctype.h>
 
 #define	NICHOST		"whois.crsnic.net"
 #define	INICHOST	"whois.networksolutions.com"
 #define	DNICHOST	"whois.nic.mil"
 #define	GNICHOST	"whois.nic.gov"
 #define	ANICHOST	"whois.arin.net"
+#define	AUNICHOST	"whois.aunic.net"
 #define	RNICHOST	"whois.ripe.net"
 #define	PNICHOST	"whois.apnic.net"
 #define	RUNICHOST	"whois.ripn.net"
@@ -75,7 +77,7 @@
 #define WHOIS_QUICK		0x04
 
 static void usage __P((void));
-static void whois __P((char *, struct addrinfo *, int));
+static void whois __P((char *, struct addrinfo *, char *, int));
 
 int
 main(argc, argv)
@@ -84,9 +86,11 @@
 {
 	int ch, i, j, error;
 	int use_qnichost, flags;
+	char *port;
 	char *host;
 	char *qnichost;
 	struct addrinfo hints, *res;
+	struct servent *se;
 
 #ifdef	SOCKS
 	SOCKSinit(argv[0]);
@@ -96,7 +100,8 @@
 	qnichost = NULL;
 	flags = 0;
 	use_qnichost = 0;
-	while ((ch = getopt(argc, argv, "adgh:impQrR6")) != -1) {
+	port = NULL;
+	while ((ch = getopt(argc, argv, "adgh:impP:QrRu6")) != -1) {
 		switch((char)ch) {
 		case 'a':
 			host = ANICHOST;
@@ -116,6 +121,9 @@
 		case 'm':
 			host = MNICHOST;
 			break;
+		case 'P':
+			port = optarg;
+			break;
 		case 'p':
 			host = PNICHOST;
 			break;
@@ -128,6 +136,9 @@
 		case 'R':
 			host = RUNICHOST;
 			break;
+		case 'u':
+			host = AUNICHOST;
+			break;
 		case '6':
 			host = SNICHOST;
 			break;
@@ -154,6 +165,18 @@
 			flags |= WHOIS_INIC_FALLBACK | WHOIS_RECURSE;
 		}
 	}
+	if (port != NULL) {
+		for (i = 0; i < strlen(port); i++) {
+			if (!isdigit(port[i])) {
+				port = NULL;
+				(void)setservent(0);
+				se = getservbyname("whois", "tcp");
+				(void)fprintf(stderr,
+					"Invalid port, defaulting\n");
+				break;
+			}
+		}
+	}
 	while (argc--) {
 		if (use_qnichost) {
 			if (qnichost) {
@@ -178,7 +201,11 @@
 				hints.ai_flags = 0;
 				hints.ai_family = AF_UNSPEC;
 				hints.ai_socktype = SOCK_STREAM;
-				error = getaddrinfo(qnichost, "whois",
+				if (port)
+					error = getaddrinfo(qnichost, port,
+						&hints, &res);
+				else
+					error = getaddrinfo(qnichost, "whois",
 						&hints, &res);
 				if (error != 0)
 					errx(EX_NOHOST, "%s: %s", qnichost,
@@ -190,22 +217,27 @@
 			hints.ai_flags = 0;
 			hints.ai_family = AF_UNSPEC;
 			hints.ai_socktype = SOCK_STREAM;
-			error = getaddrinfo(host, "whois", &hints, &res);
+			if (port)
+				error = getaddrinfo(host, port, &hints, &res);
+			else
+				error = getaddrinfo(host, "whois", &hints,
+					&res);
 			if (error != 0)
 				errx(EX_NOHOST, "%s: %s", host,
 					gai_strerror(error));
 		}
 
-		whois(*argv++, res, flags);
+		whois(*argv++, res, port, flags);
 		freeaddrinfo(res);
 	}
 	exit(0);
 }
 
 static void
-whois(name, res, flags)
+whois(name, res, port, flags)
 	char *name;
 	struct addrinfo *res;
+	char *port;
 	int flags;
 {
 	FILE *sfi, *sfo;
@@ -275,7 +307,10 @@
 		hints.ai_flags = 0;
 		hints.ai_family = AF_UNSPEC;
 		hints.ai_socktype = SOCK_STREAM;
-		error = getaddrinfo(nhost, "whois", &hints, &res2);
+		if (port)
+			error = getaddrinfo(nhost, port, &hints, &res2);
+		else
+			error = getaddrinfo(nhost, "whois", &hints, &res2);
 		if (error != 0) {
 			warnx("%s: %s", nhost, gai_strerror(error));
 			return;
@@ -283,7 +318,7 @@
 		if (!nomatch) {
 			free(nhost);
 		}
-		whois(name, res2, 0);
+		whois(name, res2, port, 0);
 		freeaddrinfo(res2);
 	}
 }
@@ -292,6 +327,6 @@
 usage()
 {
 	(void)fprintf(stderr,
-	    "usage: whois [-adgimpQrR6] [-h hostname] name ...\n");
+	    "usage: whois [-adgimpQrRu6] [-h hostname] [-P port] name ...\n");
 	exit(EX_USAGE);
 }
>Release-Note:
>Audit-Trail:
Responsible-Changed-From-To: freebsd-bugs->mike 
Responsible-Changed-By: mike 
Responsible-Changed-When: Tue Jul 17 08:09:11 PDT 2001 
Responsible-Changed-Why:  
I'm going to be working on some whois(1) changes, 
so I'll take a look at this one. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28790 
State-Changed-From-To: open->analyzed 
State-Changed-By: mike 
State-Changed-When: Mon Sep 3 11:10:39 PDT 2001 
State-Changed-Why:  

Two new options have been added to whois(1) in -CURRENT.  The first 
option -p, allows one to query a whois server on a specific port.  The 
second option -c, allows one to query a whois server based on a 
country code (for example: whois -c au query). 

The first one will not be MFC'd, but instead will be available in 
5.0-RELEASE because we don't change around options in established 
branches.  The second will be MFC'd after 4.4-RELEASE. 

http://www.FreeBSD.org/cgi/query-pr.cgi?pr=28790 
State-Changed-From-To: analyzed->closed 
State-Changed-By: mike 
State-Changed-When: Sat Oct 20 20:21:09 PDT 2001 
State-Changed-Why:  

The -c option has been MFC'd. 

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