Use err(3).

This commit is contained in:
Philippe Charnier 1997-08-26 11:16:08 +00:00
parent 0abcff762c
commit 741d304e2d
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=28792
2 changed files with 22 additions and 19 deletions

View file

@ -54,10 +54,10 @@ Use the specified host instead of the default NIC (whois.internic.net).
.El
.Pp
The operands specified to
.Nm whois
.Nm
are concatenated together (separated by white-space) and presented to
the
.Nm whois
.Nm
server.
.Pp
The default action, unless directed otherwise with a special
@ -75,6 +75,6 @@ the special name
RFC 812: Nicname/Whois
.Sh HISTORY
The
.Nm whois
.Nm
command appeared in
.Bx 4.3 .

View file

@ -32,29 +32,37 @@
*/
#ifndef lint
static char copyright[] =
static const char copyright[] =
"@(#) Copyright (c) 1980, 1993\n\
The Regents of the University of California. All rights reserved.\n";
#endif /* not lint */
#ifndef lint
#if 0
static char sccsid[] = "@(#)whois.c 8.1 (Berkeley) 6/6/93";
#endif
static const char rcsid[] =
"$Id$";
#endif /* not lint */
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <err.h>
#include <netdb.h>
#include <stdio.h>
#include <string.h>
#include <unistd.h>
#define NICHOST "whois.internic.net"
static void usage __P((void));
int
main(argc, argv)
int argc;
char **argv;
{
extern char *optarg;
extern int optind;
register FILE *sfi, *sfo;
register int ch;
struct sockaddr_in sin;
@ -91,27 +99,21 @@ main(argc, argv)
}
host = hp->h_name;
s = socket(hp->h_addrtype, SOCK_STREAM, 0);
if (s < 0) {
perror("whois: socket");
exit(1);
}
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);
sp = getservbyname("whois", "tcp");
if (sp == NULL) {
(void)fprintf(stderr, "whois: whois/tcp: unknown service\n");
exit(1);
}
if (sp == NULL)
errx(1, "whois/tcp: unknown service");
sin.sin_port = sp->s_port;
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0) {
perror("whois: connect");
exit(1);
}
if (connect(s, (struct sockaddr *)&sin, sizeof(sin)) < 0)
err(1, "connect");
sfi = fdopen(s, "r");
sfo = fdopen(s, "w");
if (sfi == NULL || sfo == NULL) {
perror("whois: fdopen");
warn("fdopen");
(void)close(s);
exit(1);
}
@ -124,6 +126,7 @@ main(argc, argv)
exit(0);
}
static void
usage()
{
(void)fprintf(stderr, "usage: whois [-h hostname] name ...\n");