Skip site navigation (1)Skip section navigation (2)
Date:      Tue, 24 Jul 2001 23:41:11 -0400
From:      Mike Barcroft <mike@FreeBSD.org>
To:        audit@FreeBSD.org
Cc:        ache@FreeBSD.org, des@FreeBSD.org, phantom@FreeBSD.org, jabley@automagic.org
Subject:   whois(1) new features for review
Message-ID:  <20010724234111.A75705@coffee.q9media.com>

next in thread | raw e-mail | index | archive | help
I would appreciate reviews of the following changes I intend to make
to whois(1).  If there are no objection I'd like to commit this in two
days.  

Patch also available at:
http://people.FreeBSD.org/~mike/patches/whois.20010724.patch

Best regards,
Mike Barcroft
----------------------------------------------------------------------

whois.20010724.patch

o Move APNIC flag from -p to -A.  Since, -p is usually associated
  with specifying a port.
o Add the -p flag for specifying a port.  (PR: 28790)  This is
  useful for querying rwhois servers.  Example:
    whois -h rwhois.exodus.net -p 4321 216.136.180.0
o Add the -c flag which allows one to get the same whois server
  that would normally be determined if no arguments were specified.
  (Concept based on work by phantom, requested by ache)  Example:
    whois -c ru TCNET-MNT-RIPN
o Deprecate -R flag in favour of -c ru.

Index: whois/whois.1
===================================================================
RCS file: /home/ncvs/src/usr.bin/whois/whois.1,v
retrieving revision 1.20
diff -u -r1.20 whois.1
--- whois/whois.1	2001/06/27 23:08:57	1.20
+++ whois/whois.1	2001/07/25 02:48:25
@@ -40,8 +40,9 @@
 .Nd "Internet domain name and network number directory service"
 .Sh SYNOPSIS
 .Nm
-.Op Fl adgimpQrR6
-.Op Fl h Ar host
+.Op Fl aAdgimQr6
+.Op Fl c Ar country-code | Fl h Ar host
+.Op Fl p Ar port
 .Ar name ...
 .Sh DESCRIPTION
 .Nm
@@ -65,6 +66,17 @@
 .Pp
 .Dl "$ whois -a foo3-ARIN"
 .Pp
+.It Fl A
+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.
+.It Fl c Ar country-code
+This is the equivalent of using the
+.Fl h
+option with an argument of 
+.Qq Ar country-code Ns Li .whois-servers.net .
 .It Fl d
 Use the US Department of Defense
 database.
@@ -139,12 +151,12 @@
 database.
 It contains route policy specifications for a large
 number of operators' networks.
-.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.
+.It Fl p Ar port
+Connect to the whois server on
+.Ar port .
+If this option is not specified,
+.Nm
+defaults to port 43.
 .It Fl Q
 Do a quick lookup.
 This means that
@@ -159,13 +171,6 @@
 database.
 It contains network numbers and domain contact information
 for Europe.
-.It Fl R
-Use the Russia Network Information Center
-.Pq Tn RIPN
-database.
-It contains network numbers and domain contact information
-for subdomains of
-.Pa .RU .
 .It Fl 6
 Use the IPv6 Resource Center
 .Pq Tn 6bone
Index: whois/whois.c
===================================================================
RCS file: /home/ncvs/src/usr.bin/whois/whois.c,v
retrieving revision 1.23
diff -u -r1.23 whois.c
--- whois/whois.c	2001/07/22 18:23:24	1.23
+++ whois/whois.c	2001/07/25 02:48:25
@@ -66,11 +66,10 @@
 #define	ANICHOST	"whois.arin.net"
 #define	RNICHOST	"whois.ripe.net"
 #define	PNICHOST	"whois.apnic.net"
-#define	RUNICHOST	"whois.ripn.net"
 #define	MNICHOST	"whois.ra.net"
 #define	QNICHOST_TAIL	".whois-servers.net"
 #define	SNICHOST	"whois.6bone.net"
