MCPcopy Create free account
hub / github.com/apache/httpd / ap_get_local_host

Function ap_get_local_host

server/util.c:2429–2473  ·  view source on GitHub ↗

* We must return a FQDN */

Source from the content-addressed store, hash-verified

2427 * We must return a FQDN
2428 */
2429char *ap_get_local_host(apr_pool_t *a)
2430{
2431#ifndef MAXHOSTNAMELEN
2432#define MAXHOSTNAMELEN 256
2433#endif
2434 char str[MAXHOSTNAMELEN + 1];
2435 char *server_hostname = NULL;
2436 apr_sockaddr_t *sockaddr;
2437 char *hostname;
2438
2439 if (apr_gethostname(str, sizeof(str) - 1, a) != APR_SUCCESS) {
2440 ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_WARNING, 0, a, APLOGNO(00556)
2441 "%s: apr_gethostname() failed to determine ServerName",
2442 ap_server_argv0);
2443 } else {
2444 str[sizeof(str) - 1] = '\0';
2445 if (apr_sockaddr_info_get(&sockaddr, str, APR_UNSPEC, 0, 0, a) == APR_SUCCESS) {
2446 if ( (apr_getnameinfo(&hostname, sockaddr, 0) == APR_SUCCESS) &&
2447 (ap_strchr_c(hostname, '.')) ) {
2448 server_hostname = apr_pstrdup(a, hostname);
2449 return server_hostname;
2450 } else if (ap_strchr_c(str, '.')) {
2451 server_hostname = apr_pstrdup(a, str);
2452 } else {
2453 apr_sockaddr_ip_get(&hostname, sockaddr);
2454 server_hostname = apr_pstrdup(a, hostname);
2455 }
2456 } else {
2457 ap_log_perror(APLOG_MARK, APLOG_STARTUP | APLOG_WARNING, 0, a, APLOGNO(00557)
2458 "%s: apr_sockaddr_info_get() failed for %s",
2459 ap_server_argv0, str);
2460 }
2461 }
2462
2463 if (!server_hostname)
2464 server_hostname = apr_pstrdup(a, "127.0.0.1");
2465
2466 ap_log_perror(APLOG_MARK, APLOG_ALERT|APLOG_STARTUP, 0, a, APLOGNO(00558)
2467 "%s: Could not reliably determine the server's fully qualified "
2468 "domain name, using %s. Set the 'ServerName' directive globally "
2469 "to suppress this message",
2470 ap_server_argv0, server_hostname);
2471
2472 return server_hostname;
2473}
2474
2475/* simple 'pool' alloc()ing glue to apr_base64.c
2476 */

Callers 1

ap_fini_vhost_configFunction · 0.85

Calls 1

ap_strchr_cFunction · 0.85

Tested by

no test coverage detected