aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPhilippe Charnier <charnier@FreeBSD.org>1997-08-29 11:56:51 +0000
committerPhilippe Charnier <charnier@FreeBSD.org>1997-08-29 11:56:51 +0000
commit7008c93ddfa79f36a8538999de532f15d803d8f9 (patch)
tree995aed1cb69c338a7e069afac52d0ec3488db895
parent3eff8361b9f9e2ce7cdd58f63a418ed9cb9142ce (diff)
downloadsrc-7008c93ddfa79f36a8538999de532f15d803d8f9.tar.gz
src-7008c93ddfa79f36a8538999de532f15d803d8f9.zip
Use err(3). Cosmetic in usage(). Delay the compute of defaultdomain (from
OpenBSD). Obtained from: OpenBSD.
Notes
Notes: svn path=/head/; revision=28895
-rw-r--r--usr.bin/ypwhich/ypwhich.c62
1 files changed, 28 insertions, 34 deletions
diff --git a/usr.bin/ypwhich/ypwhich.c b/usr.bin/ypwhich/ypwhich.c
index 401cfadbe81e..e56462775be5 100644
--- a/usr.bin/ypwhich/ypwhich.c
+++ b/usr.bin/ypwhich/ypwhich.c
@@ -27,16 +27,21 @@
* SUCH DAMAGE.
*/
-#ifndef LINT
-static char rcsid[] = "ypwhich.c,v 1.2 1993/05/16 02:49:10 deraadt Exp";
-#endif
+#ifndef lint
+static const char rcsid[] =
+ "$Id$";
+#endif /* not lint */
#include <sys/param.h>
#include <sys/types.h>
#include <sys/socket.h>
-#include <stdio.h>
#include <ctype.h>
+#include <err.h>
#include <netdb.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
#include <rpc/rpc.h>
#include <rpc/xdr.h>
#include <rpcsvc/yp.h>
@@ -65,11 +70,12 @@ struct ypalias {
{ "ethers", "ethers.byname" },
};
+static void
usage()
{
- fprintf(stderr, "Usage:\n");
- fprintf(stderr, "\typwhich [-d domain] [[-t] -m [mname] | host]\n");
- fprintf(stderr, "\typwhich -x\n");
+ fprintf(stderr, "%s\n%s\n",
+ "usage: ypwhich [-d domain] [[-t] -m [mname] | host]",
+ " ypwhich -x");
exit(ERR_USAGE);
}
@@ -77,13 +83,13 @@ usage()
/*
* Like yp_bind except can query a specific host
*/
+int
bind_host(dom, sin)
char *dom;
struct sockaddr_in *sin;
{
struct hostent *hent = NULL;
struct ypbind_resp ypbr;
- struct dom_binding *ysd;
struct timeval tv;
CLIENT *client;
int sock, r;
@@ -94,8 +100,7 @@ struct sockaddr_in *sin;
tv.tv_usec = 0;
client = clntudp_create(sin, YPBINDPROG, YPBINDVERS, tv, &sock);
if(client==NULL) {
- fprintf(stderr, "can't clntudp_create: %s\n",
- yperr_string(YPERR_YPBIND));
+ warnx("can't clntudp_create: %s", yperr_string(YPERR_YPBIND));
return YPERR_YPBIND;
}
@@ -104,13 +109,12 @@ struct sockaddr_in *sin;
r = clnt_call(client, YPBINDPROC_DOMAIN,
xdr_domainname, &dom, xdr_ypbind_resp, &ypbr, tv);
if( r != RPC_SUCCESS) {
- fprintf(stderr, "can't clnt_call: %s\n",
- yperr_string(YPERR_YPBIND));
+ warnx("can't clnt_call: %s", yperr_string(YPERR_YPBIND));
clnt_destroy(client);
return YPERR_YPBIND;
} else {
if (ypbr.ypbind_status != YPBIND_SUCC_VAL) {
- fprintf(stderr, "can't yp_bind: Reason: %s\n",
+ warnx("can't yp_bind: reason: %s",
ypbinderr_string(ypbr.ypbind_resp_u.ypbind_error));
clnt_destroy(client);
return r;
@@ -132,18 +136,13 @@ int
main(argc, argv)
char **argv;
{
- char *domainname, *master, *map;
+ char *domainname = NULL, *master, *map = NULL;
struct ypmaplist *ypml, *y;
- extern char *optarg;
- extern int optind;
struct hostent *hent;
struct sockaddr_in sin;
int notrans, mode, getmap;
int c, r, i;
- yp_get_default_domain(&domainname);
-
- map = NULL;
getmap = notrans = mode = 0;
while( (c=getopt(argc, argv, "xd:mt")) != -1)
switch(c) {
@@ -166,6 +165,9 @@ char **argv;
usage();
}
+ if(!domainname)
+ yp_get_default_domain(&domainname);
+
if(mode==0) {
switch(argc-optind) {
case 0:
@@ -181,11 +183,8 @@ char **argv;
sin.sin_family = AF_INET;
if( (sin.sin_addr.s_addr=inet_addr(argv[optind]))==-1) {
hent = gethostbyname(argv[optind]);
- if(!hent) {
- fprintf(stderr, "ypwhich: host %s unknown\n",
- argv[optind]);
- exit(ERR_NOSUCHHOST);
- }
+ if(!hent)
+ errx(ERR_NOSUCHHOST, "host %s unknown", argv[optind]);
bcopy((char *)hent->h_addr_list[0],
(char *)&sin.sin_addr, sizeof sin.sin_addr);
}
@@ -213,12 +212,10 @@ char **argv;
free(master);
break;
case YPERR_YPBIND:
- fprintf(stderr, "ypwhich: not running ypbind\n");
- exit(ERR_NOYPBIND);
+ errx(ERR_NOYPBIND, "not running ypbind");
default:
- fprintf(stderr, "Can't find master for map %s. Reason: %s\n",
+ errx(ERR_NOMASTER, "can't find master for map %s. reason: %s",
map, yperr_string(r));
- exit(ERR_NOMASTER);
}
exit(0);
}
@@ -236,8 +233,7 @@ char **argv;
free(master);
break;
default:
- fprintf(stderr,
- "YP: can't find the master of %s: Reason: %s\n",
+ warnx("can't find the master of %s: reason: %s",
ypml->map, yperr_string(r));
break;
}
@@ -246,12 +242,10 @@ char **argv;
}
break;
case YPERR_YPBIND:
- fprintf(stderr, "ypwhich: not running ypbind\n");
- exit(ERR_NOYPBIND);
+ errx(ERR_NOYPBIND, "not running ypbind");
default:
- fprintf(stderr, "Can't get map list for domain %s. Reason: %s\n",
+ errx(ERR_NOMASTER, "can't get map list for domain %s. reason: %s",
domainname, yperr_string(r));
- exit(ERR_NOMASTER);
}
exit(0);
}