Permalink
Browse files

The first parameter (char *) of cherokee_gethostbyname() function

has been replace by a much convenient cherokee_buffer_t* one.

git-svn-id: svn://cherokee-project.com/cherokee/trunk@6886 5dc97367-97f1-0310-9951-d761b3857238
  • Loading branch information...
1 parent 231252b commit 41827178bd5edd0ff043f66b44961be3fac223f0 @alobbs alobbs committed Oct 7, 2011
Showing with 21 additions and 10 deletions.
  1. +1 −1 cherokee/resolv_cache.c
  2. +19 −8 cherokee/util.c
  3. +1 −1 cherokee/util.h
View
2 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;
View
27 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,21 +768,32 @@ 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;
}
#endif
/* Resolve address
*/
- n = getaddrinfo (hostname, NULL, &hints, addr);
+ n = getaddrinfo (hostname->buf, NULL, &hints, addr);
if (n < 0) {
return ret_error;
}
View
2 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);

0 comments on commit 4182717

Please sign in to comment.