]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/mount/network.c
This is the second iteration of this patch. The only difference here
[nfs-utils.git] / utils / mount / network.c
index d598fcf014d2cd4236c18847a23019a70689ed9b..c400dd8beec3ecec07f674be8bc9a864ea6af4bf 100644 (file)
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/wait.h>
+#include <sys/stat.h>
 #include <netinet/in.h>
 #include <rpc/rpc.h>
 #include <rpc/pmap_prot.h>
 #include <rpc/pmap_clnt.h>
 
+#include "sockaddr.h"
 #include "xcommon.h"
 #include "mount.h"
 #include "nls.h"
 #define CONNECT_TIMEOUT        (20)
 #define MOUNT_TIMEOUT  (30)
 
-#if SIZEOF_SOCKLEN_T - 0 == 0
-#define socklen_t unsigned int
-#endif
-
 extern int nfs_mount_data_version;
 extern char *progname;
 extern int verbose;
@@ -252,25 +250,6 @@ int nfs_lookup(const char *hostname, const sa_family_t family,
        return ret;
 }
 
-/**
- * nfs_name_to_address - resolve hostname to an IPv4 or IPv6 socket address
- * @hostname: pointer to C string containing DNS hostname to resolve
- * @sap: pointer to buffer to fill with socket address
- * @len: IN: size of buffer to fill; OUT: size of socket address
- *
- * Returns 1 and places a socket address at @sap if successful;
- * otherwise zero.
- */
-int nfs_name_to_address(const char *hostname,
-                       struct sockaddr *sap, socklen_t *salen)
-{
-#ifdef IPV6_SUPPORTED
-       return nfs_lookup(hostname, AF_UNSPEC, sap, salen);
-#else  /* !IPV6_SUPPORTED */
-       return nfs_lookup(hostname, AF_INET, sap, salen);
-#endif /* !IPV6_SUPPORTED */
-}
-
 /**
  * nfs_gethostbyname - resolve a hostname to an IPv4 address
  * @hostname: pointer to a C string containing a DNS hostname
@@ -293,8 +272,8 @@ int nfs_gethostbyname(const char *hostname, struct sockaddr_in *sin)
  *             OUT: length of converted socket address
  *
  * Convert a presentation format address string to a socket address.
- * Similar to nfs_name_to_address(), but the DNS query is squelched,
- * and won't make any noise if the getaddrinfo() call fails.
+ * Similar to nfs_lookup(), but the DNS query is squelched, and it
+ * won't make any noise if the getaddrinfo() call fails.
  *
  * Returns 1 and fills in @sap and @salen if successful; otherwise zero.
  *
@@ -559,8 +538,8 @@ static int nfs_probe_port(const struct sockaddr *sap, const socklen_t salen,
                          struct pmap *pmap, const unsigned long *versions,
                          const unsigned int *protos)
 {
-       struct sockaddr_storage address;
-       struct sockaddr *saddr = (struct sockaddr *)&address;
+       union nfs_sockaddr address;
+       struct sockaddr *saddr = &address.sa;
        const unsigned long prog = pmap->pm_prog, *p_vers;
        const unsigned int prot = (u_int)pmap->pm_prot, *p_prot;
        const u_short port = (u_short) pmap->pm_port;
@@ -850,8 +829,8 @@ int start_statd(void)
 int nfs_advise_umount(const struct sockaddr *sap, const socklen_t salen,
                      const struct pmap *pmap, const dirpath *argp)
 {
-       struct sockaddr_storage address;
-       struct sockaddr *saddr = (struct sockaddr *)&address;
+       union nfs_sockaddr address;
+       struct sockaddr *saddr = &address.sa;
        struct pmap mnt_pmap = *pmap;
        struct timeval timeout = {
                .tv_sec         = MOUNT_TIMEOUT >> 3,
@@ -1353,6 +1332,12 @@ nfs_nfs_port(struct mount_options *options, unsigned long *port)
        return 1;
 }
 
+#ifdef IPV6_SUPPORTED
+sa_family_t    config_default_family = AF_UNSPEC;
+#else
+sa_family_t    config_default_family = AF_INET;
+#endif
+
 /*
  * Returns TRUE and fills in @family if a valid NFS protocol option
  * is found, or FALSE if the option was specified with an invalid value.
@@ -1363,11 +1348,7 @@ int nfs_nfs_proto_family(struct mount_options *options,
        unsigned long protocol;
        char *option;
 
-#ifdef HAVE_LIBTIRPC
-       *family = AF_UNSPEC;
-#else
-       *family = AF_INET;
-#endif
+       *family = config_default_family;
 
        switch (po_rightmost(options, nfs_transport_opttbl)) {
        case 0: /* udp */
@@ -1510,11 +1491,7 @@ int nfs_mount_proto_family(struct mount_options *options,
        unsigned long protocol;
        char *option;
 
-#ifdef HAVE_LIBTIRPC
-       *family = AF_UNSPEC;
-#else
-       *family = AF_INET;
-#endif
+       *family = config_default_family;
 
        option = po_get(options, "mountproto");
        if (option != NULL)