@@ -1977,59 +1977,29 @@ AP_DECLARE(void) ap_str_tolower(char *str)
19771977 }
19781978}
19791979
1980- static char * find_fqdn (apr_pool_t * a , struct hostent * p )
1981- {
1982- int x ;
1983-
1984- if (!strchr (p -> h_name , '.' )) {
1985- if (p -> h_aliases ) {
1986- for (x = 0 ; p -> h_aliases [x ]; ++ x ) {
1987- if (strchr (p -> h_aliases [x ], '.' ) &&
1988- (!strncasecmp (p -> h_aliases [x ], p -> h_name ,
1989- strlen (p -> h_name ))))
1990- return apr_pstrdup (a , p -> h_aliases [x ]);
1991- }
1992- }
1993- return NULL ;
1994- }
1995- return apr_pstrdup (a , (void * ) p -> h_name );
1996- }
1997-
19981980char * ap_get_local_host (apr_pool_t * a )
19991981{
20001982#ifndef MAXHOSTNAMELEN
20011983#define MAXHOSTNAMELEN 256
20021984#endif
20031985 char str [MAXHOSTNAMELEN + 1 ];
20041986 char * server_hostname = NULL ;
2005- struct hostent * p ;
1987+ apr_sockaddr_t * sockaddr ;
20061988
2007- #ifdef BEOS_R5
2008- if (gethostname (str , sizeof (str ) - 1 ) == 0 )
2009- #else
2010- if (gethostname (str , sizeof (str ) - 1 ) != 0 )
2011- #endif
2012- {
1989+ if (apr_gethostname (str , sizeof (str ) - 1 , a ) != APR_SUCCESS ) {
20131990 ap_log_perror (APLOG_MARK , APLOG_STARTUP | APLOG_WARNING , 0 , a ,
2014- "%s: gethostname () failed to determine ServerName" ,
1991+ "%s: apr_gethostname () failed to determine ServerName" ,
20151992 ap_server_argv0 );
2016- }
2017- else
2018- {
1993+ } else {
20191994 str [sizeof (str ) - 1 ] = '\0' ;
2020- /* TODO: Screaming for APR-ization */
2021- if ((!(p = gethostbyname (str )))
2022- || (!(server_hostname = find_fqdn (a , p )))) {
2023- /* Recovery - return the default servername by IP: */
2024- if (p && p -> h_addr_list [0 ]) {
2025- apr_snprintf (str , sizeof (str ), "%pA" , p -> h_addr_list [0 ]);
2026- server_hostname = apr_pstrdup (a , str );
2027- /* We will drop through to report the IP-named server */
2028- }
2029- }
2030- else {
2031- /* Since we found a fdqn, return it with no logged message. */
1995+ if (apr_sockaddr_info_get (& sockaddr , str , AF_INET , 0 , 0 , a ) == APR_SUCCESS ) {
1996+ server_hostname = apr_pstrdup (a , sockaddr -> hostname );
20321997 return server_hostname ;
1998+ } else {
1999+ ap_log_perror (APLOG_MARK , APLOG_STARTUP | APLOG_WARNING , 0 , a ,
2000+ "%s: apr_sockaddr_info_get() failed for hostname '%s'" ,
2001+ ap_server_argv0 , str );
2002+ server_hostname = apr_pstrdup (a , str );
20332003 }
20342004 }
20352005
0 commit comments