]> git.decadent.org.uk Git - nfs-utils.git/commitdiff
libnfs.a: move clnt_ping() to utils/mount
authorChuck Lever <chuck.lever@oracle.com>
Sat, 28 Jul 2007 21:50:40 +0000 (17:50 -0400)
committerNeil Brown <neilb@suse.de>
Mon, 30 Jul 2007 06:12:53 +0000 (16:12 +1000)
Continue clean up of mount functionality in libnfs.a by moving clnt_ping()
to utils/mount/network.c.  Note that socklen_t is an unsigned int... the
i386 gcc compiler threw a signedness warning about the 3rd argument of
getsockname().

Signed-off-by: Chuck Lever <chuck.lever@oracle.com>
Signed-off-by: Neil Brown <neilb@suse.de>
support/include/conn.h
support/nfs/conn.c
utils/mount/network.c
utils/mount/network.h
utils/mount/nfs4mount.c

index 48f5a1c97a25006c9b8bfe0f13fb649a9e1943b1..ee1b686a440f29d8b68c3bb095cd62e169da16a5 100644 (file)
@@ -28,8 +28,6 @@ typedef struct {
 static const struct timeval TIMEOUT = { 20, 0 };
 static const struct timeval RETRY_TIMEOUT = { 3, 0 };
 
-int clnt_ping(struct sockaddr_in *, const u_long, const u_long, const u_int,
-             struct sockaddr_in *);
 int get_socket(struct sockaddr_in *, u_int, int, int);
 
 #endif /* _CONN_H */
index 970abfe38025d3031cf0ec1c547c931226afecd8..d153aa2d55831a0d0db4a1b74fff27ee3fb38ec6 100644 (file)
@@ -97,78 +97,3 @@ int get_socket(struct sockaddr_in *saddr, u_int p_prot, int resvp, int conn)
        }
        return so;
 }
