summaryrefslogtreecommitdiffstats
path: root/usr.bin/ypwhich
diff options
context:
space:
mode:
authorcharnier <charnier@FreeBSD.org>1997-08-29 11:56:51 +0000
committercharnier <charnier@FreeBSD.org>1997-08-29 11:56:51 +0000
commitd40272764911557633a2410d8c3265efdfe7955a (patch)
treef7be2020f699606d966da09de030b48bddfb0594 /usr.bin/ypwhich
parente94e60b6cd96fdcc544276ff5a193ae0d49dca3b (diff)
downloadFreeBSD-src-d40272764911557633a2410d8c3265efdfe7955a.zip
FreeBSD-src-d40272764911557633a2410d8c3265efdfe7955a.tar.gz
Use err(3). Cosmetic in usage(). Delay the compute of defaultdomain (from
OpenBSD). Obtained from: OpenBSD.
Diffstat (limited to 'usr.bin/ypwhich')
-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 401cfad..e564627 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);
}
OpenPOWER on IntegriCloud