]> granicus.if.org Git - libtirpc/commitdiff
Introduce new helper function getpmaphandle
authorOlaf Kirch <okir@suse.de>
Tue, 16 Dec 2014 18:43:30 +0000 (13:43 -0500)
committerSteve Dickson <steved@redhat.com>
Tue, 16 Dec 2014 19:04:33 +0000 (14:04 -0500)
This moves some code for creation of PMAP handles out of the getaddr
code and into a function of its own.

Signed-off-by: Olaf Kirch <okir@suse.de>
Signed-off-by: Steve Dickson <steved@redhat.com>
INSTALL
src/rpcb_clnt.c

diff --git a/INSTALL b/INSTALL
index 8b641e394823ac11d9b95afd89bff35b47f0f808..f812f5a257ee91d3693c395c4971adb0584c76cd 120000 (symlink)
--- a/INSTALL
+++ b/INSTALL
@@ -1 +1 @@
-/usr/share/automake-1.13/INSTALL
\ No newline at end of file
+/usr/share/automake-1.14/INSTALL
\ No newline at end of file
index a796593fb19d800323e89bb5eceb1a7114d7f6bf..f1c71a2c6afada3c258d79bb689c3f20c2e20f5b 100644 (file)
@@ -401,6 +401,44 @@ out_err:
        return (client);
 }
 
+/*
+ * Create a PMAP client handle.
+ */
+static CLIENT *
+getpmaphandle(nconf, hostname, tgtaddr)
+       const struct netconfig *nconf;
+       const char *hostname;
+       char **tgtaddr;
+{
+       CLIENT *client = NULL;
+       rpcvers_t pmapvers = 2;
+
+       /*
+        * Try UDP only - there are some portmappers out
+        * there that use UDP only.
+        */
+       if (nconf == NULL || strcmp(nconf->nc_proto, NC_TCP) == 0) {
+               struct netconfig *newnconf;
+
+               if ((newnconf = getnetconfigent("udp")) == NULL) {
+                       rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
+                       return NULL;
+               }
+               client = getclnthandle(hostname, newnconf, tgtaddr);
+               freenetconfigent(newnconf);
+       } else if (strcmp(nconf->nc_proto, NC_UDP) == 0) {
+               if (strcmp(nconf->nc_protofmly, NC_INET) != 0)
+                       return NULL;
+               client = getclnthandle(hostname, nconf, tgtaddr);
+       }
+
+       /* Set version */
+       if (client != NULL)
+               CLNT_CONTROL(client, CLSET_VERS, (char *)&pmapvers);
+
+       return client;
+}
+
 /* XXX */
 #define IN4_LOCALHOST_STRING   "127.0.0.1"
 #define IN6_LOCALHOST_STRING   "::1"
@@ -733,34 +771,20 @@ __rpcb_findaddr_timed(program, version, nconf, host, clpp, tp)
        if (strcmp(nconf->nc_protofmly, NC_INET) == 0) {
                u_short port = 0;
                struct netbuf remote;
-               rpcvers_t pmapvers = 2;
                struct pmap pmapparms;
 
-               /*
-                * Try UDP only - there are some portmappers out
-                * there that use UDP only.
-                */
-               if (strcmp(nconf->nc_proto, NC_TCP) == 0) {
-                       struct netconfig *newnconf;
-
-                       if ((newnconf = getnetconfigent("udp")) == NULL) {
-                               rpc_createerr.cf_stat = RPC_UNKNOWNPROTO;
-                               return (NULL);
-                       }
-                       client = getclnthandle(host, newnconf, &parms.r_addr);
-                       freenetconfigent(newnconf);
-               } else if (strcmp(nconf->nc_proto, NC_UDP) == 0)
-                       client = getclnthandle(host, nconf, &parms.r_addr);
-               else
+               if (strcmp(nconf->nc_proto, NC_UDP) != 0
+                && strcmp(nconf->nc_proto, NC_TCP) != 0)
                        goto try_rpcbind;
+
+               client = getpmaphandle(nconf, host, &parms.r_addr);
                if (client == NULL)
                        return (NULL);
 
                /*
-                * Set version and retry timeout.
+                * Set retry timeout.
                 */
                CLNT_CONTROL(client, CLSET_RETRY_TIMEOUT, (char *)&rpcbrmttime);
-               CLNT_CONTROL(client, CLSET_VERS, (char *)&pmapvers);
 
                pmapparms.pm_prog = program;
                pmapparms.pm_vers = version;