From 6c265eb9e61a33fde3554a1585afca1f68c11369 Mon Sep 17 00:00:00 2001 From: "William A. Rowe Jr" Date: Tue, 20 Jun 2000 19:30:32 +0000 Subject: [PATCH] Correct the problem where the only local host name that the IP stack can discover are 'undotted' private names. If no fully qualified domain name can be identified, the default ServerName will be set to the machine's IP address string. git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@85636 13f79535-47bb-0310-9956-ffa450edef68 --- server/util.c | 36 +++++++++++++++++++++++++----------- 1 file changed, 25 insertions(+), 11 deletions(-) diff --git a/server/util.c b/server/util.c index b689bfe01f..2bcbbf37a5 100644 --- a/server/util.c +++ b/server/util.c @@ -1879,7 +1879,7 @@ char *ap_get_local_host(ap_pool_t *a) #define MAXHOSTNAMELEN 256 #endif char str[MAXHOSTNAMELEN + 1]; - char *server_hostname; + char *server_hostname = NULL; struct hostent *p; #ifdef BEOS @@ -1888,19 +1888,33 @@ char *ap_get_local_host(ap_pool_t *a) if (gethostname(str, sizeof(str) - 1) != 0) #endif { - perror("Unable to gethostname"); - exit(1); + ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_WARNING, 0, NULL, + "%s: gethostname() failed to detemine ServerName\n", + ap_server_argv0); } - str[MAXHOSTNAMELEN] = '\0'; - if ((!(p = gethostbyname(str))) || (!(server_hostname = find_fqdn(a, p)))) { - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, - "%s: cannot determine local host name.", - ap_server_argv0); - ap_log_error(APLOG_MARK, APLOG_STARTUP | APLOG_NOERRNO, 0, NULL, - "Use the ServerName directive to set it manually."); - exit(1); + else + { + str[sizeof(str) - 1] = '\0'; + if ((!(p = gethostbyname(str))) + || (!(server_hostname = find_fqdn(a, p)))) { + /* Recovery - return the default servername by IP: */ + if (!str && p->h_addr_list[0]) { + ap_snprintf(str, sizeof(str), "%pA", p->h_addr_list[0]); + server_hostname = ap_pstrdup(a, str); + } + } } + if (!server_hostname) + server_hostname = ap_pstrdup(a, "127.0.0.1"); + + ap_log_error(APLOG_MARK, APLOG_ALERT | APLOG_NOERRNO, 0, + NULL, "%s: Missing ServerName directive in httpd.conf.", + ap_server_argv0); + ap_log_error(APLOG_MARK, APLOG_ALERT | APLOG_NOERRNO, 0, + NULL, "%s: assumed ServerName of %s", + ap_server_argv0, server_hostname); + return server_hostname; } -- 2.50.1