-#define	WHOIS_PORT	43
+#define	DEFAULT_PORT	"whois"
 #define	WHOIS_SERVER_ID	"Whois Server: "
 #define	NO_MATCH_ID	"No match for \""
 
@@ -79,6 +78,7 @@
 #define WHOIS_QUICK		0x04
 
 const char *ip_whois[] = { RNICHOST, PNICHOST, NULL };
+const char *port = DEFAULT_PORT;
 
 static char *choose_server(char *);
 static struct addrinfo *gethostinfo(char const *host, int exit_on_error);
@@ -90,7 +90,7 @@
 main(int argc, char *argv[])
 {
 	struct addrinfo *res;
-	const char *host;
+	const char *country, *host;
 	char *qnichost;
 	int ch, flags, use_qnichost;
 
@@ -98,15 +98,19 @@
 	SOCKSinit(argv[0]);
 #endif
 
-	host = NULL;
-	qnichost = NULL;
-	flags = 0;
-	use_qnichost = 0;
-	while ((ch = getopt(argc, argv, "adgh:impQrR6")) != -1) {
+	country = host = qnichost = NULL;
+	flags = use_qnichost = 0;
+	while ((ch = getopt(argc, argv, "aAc:dgh:imp:QrR6")) != -1) {
 		switch (ch) {
 		case 'a':
 			host = ANICHOST;
 			break;
+		case 'A':
+			host = PNICHOST;
+			break;
+		case 'c':
+			country = optarg;
+			break; 
 		case 'd':
 			host = DNICHOST;
 			break;
@@ -123,7 +127,7 @@
 			host = MNICHOST;
 			break;
 		case 'p':
-			host = PNICHOST;
+			port = optarg;
 			break;
 		case 'Q':
 			flags |= WHOIS_QUICK;
@@ -132,7 +136,7 @@
 			host = RNICHOST;
 			break;
 		case 'R':
-			host = RUNICHOST;
+			errx(EX_USAGE, "deprecated: use -c ru");
 			break;
 		case '6':
 			host = SNICHOST;
@@ -146,23 +150,26 @@
 	argc -= optind;
 	argv += optind;
 
-	if (!argc)
+	if (!argc || (country != NULL && host != NULL))
 		usage();
 
 	/*
-	 * If no nic host is specified determine the top level domain from
-	 * the query.  If the TLD is a number, query ARIN.  Otherwise, use 
+	 * If no host or country is specified determine the top level domain
+	 * from the query.  If the TLD is a number, query ARIN.  Otherwise, use 
 	 * TLD.whois-server.net.  If the domain does not contain '.', fall
 	 * back to NICHOST.
 	 */
-	if (host == NULL) {
+	if (host == NULL && country == NULL) {
 		use_qnichost = 1;
 		host = NICHOST;
 		if (!(flags & WHOIS_QUICK))
 			flags |= WHOIS_INIC_FALLBACK | WHOIS_RECURSE;
 	}
 	while (argc--) {
-		if (use_qnichost)
+		if (country != NULL) {
+			s_asprintf(&qnichost, "%s%s", country, QNICHOST_TAIL);
+			res = gethostinfo(qnichost, 1);
+		} else if (use_qnichost) 
 			if ((qnichost = choose_server(*argv)) != NULL)
 				res = gethostinfo(qnichost, 1);
 		if (qnichost == NULL)
@@ -212,7 +219,7 @@
 	hints.ai_flags = 0;
 	hints.ai_family = AF_UNSPEC;
 	hints.ai_socktype = SOCK_STREAM;
-	error = getaddrinfo(host, "whois", &hints, &res);
+	error = getaddrinfo(host, port, &hints, &res);
 	if (error) {
 		warnx("%s: %s", host, gai_strerror(error));
 		if (exit_on_error)
@@ -319,6 +326,7 @@
 usage(void)
 {
 	fprintf(stderr,
-	    "usage: whois [-adgimpQrR6] [-h hostname] name ...\n");
+	    "usage: whois [-adgimpQrR6] [-c country-code | -h hostname] "
+	    "[-p port] name ...\n");
 	exit(EX_USAGE);
 }

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




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