diff --git a/cherokee/resolv_cache.c b/cherokee/resolv_cache.c index 413b7a3de..d19acd842 100644 --- a/cherokee/resolv_cache.c +++ b/cherokee/resolv_cache.c @@ -97,7 +97,7 @@ entry_fill_up (cherokee_resolv_cache_entry_t *entry, time_t eagain_at = 0; while (true) { - ret = cherokee_gethostbyname (domain->buf, &entry->addr); + ret = cherokee_gethostbyname (domain, &entry->addr); if (ret == ret_ok) { break; diff --git a/cherokee/util.c b/cherokee/util.c index 80891b785..96f583070 100644 --- a/cherokee/util.c +++ b/cherokee/util.c @@ -757,7 +757,7 @@ cherokee_eval_formated_time (cherokee_buffer_t *buf) ret_t -cherokee_gethostbyname (const char *hostname, struct addrinfo **addr) +cherokee_gethostbyname (cherokee_buffer_t *hostname, struct addrinfo **addr) { int n; struct addrinfo hints; @@ -768,13 +768,24 @@ cherokee_gethostbyname (const char *hostname, struct addrinfo **addr) hints.ai_family = AF_UNSPEC; hints.ai_socktype = SOCK_STREAM; + #ifdef AI_ADDRCONFIG - if ((strcmp(hostname, "127.0.0.1") != 0) && - (strcmp(hostname, "localhost") != 0) && - (strcmp(hostname, "localhost.localdomain") != 0) && - (strcmp(hostname, "::1") != 0) && - (strcmp(hostname, "localhost6") != 0) && - (strcmp(hostname, "localhost6.localdomain6") != 0)) + /* Workaround for loopback host addresses: + * + * If a computer does not have any outgoing IPv6 network + * interface, but its loopback network interface supports + * IPv6, a getaddrinfo call on "localhost" with AI_ADDRCONFIG + * won't return the IPv6 loopback address "::1", because + * getaddrinfo() thinks the computer cannot connect to any + * IPv6 destination, ignoring the remote vs. local/loopback + * distinction. + */ + if ((cherokee_buffer_cmp_str (hostname, "::1") == 0) || + (cherokee_buffer_cmp_str (hostname, "127.0.0.1") == 0) || + (cherokee_buffer_cmp_str (hostname, "localhost") == 0) || + (cherokee_buffer_cmp_str (hostname, "localhost6") == 0) || + (cherokee_buffer_cmp_str (hostname, "localhost.localdomain") == 0) || + (cherokee_buffer_cmp_str (hostname, "localhost6.localdomain6") == 0)) { hints.ai_flags = AI_ADDRCONFIG; } @@ -782,7 +793,7 @@ cherokee_gethostbyname (const char *hostname, struct addrinfo **addr) /* Resolve address */ - n = getaddrinfo (hostname, NULL, &hints, addr); + n = getaddrinfo (hostname->buf, NULL, &hints, addr); if (n < 0) { return ret_error; } diff --git a/cherokee/util.h b/cherokee/util.h index 63c9dfdb7..ebe69011f 100644 --- a/cherokee/util.h +++ b/cherokee/util.h @@ -161,7 +161,7 @@ int cherokee_open (const char *path, int oflag, int mode); int cherokee_unlink (const char *path); int cherokee_pipe (int fildes[2]); -ret_t cherokee_gethostbyname (const char *hostname, struct addrinfo **addr); +ret_t cherokee_gethostbyname (cherokee_buffer_t *hostname, struct addrinfo **addr); ret_t cherokee_gethostname (cherokee_buffer_t *buf); ret_t cherokee_syslog (int priority, cherokee_buffer_t *buf);