You are viewing a plain text version of this content. The canonical link for it is here.
Posted to cvs@httpd.apache.org by ji...@apache.org on 2005/04/20 22:40:46 UTC

svn commit: r162066 - /httpd/httpd/trunk/server/util.c

Author: jim
Date: Wed Apr 20 13:40:46 2005
New Revision: 162066

URL: http://svn.apache.org/viewcvs?rev=162066&view=rev
Log:
APRized ap_get_local_host()

Modified:
    httpd/httpd/trunk/server/util.c

Modified: httpd/httpd/trunk/server/util.c
URL: http://svn.apache.org/viewcvs/httpd/httpd/trunk/server/util.c?rev=162066&r1=162065&r2=162066&view=diff
==============================================================================
--- httpd/httpd/trunk/server/util.c (original)
+++ httpd/httpd/trunk/server/util.c Wed Apr 20 13:40:46 2005
@@ -1977,24 +1977,6 @@
     }
 }
 
-static char *find_fqdn(apr_pool_t *a, struct hostent *p)
-{
-    int x;
-
-    if (!strchr(p->h_name, '.')) {
-        if (p->h_aliases) {
-            for (x = 0; p->h_aliases[x]; ++x) {
-                if (strchr(p->h_aliases[x], '.') &&
-                    (!strncasecmp(p->h_aliases[x], p->h_name,
-                                  strlen(p->h_name))))
-                    return apr_pstrdup(a, p->h_aliases[x]);
-            }
-        }
-        return NULL;
-    }
-    return apr_pstrdup(a, (void *) p->h_name);
-}
-
 char *ap_get_local_host(apr_pool_t *a)
 {
 #ifndef MAXHOSTNAMELEN
@@ -2002,34 +1984,22 @@
 #endif
     char str[MAXHOSTNAMELEN + 1];
     char *server_hostname = NULL;
-    struct hostent *p;
+    apr_sockaddr_t *sockaddr;
 
-#ifdef BEOS_R5
-    if (gethostname(str, sizeof(str) - 1) == 0)
-#else
-    if (gethostname(str, sizeof(str) - 1) != 0)
-#endif
-    {
+    if (apr_gethostname(str, sizeof(str) - 1, a) != APR_SUCCESS) {
         ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_WARNING, 0, a,
-                     "%s: gethostname() failed to determine ServerName",
+                     "%s: apr_gethostname() failed to determine ServerName",
                      ap_server_argv0);
-    }
-    else 
-    {
+    } else {
         str[sizeof(str) - 1] = '\0';
-        /* TODO: Screaming for APR-ization */
-        if ((!(p = gethostbyname(str))) 
-            || (!(server_hostname = find_fqdn(a, p)))) {
-            /* Recovery - return the default servername by IP: */
-            if (p && p->h_addr_list[0]) {
-                apr_snprintf(str, sizeof(str), "%pA", p->h_addr_list[0]);
-                server_hostname = apr_pstrdup(a, str);
-                /* We will drop through to report the IP-named server */
-            }
-        }
-        else {
-            /* Since we found a fdqn, return it with no logged message. */
+        if (apr_sockaddr_info_get(&sockaddr, str, AF_INET, 0, 0, a) == APR_SUCCESS) {
+            server_hostname = apr_pstrdup(a, sockaddr->hostname);
             return server_hostname;
+        } else {
+            ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_WARNING, 0, a,
+                         "%s: apr_sockaddr_info_get() failed for hostname '%s'",
+                         ap_server_argv0, str);
+            server_hostname = apr_pstrdup(a, str);
         }
     }