[nginx] Core: make ngx_connection_local_sockaddr() always assign...

Roman Arutyunyan arut at nginx.com
Tue Feb 17 11:31:52 UTC 2015


details:   http://hg.nginx.org/nginx/rev/69c4912066a4
branches:  
changeset: 5983:69c4912066a4
user:      Roman Arutyunyan <arut at nginx.com>
date:      Tue Feb 17 14:26:44 2015 +0300
description:
Core: make ngx_connection_local_sockaddr() always assign address.

Previously, this function checked for connection local address existence
and returned error if it was missing.  Now a new address is assigned in this
case making it possible to call this function not only for accepted connections.

diffstat:

 src/core/ngx_connection.c |  34 +++++++++++++++++-----------------
 1 files changed, 17 insertions(+), 17 deletions(-)

diffs (54 lines):

diff -r f3f25ad09dee -r 69c4912066a4 src/core/ngx_connection.c
--- a/src/core/ngx_connection.c	Wed Feb 11 20:18:55 2015 +0300
+++ b/src/core/ngx_connection.c	Tue Feb 17 14:26:44 2015 +0300
@@ -1073,33 +1073,33 @@ ngx_connection_local_sockaddr(ngx_connec
     struct sockaddr_in6  *sin6;
 #endif
 
-    if (c->local_socklen == 0) {
-        return NGX_ERROR;
-    }
+    addr = 0;
 
-    switch (c->local_sockaddr->sa_family) {
+    if (c->local_socklen) {
+        switch (c->local_sockaddr->sa_family) {
 
 #if (NGX_HAVE_INET6)
-    case AF_INET6:
-        sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
+        case AF_INET6:
+            sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
 
-        for (addr = 0, i = 0; addr == 0 && i < 16; i++) {
-            addr |= sin6->sin6_addr.s6_addr[i];
-        }
+            for (i = 0; addr == 0 && i < 16; i++) {
+                addr |= sin6->sin6_addr.s6_addr[i];
+            }
 
-        break;
+            break;
 #endif
 
 #if (NGX_HAVE_UNIX_DOMAIN)
-    case AF_UNIX:
-        addr = 1;
-        break;
+        case AF_UNIX:
+            addr = 1;
+            break;
 #endif
 
-    default: /* AF_INET */
-        sin = (struct sockaddr_in *) c->local_sockaddr;
-        addr = sin->sin_addr.s_addr;
-        break;
+        default: /* AF_INET */
+            sin = (struct sockaddr_in *) c->local_sockaddr;
+            addr = sin->sin_addr.s_addr;
+            break;
+        }
     }
 
     if (addr == 0) {



More information about the nginx-devel mailing list