Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/usr.bin/rpcinfo Simplify previous: instead of polluting the ...



details:   https://anonhg.NetBSD.org/src/rev/ff5cddfc3d9b
branches:  trunk
changeset: 786726:ff5cddfc3d9b
user:      christos <christos%NetBSD.org@localhost>
date:      Wed May 08 00:34:50 2013 +0000

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

diffstat:

 usr.bin/rpcinfo/rpcinfo.c |  56 ++++++++++++++++++++--------------------------
 1 files changed, 25 insertions(+), 31 deletions(-)

diffs (200 lines):

diff -r 6cb9d14201fa -r ff5cddfc3d9b usr.bin/rpcinfo/rpcinfo.c
--- a/usr.bin/rpcinfo/rpcinfo.c Wed May 08 00:25:55 2013 +0000
+++ b/usr.bin/rpcinfo/rpcinfo.c Wed May 08 00:34:50 2013 +0000
@@ -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 @@
 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    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 @@
            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 @@
                        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 @@
                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 @@
  */
 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 @@
                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 @@
        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 @@
        } 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 @@
                 * 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 @@
                        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 @@
            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 @@
                        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 @@
                    (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 @@
  * 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 @@
                    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;
        }
 }



Home | Main Index | Thread Index | Old Index