diff src/http/modules/ngx_http_upstream_ip_hash_module.c @ 448:76a79816b771 NGINX_0_7_36

nginx 0.7.36 *) Feature: a preliminary IPv6 support; the "listen" directive of the HTTP module supports IPv6. *) Bugfix: the $ancient_browser variable did not work for browsers preset by a "modern_browser" directives.
author Igor Sysoev <http://sysoev.ru>
date Sat, 21 Feb 2009 00:00:00 +0300
parents 5e3b425174f6
children 6f21ae02fb01
line wrap: on
line diff
--- a/src/http/modules/ngx_http_upstream_ip_hash_module.c
+++ b/src/http/modules/ngx_http_upstream_ip_hash_module.c
@@ -15,7 +15,6 @@ typedef struct {
 
     ngx_uint_t                         hash;
 
-    /* AF_INET only */
     u_char                             addr[3];
 
     u_char                             tries;
@@ -111,11 +110,20 @@ ngx_http_upstream_init_ip_hash_peer(ngx_
     r->upstream->peer.get = ngx_http_upstream_get_ip_hash_peer;
 
     /* AF_INET only */
-    sin = (struct sockaddr_in *) r->connection->sockaddr;
-    p = (u_char *) &sin->sin_addr.s_addr;
-    iphp->addr[0] = p[0];
-    iphp->addr[1] = p[1];
-    iphp->addr[2] = p[2];
+
+    if (r->connection->sockaddr->sa_family == AF_INET) {
+
+        sin = (struct sockaddr_in *) r->connection->sockaddr;
+        p = (u_char *) &sin->sin_addr.s_addr;
+        iphp->addr[0] = p[0];
+        iphp->addr[1] = p[1];
+        iphp->addr[2] = p[2];
+
+    } else {
+        iphp->addr[0] = 0;
+        iphp->addr[1] = 0;
+        iphp->addr[2] = 0;
+    }
 
     iphp->hash = 89;
     iphp->tries = 0;