diff options
author | Jim Jagielski <jim@apache.org> | 2005-04-21 19:30:21 +0200 |
---|---|---|
committer | Jim Jagielski <jim@apache.org> | 2005-04-21 19:30:21 +0200 |
commit | 9ba8a004c9ee6eeb38a03c0607a32fb3480d9188 (patch) | |
tree | 21ef53390040b847804ed4e99bb424a099d41a1d /server | |
parent | APRized ap_get_local_host() (diff) | |
download | apache2-9ba8a004c9ee6eeb38a03c0607a32fb3480d9188.tar.xz apache2-9ba8a004c9ee6eeb38a03c0607a32fb3480d9188.zip |
Ensure that we always return a FQDN... This is not guaranteed by either
apr_sockaddr_info_get() or apr_getnameinfo(). Also note that under
OS X, apr_getnameinfo() always seems to fail (at least on my
machines) so if we don't specific ServerName at the global setting,
we get a warning.
git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@164092 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'server')
-rw-r--r-- | server/util.c | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/server/util.c b/server/util.c index 6adb1e2169..f506423b24 100644 --- a/server/util.c +++ b/server/util.c @@ -1977,6 +1977,9 @@ AP_DECLARE(void) ap_str_tolower(char *str) } } +/* + * We must return a FQDN + */ char *ap_get_local_host(apr_pool_t *a) { #ifndef MAXHOSTNAMELEN @@ -1985,6 +1988,7 @@ char *ap_get_local_host(apr_pool_t *a) char str[MAXHOSTNAMELEN + 1]; char *server_hostname = NULL; apr_sockaddr_t *sockaddr; + char *hostname; if (apr_gethostname(str, sizeof(str) - 1, a) != APR_SUCCESS) { ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_WARNING, 0, a, @@ -1992,14 +1996,21 @@ char *ap_get_local_host(apr_pool_t *a) ap_server_argv0); } else { str[sizeof(str) - 1] = '\0'; - if (apr_sockaddr_info_get(&sockaddr, str, AF_INET, 0, 0, a) == APR_SUCCESS) { - server_hostname = apr_pstrdup(a, sockaddr->hostname); - return server_hostname; + if (apr_sockaddr_info_get(&sockaddr, str, APR_UNSPEC, 0, 0, a) == APR_SUCCESS) { + if ( (apr_getnameinfo(&hostname, sockaddr, 0) == APR_SUCCESS) && + (ap_strchr_c(hostname, '.')) ) { + server_hostname = apr_pstrdup(a, hostname); + return server_hostname; + } else if (ap_strchr_c(str, '.')) { + server_hostname = apr_pstrdup(a, str); + } else { + apr_sockaddr_ip_get(&hostname, sockaddr); + server_hostname = apr_pstrdup(a, hostname); + } } else { ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_WARNING, 0, a, - "%s: apr_sockaddr_info_get() failed for hostname '%s'", + "%s: apr_sockaddr_info_get() failed for %s", ap_server_argv0, str); - server_hostname = apr_pstrdup(a, str); } } @@ -2007,7 +2018,7 @@ char *ap_get_local_host(apr_pool_t *a) server_hostname = apr_pstrdup(a, "127.0.0.1"); ap_log_perror(APLOG_MARK, APLOG_ALERT|APLOG_STARTUP, 0, a, - "%s: Could not determine the server's fully qualified " + "%s: Could not reliably determine the server's fully qualified " "domain name, using %s for ServerName", ap_server_argv0, server_hostname); |