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.
This commit is contained in:
Roman Arutyunyan 2015-02-17 14:26:44 +03:00
parent 7f3f7fec77
commit 6337c1d185

View File

@ -1073,17 +1073,16 @@ ngx_connection_local_sockaddr(ngx_connection_t *c, ngx_str_t *s,
struct sockaddr_in6 *sin6; struct sockaddr_in6 *sin6;
#endif #endif
if (c->local_socklen == 0) { addr = 0;
return NGX_ERROR;
}
if (c->local_socklen) {
switch (c->local_sockaddr->sa_family) { switch (c->local_sockaddr->sa_family) {
#if (NGX_HAVE_INET6) #if (NGX_HAVE_INET6)
case AF_INET6: case AF_INET6:
sin6 = (struct sockaddr_in6 *) c->local_sockaddr; sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
for (addr = 0, i = 0; addr == 0 && i < 16; i++) { for (i = 0; addr == 0 && i < 16; i++) {
addr |= sin6->sin6_addr.s6_addr[i]; addr |= sin6->sin6_addr.s6_addr[i];
} }
@ -1101,6 +1100,7 @@ ngx_connection_local_sockaddr(ngx_connection_t *c, ngx_str_t *s,
addr = sin->sin_addr.s_addr; addr = sin->sin_addr.s_addr;
break; break;
} }
}
if (addr == 0) { if (addr == 0) {