summaryrefslogtreecommitdiffstats
path: root/usr.bin/whois
diff options
context:
space:
mode:
authormike <mike@FreeBSD.org>2001-08-05 19:37:12 +0000
committermike <mike@FreeBSD.org>2001-08-05 19:37:12 +0000
commitee03551b7f9b7d104121f415506228bc8530f28b (patch)
treee80a28f5420798dd0f38f3287c0824e12c49120e /usr.bin/whois
parent4c37b1678b0232380d535df485494283287f9552 (diff)
downloadFreeBSD-src-ee03551b7f9b7d104121f415506228bc8530f28b.zip
FreeBSD-src-ee03551b7f9b7d104121f415506228bc8530f28b.tar.gz
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 rwhois 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. PR: 28790 Reviewed by: -audit, ache, phantom
Diffstat (limited to 'usr.bin/whois')
-rw-r--r--usr.bin/whois/whois.133
-rw-r--r--usr.bin/whois/whois.c43
2 files changed, 51 insertions, 25 deletions
diff --git a/usr.bin/whois/whois.1 b/usr.bin/whois/whois.1
index 0c1023f..41b154a 100644
--- a/usr.bin/whois/whois.1
+++ b/usr.bin/whois/whois.1
@@ -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 aAdgimQrR6
+.Op Fl c Ar country-code | Fl h Ar host
+.Op Fl p Ar port
.Ar name ...
.Sh DESCRIPTION
.Nm
@@ -65,6 +66,17 @@ to the NIC handle:
.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 @@ Use the Route Arbiter Database
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
@@ -166,6 +178,11 @@ database.
It contains network numbers and domain contact information
for subdomains of
.Pa .RU .
+This option is deprecated; use the
+.Fl c
+option with an argument of
+.Qq ru
+instead.
.It Fl 6
Use the IPv6 Resource Center
.Pq Tn 6bone
diff --git a/usr.bin/whois/whois.c b/usr.bin/whois/whois.c
index 4115f44..9cae44a 100644
--- a/usr.bin/whois/whois.c
+++ b/usr.bin/whois/whois.c
@@ -66,11 +66,10 @@ static const char rcsid[] =
#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 @@ static const char rcsid[] =
#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 @@ int
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 @@ main(int argc, char *argv[])
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 @@ main(int argc, char *argv[])
host = MNICHOST;
break;
case 'p':
- host = PNICHOST;
+ port = optarg;
break;
case 'Q':
flags |= WHOIS_QUICK;
@@ -132,7 +136,8 @@ main(int argc, char *argv[])
host = RNICHOST;
break;
case 'R':
- host = RUNICHOST;
+ warnx("-R is deprecated; use '-c ru' instead");
+ country = "ru";
break;
case '6':
host = SNICHOST;
@@ -146,23 +151,26 @@ main(int argc, char *argv[])
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 +220,7 @@ gethostinfo(char const *host, int exit_on_error)
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 +327,7 @@ static void
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);
}
OpenPOWER on IntegriCloud