Mailing List Archive

[6886] cherokee/trunk/cherokee: The first parameter (char *) of cherokee_gethostbyname() function
Revision: 6886
http://svn.cherokee-project.com/changeset/6886
Author: alo
Date: 2011-10-07 10:20:17 +0200 (Fri, 07 Oct 2011)
Log Message:
-----------
The first parameter (char *) of cherokee_gethostbyname() function
has been replace by a much convenient cherokee_buffer_t* one.

Modified Paths:
--------------
cherokee/trunk/cherokee/resolv_cache.c
cherokee/trunk/cherokee/util.c
cherokee/trunk/cherokee/util.h

Modified: cherokee/trunk/cherokee/resolv_cache.c
===================================================================
--- cherokee/trunk/cherokee/resolv_cache.c 2011-10-06 20:46:57 UTC (rev 6885)
+++ cherokee/trunk/cherokee/resolv_cache.c 2011-10-07 08:20:17 UTC (rev 6886)
@@ -97,7 +97,7 @@
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;


Modified: cherokee/trunk/cherokee/util.c
===================================================================
--- cherokee/trunk/cherokee/util.c 2011-10-06 20:46:57 UTC (rev 6885)
+++ cherokee/trunk/cherokee/util.c 2011-10-07 08:20:17 UTC (rev 6886)
@@ -757,7 +757,7 @@


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 @@

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 @@

/* Resolve address
*/
- n = getaddrinfo (hostname, NULL, &hints, addr);
+ n = getaddrinfo (hostname->buf, NULL, &hints, addr);
if (n < 0) {
return ret_error;
}

Modified: cherokee/trunk/cherokee/util.h
===================================================================
--- cherokee/trunk/cherokee/util.h 2011-10-06 20:46:57 UTC (rev 6885)
+++ cherokee/trunk/cherokee/util.h 2011-10-07 08:20:17 UTC (rev 6886)
@@ -161,7 +161,7 @@
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);