Module Name:    src
Committed By:   christos
Date:           Wed May  8 00:34:50 UTC 2013

Modified Files:
        src/usr.bin/rpcinfo: rpcinfo.c

Log Message:
Simplify previous: instead of polluting the whole code with extra arguments
and dealing with byteorder, do the whole thing in where we need it.


To generate a diff of this commit:
cvs rdiff -u -r1.35 -r1.36 src/usr.bin/rpcinfo/rpcinfo.c

Please note that diffs are not public domain; they are subject to the
copyright notices on the relevant files.

Modified files:

Index: src/usr.bin/rpcinfo/rpcinfo.c
diff -u src/usr.bin/rpcinfo/rpcinfo.c:1.35 src/usr.bin/rpcinfo/rpcinfo.c:1.36
--- src/usr.bin/rpcinfo/rpcinfo.c:1.35	Tue May  7 17:41:51 2013
+++ src/usr.bin/rpcinfo/rpcinfo.c	Tue May  7 20:34:50 2013
@@ -1,4 +1,4 @@
-/*	$NetBSD: rpcinfo.c,v 1.35 2013/05/07 21:41:51 christos Exp $	*/
+/*	$NetBSD: rpcinfo.c,v 1.36 2013/05/08 00:34:50 christos Exp $	*/
 
 /*
  * Sun RPC is a product of Sun Microsystems, Inc. and is provided for
@@ -141,12 +141,12 @@ __dead static void	brdcst(int, char **);
 static void	addrping(const char *, const char *, int, char **);
 static void	progping(const char *, int, char **);
 static CLIENT	*clnt_addr_create(const char *, const struct netconfig *,
-    rpcprog_t, rpcvers_t, in_port_t *);
+    rpcprog_t, rpcvers_t);
 static CLIENT   *clnt_rpcbind_create(const char *, rpcvers_t, struct netbuf **);
 static CLIENT   *getclnthandle(const char *, const struct netconfig *,
     rpcvers_t, struct netbuf **);
 static CLIENT	*local_rpcb(rpcprog_t, rpcvers_t);
-static int	pstatus(CLIENT *, rpcprog_t, rpcvers_t, in_port_t);
+static int	pstatus(CLIENT *, rpcprog_t, rpcvers_t);
 static void	rpcbdump(int, const char *, int, char **);
 static void	rpcbgetstat(int, char **);
 static void	rpcbaddrlist(const char *, int, char **);
@@ -156,7 +156,6 @@ static void	print_getaddrstat(int, const
 static void	usage(void) __dead;
 static rpcprog_t	getprognum(const char *);
 static rpcvers_t	getvers(const char *);
-static in_port_t	getport(const struct netbuf *);
 static const char *spaces(size_t);
 static bool_t	add_version(struct rpcbdump_short *, rpcvers_t);
 static bool_t	add_netid(struct rpcbdump_short *, char *);
@@ -402,7 +401,7 @@ ip_ping(u_short portnum, const char *tra
 	    NULL, (xdrproc_t)xdr_void, NULL, to);
 	if (argc != 2) {
 		/* Version number was known */
-		if (pstatus(client, prognum, vers, portnum) < 0)
+		if (pstatus(client, prognum, vers) < 0)
 			exit(1);
 		(void)CLNT_DESTROY(client);
 		return;
@@ -438,11 +437,11 @@ ip_ping(u_short portnum, const char *tra
 			minvers = 0;
 			maxvers = MAX_VERS;
 		} else {
-			(void)pstatus(client, prognum, MAX_VERS, portnum);
+			(void)pstatus(client, prognum, MAX_VERS);
 			exit(1);
 		}
 	} else {
-		(void)pstatus(client, prognum, MIN_VERS, portnum);
+		(void)pstatus(client, prognum, MIN_VERS);
 		exit(1);
 	}
 	(void)CLNT_DESTROY(client);
@@ -451,7 +450,7 @@ ip_ping(u_short portnum, const char *tra
 		client = clnt_com_create(&addr, prognum, vers, &fd, trans);
 		rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
 		    NULL, (xdrproc_t)xdr_void, NULL, to);
-		if (pstatus(client, prognum, vers, portnum) < 0)
+		if (pstatus(client, prognum, vers) < 0)
 		    failure = 1;
 		(void)CLNT_DESTROY(client);
 	}
