Make it more convenient to query NICs other than InterNIC. Explain in the

man page what each database contains.
This commit is contained in:
Garrett Wollman 1998-02-19 19:07:50 +00:00
parent f5c7505126
commit a00fe97d5a
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=33626
2 changed files with 81 additions and 34 deletions

View file

@ -29,28 +29,54 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)whois.1 8.1 (Berkeley) 6/6/93
.\" From: @(#)whois.1 8.1 (Berkeley) 6/6/93
.\" $Id$
.\"
.Dd June 6, 1993
.Dd February 19, 1998
.Dt WHOIS 1
.Os BSD 4.3
.Sh NAME
.Nm whois
.Nd Internet user name directory service
.Nd Internet domain name and network number directory service
.Sh SYNOPSIS
.Nm whois
.Op Fl h Ar hostname
.Op Fl adpr
.Op Fl h Ar host
.Ar name ...
.Sh DESCRIPTION
.Nm Whois
looks up records in the Network Information Center
.Pq Tn NIC
database.
looks up records in the databases maintained by several
Network Information Centers
.Pq Tn NICs .
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl h
Use the specified host instead of the default NIC (whois.internic.net).
.It Fl a
Use the American Registry for Internet Numbers
.Pq Tn ARIN
database. It contains network numbers used in those parts of the world
covered neither by
.Tn APNIC nor by
.Tn RIPE .
.It Fl d
Use the (US Military) Defense Data Network
.Pq Tn DDN
database. It contains points of contact for subdomains of
.Tn \&.MIL .
.It Fl h Ar host
Use the specified host instead of the default NIC
(whois.internic.net).
Either a host name or an IP address may be specified.
.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 r
Use the R\(aaeseaux IP Europ\(aaeens
.Pq Tn RIPE
database. It contains network numbers and domain contact information
for Europe.
.El
.Pp
The operands specified to

View file

@ -42,7 +42,7 @@ static const char copyright[] =
static char sccsid[] = "@(#)whois.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
"$Id: whois.c,v 1.4 1997/08/26 11:16:08 charnier Exp $";
#endif /* not lint */
#include <sys/types.h>
@ -52,9 +52,15 @@ static const char rcsid[] =
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <sysexits.h>
#include <unistd.h>
#define NICHOST "whois.internic.net"
#define NICHOST "whois.internic.net"
#define DNICHOST "nic.ddn.mil"
#define ANICHOST "whois.arin.net"
#define RNICHOST "whois.ripe.net"
#define PNICHOST "whois.apnic.net"
#define WHOIS_PORT 43
static void usage __P((void));
@ -76,11 +82,23 @@ main(argc, argv)
#endif
host = NICHOST;
while ((ch = getopt(argc, argv, "h:")) != -1)
while ((ch = getopt(argc, argv, "adh:pr")) != -1)
switch((char)ch) {
case 'a':
host = ANICHOST;
break;
case 'd':
host = DNICHOST;
break;
case 'h':
host = optarg;
break;
case 'p':
host = PNICHOST;
break;
case 'r':
host = RNICHOST;
break;
case '?':
default:
usage();
@ -91,32 +109,35 @@ main(argc, argv)
if (!argc)
usage();
hp = gethostbyname(host);
if (hp == NULL) {
(void)fprintf(stderr, "whois: %s: ", host);
herror((char *)NULL);
exit(1);
}
host = hp->h_name;
s = socket(hp->h_addrtype, SOCK_STREAM, 0);
s = socket(PF_INET, SOCK_STREAM, 0);
if (s < 0)
err(1, "socket");
bzero((caddr_t)&sin, sizeof (sin));
sin.sin_family = hp->h_addrtype;
bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
err(EX_OSERR, "socket");
memset(&sin, 0, sizeof sin);
sin.sin_len = sizeof sin;
sin.sin_family = AF_INET;
if (inet_aton(host, &sin.sin_addr) == 0) {
hp = gethostbyname2(host, AF_INET);
if (hp == NULL)
errx(EX_NOHOST, "%s: %s", host, hstrerror(h_errno));
host = hp->h_name;
sin.sin_addr = *(struct in_addr *)hp->h_addr_list[0];
}
sp = getservbyname("whois", "tcp");
if (sp == NULL)
errx(1, "whois/tcp: unknown service");
sin.sin_port = sp->s_port;
sin.sin_port = htons(WHOIS_PORT);
else
sin.sin_port = sp->s_port;
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0)
err(1, "connect");
err(EX_OSERR, "connect");
sfi = fdopen(s, "r");
sfo = fdopen(s, "w");
if (sfi == NULL || sfo == NULL) {
warn("fdopen");
(void)close(s);
exit(1);
}
if (sfi == NULL || sfo == NULL)
err(EX_OSERR, "fdopen");
while (argc-- > 1)
(void)fprintf(sfo, "%s ", *argv++);
(void)fprintf(sfo, "%s\r\n", *argv);
@ -129,6 +150,6 @@ main(argc, argv)
static void
usage()
{
(void)fprintf(stderr, "usage: whois [-h hostname] name ...\n");
exit(1);
(void)fprintf(stderr, "usage: whois [-adpr] [-h hostname] name ...\n");
exit(EX_USAGE);
}