From e2609ca89f4e9670db0f4d62006179563aff3984 Mon Sep 17 00:00:00 2001 From: gene Date: Tue, 22 Apr 1997 02:55:42 +0000 Subject: [PATCH] Do some beautification of this file (that theo didn't :P). Also, print a better error message when the host you're checking isn't ypbound. The previous error was cryptic and incomprehensible. --- usr.bin/ypwhich/ypwhich.c | 29 ++++++++++++++++------------- 1 file changed, 16 insertions(+), 13 deletions(-) diff --git a/usr.bin/ypwhich/ypwhich.c b/usr.bin/ypwhich/ypwhich.c index dd19a34ffe9..75effeae7ae 100644 --- a/usr.bin/ypwhich/ypwhich.c +++ b/usr.bin/ypwhich/ypwhich.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ypwhich.c,v 1.5 1997/04/22 01:49:16 deraadt Exp $ +/* $OpenBSD: ypwhich.c,v 1.6 1997/04/22 02:55:42 gene Exp $ /* $NetBSD: ypwhich.c,v 1.6 1996/05/13 02:43:48 thorpej Exp $ */ /* @@ -34,7 +34,7 @@ */ #ifndef LINT -static char rcsid[] = "$Id: ypwhich.c,v 1.5 1997/04/22 01:49:16 deraadt Exp $"; +static char rcsid[] = "$Id: ypwhich.c,v 1.6 1997/04/22 02:55:42 gene Exp $"; #endif #include @@ -90,14 +90,15 @@ struct sockaddr_in *sin; tv.tv_sec = 15; 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)); + + if (client == NULL) { + fprintf(stderr, "ypwhich: host is not bound to a ypmaster\n"); return YPERR_YPBIND; } tv.tv_sec = 5; tv.tv_usec = 0; + r = clnt_call(client, YPBINDPROC_DOMAIN, xdr_domainname, &dom, xdr_ypbind_resp, &ypbr, tv); if (r != RPC_SUCCESS) { @@ -117,12 +118,13 @@ struct sockaddr_in *sin; bcopy(&ypbr.ypbind_resp_u.ypbind_bindinfo.ypbind_binding_addr, &ss_addr, sizeof (ss_addr)); - /*printf("%08x\n", ss_addr);*/ + hent = gethostbyaddr((char *)&ss_addr, sizeof(ss_addr), AF_INET); - if (hent) + if (hent != NULL) printf("%s\n", hent->h_name); else printf("%s\n", inet_ntoa(ss_addr)); + return 0; } @@ -137,12 +139,12 @@ char **argv; int notrans, mode, getmap; int c, r, i; - yp_get_default_domain(&domain); - map = NULL; getmap = notrans = mode = 0; - while ((c=getopt(argc, argv, "xd:mt")) != -1) - switch (c) { + + yp_get_default_domain(&domain); + while ((c = getopt(argc, argv, "xd:mt")) != -1) + switch(c) { case 'x': for (i=0; i