Andrew Bartlet pointed out that the patch was incomplete, update and write doxygen.
authorLove Hornquist Astrand <lha@h5l.org>
Thu, 30 Sep 2010 07:44:35 +0000 (00:44 -0700)
committerLove Hornquist Astrand <lha@h5l.org>
Thu, 30 Sep 2010 07:44:35 +0000 (00:44 -0700)
lib/krb5/krbhst.c

index 29a203f4dcaa660f2c4e9894a03b92a422d77abc..7d111578481b10a6cc50a05fc82748b6a2684542 100644 (file)
@@ -370,35 +370,52 @@ KRB5_LIB_FUNCTION krb5_error_code KRB5_LIB_CALL
 krb5_krbhst_get_addrinfo(krb5_context context, krb5_krbhst_info *host,
                         struct addrinfo **ai)
 {
-    struct addrinfo hints;
-    char portstr[NI_MAXSERV];
-    int ret;
+    int ret = 0;
 
     if (host->ai == NULL) {
+       struct addrinfo hints;
+       char portstr[NI_MAXSERV];
        char *hostname = host->hostname;
 
+       snprintf (portstr, sizeof(portstr), "%d", host->port);
+       make_hints(&hints, host->proto);
+
        /**
-        * If the hostname contains a dot, assumes it's a FQAN and
+        * First try this as an IP address, this allows us to add a
+        * dot at the end to stop using the search domains.
+        */
+
+       hints.ai_flags |= AI_NUMERICHOST | AI_NUMERICSERV;
+
+       ret = getaddrinfo(host->hostname, portstr, &hints, &host->ai);
+       if (ret == 0)
+           goto out;
+
+       /**
+        * If the hostname contains a dot, assumes it's a FQDN and
         * don't use search domains since that might be painfully slow
         * when machine is disconnected from that network.
         */
 
-       if (strchr(hostname, '.') && hostname[strlen(hostname) - 1] == '.') {
+       hints.ai_flags &= ~(AI_NUMERICHOST);
+
+       if (strchr(hostname, '.') && hostname[strlen(hostname) - 1] != '.') {
            ret = asprintf(&hostname, "%s.", host->hostname);
            if (ret < 0 || hostname == NULL)
                return ENOMEM;
        }
 
-       make_hints(&hints, host->proto);
-       snprintf (portstr, sizeof(portstr), "%d", host->port);
        ret = getaddrinfo(hostname, portstr, &hints, &host->ai);
        if (hostname != host->hostname)
            free(hostname);
-       if (ret)
-           return krb5_eai_to_heim_errno(ret, errno);
+       if (ret) {
+           ret = krb5_eai_to_heim_errno(ret, errno);
+           goto out;
+       }
     }
+ out:
     *ai = host->ai;
-    return 0;
+    return ret;
 }
 
 static krb5_boolean