diff options
author | Ruslan Ermilov <ru@nginx.com> | 2013-12-09 10:14:51 +0400 |
---|---|---|
committer | Ruslan Ermilov <ru@nginx.com> | 2013-12-09 10:14:51 +0400 |
commit | 675e73e3bd70af7780ed8c9dde47d2d28a8a9f56 (patch) | |
tree | e16f0fd02dff4d1b9acc33cec5a2a9cb188fdb4c /src/core/ngx_connection.c | |
parent | 19f475276de07e8c72ab4acca56c36ea4afb6572 (diff) |
Core: keep the length of the local sockaddr.
Diffstat (limited to 'src/core/ngx_connection.c')
-rw-r--r-- | src/core/ngx_connection.c | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/src/core/ngx_connection.c b/src/core/ngx_connection.c index 4544b294a..4d73eb3e0 100644 --- a/src/core/ngx_connection.c +++ b/src/core/ngx_connection.c @@ -1078,12 +1078,15 @@ ngx_connection_local_sockaddr(ngx_connection_t *c, ngx_str_t *s, struct sockaddr_in6 *sin6; #endif + if (c->local_socklen == 0) { + return NGX_ERROR; + } + switch (c->local_sockaddr->sa_family) { #if (NGX_HAVE_INET6) case AF_INET6: sin6 = (struct sockaddr_in6 *) c->local_sockaddr; - len = sizeof(struct sockaddr_in6); for (addr = 0, i = 0; addr == 0 && i < 16; i++) { addr |= sin6->sin6_addr.s6_addr[i]; @@ -1094,7 +1097,6 @@ ngx_connection_local_sockaddr(ngx_connection_t *c, ngx_str_t *s, default: /* AF_INET */ sin = (struct sockaddr_in *) c->local_sockaddr; - len = sizeof(struct sockaddr_in); addr = sin->sin_addr.s_addr; break; } @@ -1114,13 +1116,16 @@ ngx_connection_local_sockaddr(ngx_connection_t *c, ngx_str_t *s, } ngx_memcpy(c->local_sockaddr, &sa, len); + + c->local_socklen = len; } if (s == NULL) { return NGX_OK; } - s->len = ngx_sock_ntop(c->local_sockaddr, len, s->data, s->len, port); + s->len = ngx_sock_ntop(c->local_sockaddr, c->local_socklen, + s->data, s->len, port); return NGX_OK; } |