@@ -1250,7 +1249,7 @@ deletereg(const char *netid, int argc, c
  */
 static CLIENT *
 clnt_addr_create(const char *address, const struct netconfig *nconf,
-    rpcprog_t prog, rpcvers_t vers, in_port_t *port)
+    rpcprog_t prog, rpcvers_t vers)
 {
 	CLIENT *client;
 	static struct netbuf *nbuf;
@@ -1266,7 +1265,6 @@ clnt_addr_create(const char *address, co
 		nbuf = uaddr2taddr(nconf, address);
 		if (nbuf == NULL)
 			errx(1, "No address for client handle");
-		*port = getport(nbuf);
 	}
 	client = clnt_tli_create(fd, nconf, nbuf, prog, vers, 0, 0);
 	if (client == NULL) {
@@ -1292,7 +1290,6 @@ addrping(const char *address, const char
 	struct rpc_err rpcerr;
 	int failure = 0;
 	struct netconfig *nconf;
-	in_port_t portnum;
 	int fd;
 
 	if (argc < 1 || argc > 2 || (netid == NULL))
@@ -1312,12 +1309,12 @@ addrping(const char *address, const char
 	} else {
 		versnum = getvers(argv[1]);
 	}
-	client = clnt_addr_create(address, nconf, prognum, versnum, &portnum);
+	client = clnt_addr_create(address, nconf, prognum, versnum);
 	rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
 	    NULL, (xdrproc_t)xdr_void, NULL, to);
 	if (argc == 2) {
 		/* Version number was known */
-		if (pstatus(client, prognum, versnum, portnum) < 0)
+		if (pstatus(client, prognum, versnum) < 0)
 			failure = 1;
 		(void)CLNT_DESTROY(client);
 		if (failure)
@@ -1337,8 +1334,7 @@ addrping(const char *address, const char
 		 * Let's try version MAX_VERS.
 		 */
 		(void)CLNT_DESTROY(client);
-		client = clnt_addr_create(address, nconf, prognum, MAX_VERS,
-		    &portnum);
+		client = clnt_addr_create(address, nconf, prognum, MAX_VERS);
 		rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
 		    NULL, (xdrproc_t)xdr_void, NULL, to);
 		if (rpc_stat == RPC_PROGVERSMISMATCH) {
@@ -1355,20 +1351,19 @@ addrping(const char *address, const char
 			minvers = 0;
 			maxvers = MAX_VERS;
 		} else {
-			(void)pstatus(client, prognum, MAX_VERS, portnum);
+			(void)pstatus(client, prognum, MAX_VERS);
 			exit(1);
 		}
 	} else {
-		(void)pstatus(client, prognum, MIN_VERS, portnum);
+		(void)pstatus(client, prognum, MIN_VERS);
 		exit(1);
 	}
 	(void)CLNT_DESTROY(client);
 	for (versnum = minvers; versnum <= maxvers; versnum++) {
-		client = clnt_addr_create(address, nconf, prognum, versnum,
-		    &portnum);
+		client = clnt_addr_create(address, nconf, prognum, versnum);
 		rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
 		    NULL, (xdrproc_t)xdr_void, NULL, to);
-		if (pstatus(client, prognum, versnum, portnum) < 0)
+		if (pstatus(client, prognum, versnum) < 0)
 			failure = 1;
 		(void)CLNT_DESTROY(client);
 	}
@@ -1426,7 +1421,7 @@ progping(const char *netid, int argc, ch
 	    NULL, (xdrproc_t)xdr_void, NULL, to);
 	if (argc == 3) {
 		/* Version number was known */
-		if (pstatus(client, prognum, versnum, -1) < 0)
+		if (pstatus(client, prognum, versnum) < 0)
 			failure = 1;
 		(void)CLNT_DESTROY(client);
 		if (failure)
@@ -1462,11 +1457,11 @@ progping(const char *netid, int argc, ch
 			minvers = 0;
 			maxvers = MAX_VERS;
 		} else {
-			(void)pstatus(client, prognum, MAX_VERS, -1);
+			(void)pstatus(client, prognum, MAX_VERS);
 			exit(1);
 		}
 	} else {
-		(void)pstatus(client, prognum, MIN_VERS, -1);
+		(void)pstatus(client, prognum, MIN_VERS);
 		exit(1);
 	}
 	for (versnum = minvers; versnum <= maxvers; versnum++) {
@@ -1474,7 +1469,7 @@ progping(const char *netid, int argc, ch
 		    (char *)(void *)&versnum);
 		rpc_stat = CLNT_CALL(client, NULLPROC, (xdrproc_t)xdr_void,
 		    NULL, (xdrproc_t)xdr_void, NULL, to);
-		if (pstatus(client, prognum, versnum, -1) < 0)
+		if (pstatus(client, prognum, versnum) < 0)
 			failure = 1;
 	}
 	(void)CLNT_DESTROY(client);
@@ -1567,7 +1562,7 @@ getport(const struct netbuf *nb)
  * a good error message.
  */
 static int
-pstatus(CLIENT *client, rpcprog_t prog, rpcvers_t vers, in_port_t portnum)
+pstatus(CLIENT *client, rpcprog_t prog, rpcvers_t vers)
 {
 	struct rpc_err rpcerr;
 
@@ -1578,14 +1573,13 @@ pstatus(CLIENT *client, rpcprog_t prog, 
 		    clnt_sperror(client, "") + 2);
 		return -1;
 	} else {
-		if (portnum == (in_port_t)-1) {
-			struct netbuf nb;
-			CLNT_CONTROL(client, CLGET_SVC_ADDR, (char *)&nb);
-			portnum = getport(&nb);
-		}
+		in_port_t portnum;
+		struct netbuf nb;
+		CLNT_CONTROL(client, CLGET_SVC_ADDR, (char *)&nb);
+		portnum = ntohs(getport(&nb));
 		(void)printf("program %lu version %lu ready and waiting"
 		    " at port %u\n", (unsigned long)prog, (unsigned long)vers,
-		    ntohs(portnum));
+		    portnum);
 		return 0;
 	}
 }

Reply via email to