Initial commit of whois utility

This commit is contained in:
taubert 1998-01-24 08:25:03 +00:00
parent c7b1d54b03
commit 767546b525
5 changed files with 270 additions and 0 deletions

9
usr.bin/whois/Makefile Normal file
View File

@ -0,0 +1,9 @@
# @(#)Makefile 8.1 (Berkeley) 6/6/93
# $Id: Makefile,v 1.1 1998/01/24 08:24:58 taubert Exp $
PROG= whois
LDADD= -lnetdb
OPTIMIZE=79
DEBUG= 25
.INCLUDE: /src/gno/prog.mk

80
usr.bin/whois/whois.1 Normal file
View File

@ -0,0 +1,80 @@
.\" Copyright (c) 1985, 1990, 1993
.\" The Regents of the University of California. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
.\" 2. Redistributions in binary form must reproduce the above copyright
.\" notice, this list of conditions and the following disclaimer in the
.\" documentation and/or other materials provided with the distribution.
.\" 3. All advertising materials mentioning features or use of this software
.\" must display the following acknowledgement:
.\" This product includes software developed by the University of
.\" California, Berkeley and its contributors.
.\" 4. Neither the name of the University nor the names of its contributors
.\" may be used to endorse or promote products derived from this software
.\" without specific prior written permission.
.\"
.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
.\" @(#)whois.1 8.1 (Berkeley) 6/6/93
.\"
.Dd June 6, 1993
.Dt WHOIS 1
.Os BSD 4.3
.Sh NAME
.Nm whois
.Nd Internet user name directory service
.Sh SYNOPSIS
.Nm whois
.Op Fl h Ar hostname
.Ar name ...
.Sh DESCRIPTION
.Nm Whois
looks up records in the Network Information Center
.Pq Tn NIC
database.
.Pp
The options are as follows:
.Bl -tag -width Ds
.It Fl h
Use the specified host instead of the default NIC (nic.ddn.mil).
.El
.Pp
The operands specified to
.Nm whois
are concatenated together (separated by white-space) and presented to
the
.Nm whois
server.
.Pp
The default action, unless directed otherwise with a special
.Ar name ,
is to do a very broad search, looking for matches to
.Ar name
in all types of records and most fields (name, nicknames, hostname, net
address, etc.) in the database.
For more information as to what
.Ar name
operands have special meaning, and how to guide the search, use
the special name
.Dq Ar help .
.Sh SEE ALSO
RFC 812: Nicname/Whois
.Sh HISTORY
The
.Nm whois
command appeared in
.Bx 4.3 .

141
usr.bin/whois/whois.c Normal file
View File

@ -0,0 +1,141 @@
/*
* Copyright (c) 1980, 1993
* The Regents of the University of California. All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met:
* 1. Redistributions of source code must retain the above copyright
* notice, this list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright
* notice, this list of conditions and the following disclaimer in the
* documentation and/or other materials provided with the distribution.
* 3. All advertising materials mentioning features or use of this software
* must display the following acknowledgement:
* This product includes software developed by the University of
* California, Berkeley and its contributors.
* 4. Neither the name of the University nor the names of its contributors
* may be used to endorse or promote products derived from this software
* without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
* ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE.
*/
#ifndef lint
static char copyright[] =
"@(#) Copyright (c) 1980, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
static char sccsid[] = "@(#)whois.c 8.1 (Berkeley) 6/6/93";
#endif /* not lint */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <netdb.h>
#include <stdio.h>
#ifdef __GNO__
#include <string.h>
#include <stdlib.h>
#include <unistd.h>
#endif
#define NICHOST "whois.internic.net"
void
usage(void)
{
(void)fprintf(stderr, "usage: whois [-h hostname] name ...\n");
exit(1);
}
int
main(int argc, char **argv)
{
extern char *optarg;
extern int optind;
register FILE *sfi, *sfo;
register int ch;
struct sockaddr_in sin;
struct hostent *hp;
struct servent *sp;
int s;
char *host;
host = NICHOST;
while ((ch = getopt(argc, argv, "h:")) != EOF)
switch((char)ch) {
case 'h':
host = optarg;
break;
case '?':
default:
usage();
}
argc -= optind;
argv += optind;
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);
if (s < 0) {
perror("whois: socket");
exit(1);
}
bzero((caddr_t)&sin, sizeof (sin));
sin.sin_family = hp->h_addrtype;
if (bind(s, (struct __SOCKADDR *)&sin, sizeof(sin)) < 0) {
perror("whois: bind");
exit(1);
}
bcopy(hp->h_addr, (char *)&sin.sin_addr, hp->h_length);
sp = getservbyname("whois", "tcp");
if (sp == NULL) {
(void)fprintf(stderr, "whois: whois/tcp: unknown service\n");
exit(1);
}
sin.sin_port = sp->s_port;
if (connect(s, (struct __SOCKADDR *)&sin, sizeof(sin)) < 0) {
perror("whois: connect");
exit(1);
}
sfi = fdopen(s, "r");
#ifdef __GNO__
sfo = fdopen(s, "wb");
#else
sfo = fdopen(s, "w");
#endif
if (sfi == NULL || sfo == NULL) {
perror("whois: fdopen");
(void)close(s);
exit(1);
}
while (argc-- > 1)
(void)fprintf(sfo, "%s ", *argv++);
(void)fprintf(sfo, "%s\r\n", *argv);
(void)fflush(sfo);
while ((ch = getc(sfi)) != EOF)
putchar(ch);
exit(0);
}

9
usr.bin/whois/whois.desc Normal file
View File

@ -0,0 +1,9 @@
Name: whois
Version: 1.0 (November 1997)
Shell: GNO & GS/TCP
Author: Derek Taubert (from FreeBSD 2.1.0 code)
Contact: taubert@geeks.org
Where: /usr/bin
FTP: ground.isca.uiowa.edu apple2.caltech.edu trenco.myrias.com
Internet user name directory service.

31
usr.bin/whois/whois.rez Normal file
View File

@ -0,0 +1,31 @@
/*
* Resources for whois version and comment
*
* $Id: whois.rez,v 1.1 1998/01/24 08:25:03 taubert Exp $
*/
#define PROG "whois"
#define DESC "Internet user name directory service."
#include "Types.rez"
/*
* Version
*/
resource rVersion (1, purgeable3) {
{ 1, 0, 0, /* Version 1.0.0 */
release, /* development|alpha|beta|final|release */
0 }, /* non-final release number */
verUS, /* Country */
PROG, /* Program name */
DESC " Released with GNO/ME and GS/TCP."
};
/*
* Comment
*/
resource rComment (1, purgeable3) {
PROG " v1.0 (November 1997)\n"
"GNO utility: " DESC "\n"
"Ported from FreeBSD 2.1.0 code by Derek Taubert."
};