Return-Path: Delivered-To: apmail-httpd-cvs-archive@www.apache.org Received: (qmail 136 invoked from network); 21 Apr 2005 17:30:25 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 21 Apr 2005 17:30:25 -0000 Received: (qmail 85893 invoked by uid 500); 21 Apr 2005 17:30:42 -0000 Delivered-To: apmail-httpd-cvs-archive@httpd.apache.org Received: (qmail 85853 invoked by uid 500); 21 Apr 2005 17:30:41 -0000 Mailing-List: contact cvs-help@httpd.apache.org; run by ezmlm Precedence: bulk Reply-To: dev@httpd.apache.org list-help: list-unsubscribe: List-Post: Delivered-To: mailing list cvs@httpd.apache.org Received: (qmail 85838 invoked by uid 99); 21 Apr 2005 17:30:41 -0000 X-ASF-Spam-Status: No, hits=0.2 required=10.0 tests=NO_REAL_NAME X-Spam-Check-By: apache.org Received: from minotaur.apache.org (HELO minotaur.apache.org) (209.237.227.194) by apache.org (qpsmtpd/0.28) with SMTP; Thu, 21 Apr 2005 10:30:41 -0700 Received: (qmail 99972 invoked by uid 65534); 21 Apr 2005 17:30:22 -0000 Message-ID: <20050421173022.99971.qmail@minotaur.apache.org> Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Subject: svn commit: r164092 - /httpd/httpd/trunk/server/util.c Date: Thu, 21 Apr 2005 17:30:22 -0000 To: cvs@httpd.apache.org From: jim@apache.org X-Mailer: svnmailer-1.0.0-dev X-Virus-Checked: Checked X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Author: jim Date: Thu Apr 21 10:30:21 2005 New Revision: 164092 URL: http://svn.apache.org/viewcvs?rev=3D164092&view=3Drev Log: 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. 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=3D16= 4092&r1=3D164091&r2=3D164092&view=3Ddiff =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D --- httpd/httpd/trunk/server/util.c (original) +++ httpd/httpd/trunk/server/util.c Thu Apr 21 10:30:21 2005 @@ -1977,6 +1977,9 @@ } } =20 +/* + * We must return a FQDN + */ char *ap_get_local_host(apr_pool_t *a) { #ifndef MAXHOSTNAMELEN @@ -1985,6 +1988,7 @@ char str[MAXHOSTNAMELEN + 1]; char *server_hostname =3D NULL; apr_sockaddr_t *sockaddr; + char *hostname; =20 if (apr_gethostname(str, sizeof(str) - 1, a) !=3D APR_SUCCESS) { ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_WARNING, 0, a, @@ -1992,14 +1996,21 @@ ap_server_argv0); } else { str[sizeof(str) - 1] =3D '\0'; - if (apr_sockaddr_info_get(&sockaddr, str, AF_INET, 0, 0, a) =3D=3D= APR_SUCCESS) { - server_hostname =3D apr_pstrdup(a, sockaddr->hostname); - return server_hostname; + if (apr_sockaddr_info_get(&sockaddr, str, APR_UNSPEC, 0, 0, a) =3D= =3D APR_SUCCESS) { + if ( (apr_getnameinfo(&hostname, sockaddr, 0) =3D=3D APR_SUCCE= SS) && + (ap_strchr_c(hostname, '.')) ) { + server_hostname =3D apr_pstrdup(a, hostname); + return server_hostname; + } else if (ap_strchr_c(str, '.')) { + server_hostname =3D apr_pstrdup(a, str); + } else { + apr_sockaddr_ip_get(&hostname, sockaddr); + server_hostname =3D 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 =3D apr_pstrdup(a, str); } } =20 @@ -2007,7 +2018,7 @@ server_hostname =3D apr_pstrdup(a, "127.0.0.1"); =20 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 qual= ified " "domain name, using %s for ServerName", ap_server_argv0, server_hostname); =20