Core: keep the length of the local sockaddr.

This commit is contained in:
Ruslan Ermilov 2013-12-09 10:14:51 +04:00
parent 19f475276d
commit 675e73e3bd
4 changed files with 11 additions and 5 deletions

View File

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

View File

@ -143,6 +143,7 @@ struct ngx_connection_s {
#endif
struct sockaddr *local_sockaddr;
socklen_t local_socklen;
ngx_buf_t *buffer;

View File

@ -212,6 +212,7 @@ ngx_event_accept(ngx_event_t *ev)
c->socklen = socklen;
c->listening = ls;
c->local_sockaddr = ls->sockaddr;
c->local_socklen = ls->socklen;
c->unexpected_eof = 1;

View File

@ -18,7 +18,6 @@ ngx_event_acceptex(ngx_event_t *rev)
{
ngx_listening_t *ls;
ngx_connection_t *c;
socklen_t len;
c = rev->data;
ls = c->listening;
@ -50,7 +49,7 @@ ngx_event_acceptex(ngx_event_t *rev)
ls->post_accept_buffer_size,
ls->socklen + 16,
ls->socklen + 16,
&c->local_sockaddr, &len,
&c->local_sockaddr, &c->local_socklen,
&c->sockaddr, &c->socklen);
if (ls->post_accept_buffer_size) {