Skip site navigation (1)Skip section navigation (2)
Date:      Sat, 7 Jul 2001 13:20:28 -0400 (EDT)
From:      Walter Campbell <wcampbel@botbay.net>
To:        FreeBSD-gnats-submit@freebsd.org
Subject:   bin/28790: [PATCH] whois: AUNIC fix, Add an option to connect to a specific port
Message-ID:  <200107071720.f67HKSW47305@botbay.net>

next in thread | raw e-mail | index | archive | help

>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:    freebsd-bugs
>State:          open
>Quarter:        
>Keywords:       
>Date-Required:
>Class:          change-request
>Submitter-Id:   current-users
>Arrival-Date:   Sat Jul 07 10:30:01 PDT 2001
>Closed-Date:
>Last-Modified:
>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:
>Unformatted:

To Unsubscribe: send mail to majordomo@FreeBSD.org
with "unsubscribe freebsd-bugs" in the body of the message




Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?200107071720.f67HKSW47305>