-
-/*
- * Sigh... getport() doesn't actually check the version number.
- * In order to make sure that the server actually supports the service
- * we're requesting, we open and RPC client, and fire off a NULL
- * RPC call.
- */
-int
-clnt_ping(struct sockaddr_in *saddr, const u_long prog, const u_long vers,
-         const u_int prot, struct sockaddr_in *caddr)
-{
-       CLIENT *clnt=NULL;
-       int sock, stat;
-       static char clnt_res;
-       struct sockaddr dissolve;
-
-       rpc_createerr.cf_stat = stat = errno = 0;
-       sock = get_socket(saddr, prot, FALSE, TRUE);
-       if (sock == RPC_ANYSOCK) {
-               if (errno == ETIMEDOUT) {
-                       /*
-                        * TCP timeout. Bubble up the error to see 
-                        * how it should be handled.
-                        */
-                       rpc_createerr.cf_stat = RPC_TIMEDOUT;
-               }
-               return 0;
-       }
-
-       if (caddr) {
-               /* Get the address of our end of this connection */
-               socklen_t len = sizeof(*caddr);
-               if (getsockname(sock, caddr, &len) != 0)
-                       caddr->sin_family = 0;
-       }
-
-       switch(prot) {
-       case IPPROTO_UDP:
-               /* The socket is connected (so we could getsockname successfully),
-                * but some servers on multi-homed hosts reply from
-                * the wrong address, so if we stay connected, we lose the reply.
-                */
-               dissolve.sa_family = AF_UNSPEC;
-               connect(sock, &dissolve, sizeof(dissolve));
-
-               clnt = clntudp_bufcreate(saddr, prog, vers,
-                                        RETRY_TIMEOUT, &sock,
-                                        RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
-               break;
-       case IPPROTO_TCP:
-               clnt = clnttcp_create(saddr, prog, vers, &sock,
-                                     RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
-               break;
-       }
-       if (!clnt) {
-               close(sock);
-               return 0;
-       }
-       memset(&clnt_res, 0, sizeof(clnt_res));
-       stat = clnt_call(clnt, NULLPROC,
-                        (xdrproc_t)xdr_void, (caddr_t)NULL,
-                        (xdrproc_t)xdr_void, (caddr_t)&clnt_res,
-                        TIMEOUT);
-       if (stat) {
-               clnt_geterr(clnt, &rpc_createerr.cf_error);
-               rpc_createerr.cf_stat = stat;
-       }
-       clnt_destroy(clnt);
-       close(sock);
-
-       if (stat == RPC_SUCCESS)
-               return 1;
-       else
-               return 0;
-}
index c092571044b0c31d61cec3f7862c16a93c8f8650..a5b0b71435303b94068c6bc86c5427e7d9c71e64 100644 (file)
 #define NFS_PORT 2049
 #endif
 
+#if SIZEOF_SOCKLEN_T - 0 == 0
+#define socklen_t unsigned int
+#endif
+
 extern int nfs_mount_data_version;
 extern char *progname;
 extern int verbose;
@@ -510,3 +514,78 @@ void mnt_closeclnt(CLIENT *clnt, int msock)
        clnt_destroy(clnt);
        close(msock);
 }
+
+/*
+ * Sigh... getport() doesn't actually check the version number.
+ * In order to make sure that the server actually supports the service
+ * we're requesting, we open and RPC client, and fire off a NULL
+ * RPC call.
+ */
+int clnt_ping(struct sockaddr_in *saddr, const unsigned long prog,
+               const unsigned long vers, const unsigned int prot,
+               struct sockaddr_in *caddr)
+{
+       CLIENT *clnt = NULL;
+       int sock, stat;
+       static char clnt_res;
+       struct sockaddr dissolve;
+
+       rpc_createerr.cf_stat = stat = errno = 0;
+       sock = get_socket(saddr, prot, FALSE, TRUE);
+       if (sock == RPC_ANYSOCK) {
+               if (errno == ETIMEDOUT) {
+                       /*
+                        * TCP timeout. Bubble up the error to see 
+                        * how it should be handled.
+                        */
+                       rpc_createerr.cf_stat = RPC_TIMEDOUT;
+               }
+               return 0;
+       }
+
+       if (caddr) {
+               /* Get the address of our end of this connection */
+               socklen_t len = sizeof(*caddr);
+               if (getsockname(sock, caddr, &len) != 0)
+                       caddr->sin_family = 0;
+       }
+
+       switch(prot) {
+       case IPPROTO_UDP:
+               /* The socket is connected (so we could getsockname successfully),
+                * but some servers on multi-homed hosts reply from
+                * the wrong address, so if we stay connected, we lose the reply.
+                */
+               dissolve.sa_family = AF_UNSPEC;
+               connect(sock, &dissolve, sizeof(dissolve));
+
+               clnt = clntudp_bufcreate(saddr, prog, vers,
+                                        RETRY_TIMEOUT, &sock,
+                                        RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
+               break;
+       case IPPROTO_TCP:
+               clnt = clnttcp_create(saddr, prog, vers, &sock,
+                                     RPCSMALLMSGSIZE, RPCSMALLMSGSIZE);
+               break;
+       }
+       if (!clnt) {
+               close(sock);
+               return 0;
+       }
+       memset(&clnt_res, 0, sizeof(clnt_res));
+       stat = clnt_call(clnt, NULLPROC,
+                        (xdrproc_t)xdr_void, (caddr_t)NULL,
+                        (xdrproc_t)xdr_void, (caddr_t)&clnt_res,
+                        TIMEOUT);
+       if (stat) {
+               clnt_geterr(clnt, &rpc_createerr.cf_error);
+               rpc_createerr.cf_stat = stat;
+       }
+       clnt_destroy(clnt);
+       close(sock);
+
+       if (stat == RPC_SUCCESS)
+               return 1;
+       else
+               return 0;
+}
index b3a5525792120432e7205fa9c78988fc20c43033..0f24a32b7a011c9df7c5a6e8eb9d1ccfaea2e757 100644 (file)
@@ -30,6 +30,9 @@
 int probe_bothports(clnt_addr_t *, clnt_addr_t *);
 int nfs_gethostbyname(const char *, struct sockaddr_in *);
 int nfs_call_umount(clnt_addr_t *, dirpath *);
+int clnt_ping(struct sockaddr_in *, const unsigned long,
+               const unsigned long, const unsigned int,
+               struct sockaddr_in *);
 
 int start_statd(void);
 
index 26a6896855db4c5bc4e959ab80fcb28e7f46eebf..52b0261a6038fd6e6bf411a01fd4e28a7770fd2d 100644 (file)
@@ -46,6 +46,7 @@
 #include "nfs4_mount.h"
 #include "nfs_mount.h"
 #include "error.h"
+#include "network.h"
 
 #if defined(VAR_LOCK_DIR)
 #define DEFAULT_DIR VAR_LOCK_DIR