]> git.decadent.org.uk Git - nfs-utils.git/blobdiff - utils/exportfs/exportfs.c
mountd: Replace "struct hostent" with "struct addrinfo"
[nfs-utils.git] / utils / exportfs / exportfs.c
index 83d00a0637a9ab819c406c202ba1f1dfa5d5b3d1..0070b544d654400f9dbafa1127423e55609c5ea0 100644 (file)
@@ -232,7 +232,7 @@ exportfs(char *arg, char *options, int verbose)
 {
        struct exportent *eep;
        nfs_export      *exp;
-       struct hostent  *hp = NULL;
+       struct addrinfo *ai = NULL;
        char            *path;
        char            *hname = arg;
        int             htype;
@@ -245,32 +245,21 @@ exportfs(char *arg, char *options, int verbose)
                return;
        }
 
-       if ((htype = client_gettype(hname)) == MCL_FQDN &&
-           (hp = gethostbyname(hname)) != NULL) {
-               struct hostent *hp2 = hostent_dup (hp);
-               hp = gethostbyaddr(hp2->h_addr, hp2->h_length,
-                                  hp2->h_addrtype);
-               if (hp) {
-                       free(hp2);
-                       hp = hostent_dup(hp);
-               } else
-                       hp = hp2;
-               exp = export_find(hp, path);
-               hname = hp->h_name;
-       } else {
+       if ((htype = client_gettype(hname)) == MCL_FQDN) {
+               ai = host_addrinfo(hname);
+               if (ai != NULL) {
+                       exp = export_find(ai, path);
+                       hname = ai->ai_canonname;
+               }
+       } else
                exp = export_lookup(hname, path, 0);
-       }
 
        if (!exp) {
                if (!(eep = mkexportent(hname, path, options)) ||
-                   !(exp = export_create(eep, 0))) {
-                       if (hp) free (hp);
-                       return;
-               }
-       } else if (!updateexportent(&exp->m_export, options)) {
-               if (hp) free (hp);
-               return;
-       }
+                   !(exp = export_create(eep, 0)))
+                       goto out;
+       } else if (!updateexportent(&exp->m_export, options))
+               goto out;
 
        if (verbose)
                printf("exporting %s:%s\n", exp->m_client->m_hostname, 
@@ -280,7 +269,9 @@ exportfs(char *arg, char *options, int verbose)
        exp->m_changed = 1;
        exp->m_warned = 0;
        validate_export(exp);
-       if (hp) free (hp);
+
+out:
+       freeaddrinfo(ai);
 }
 
 static void