[nginx] Core: keep the length of the local sockaddr.
Ruslan Ermilov
ru at nginx.com
Mon Dec 9 06:17:55 UTC 2013
details: http://hg.nginx.org/nginx/rev/1ab1cf63f885
branches:
changeset: 5463:1ab1cf63f885
user: Ruslan Ermilov <ru at nginx.com>
date: Mon Dec 09 10:14:51 2013 +0400
description:
Core: keep the length of the local sockaddr.
diffstat:
src/core/ngx_connection.c | 11 ++++++++---
src/core/ngx_connection.h | 1 +
src/event/ngx_event_accept.c | 1 +
src/event/ngx_event_acceptex.c | 3 +--
4 files changed, 11 insertions(+), 5 deletions(-)
diffs (88 lines):
diff -r 58716fd3bd2d -r 1ab1cf63f885 src/core/ngx_connection.c
--- a/src/core/ngx_connection.c Fri Dec 06 16:00:49 2013 -0800
+++ b/src/core/ngx_connection.c Mon Dec 09 10:14:51 2013 +0400
@@ -1078,12 +1078,15 @@ ngx_connection_local_sockaddr(ngx_connec
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_connec
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_connec
}
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;
}
diff -r 58716fd3bd2d -r 1ab1cf63f885 src/core/ngx_connection.h
--- a/src/core/ngx_connection.h Fri Dec 06 16:00:49 2013 -0800
+++ b/src/core/ngx_connection.h Mon Dec 09 10:14:51 2013 +0400
@@ -143,6 +143,7 @@ struct ngx_connection_s {
#endif
struct sockaddr *local_sockaddr;
+ socklen_t local_socklen;
ngx_buf_t *buffer;
diff -r 58716fd3bd2d -r 1ab1cf63f885 src/event/ngx_event_accept.c
--- a/src/event/ngx_event_accept.c Fri Dec 06 16:00:49 2013 -0800
+++ b/src/event/ngx_event_accept.c Mon Dec 09 10:14:51 2013 +0400
@@ -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;
diff -r 58716fd3bd2d -r 1ab1cf63f885 src/event/ngx_event_acceptex.c
--- a/src/event/ngx_event_acceptex.c Fri Dec 06 16:00:49 2013 -0800
+++ b/src/event/ngx_event_acceptex.c Mon Dec 09 10:14:51 2013 +0400
@@ -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) {
More information about the nginx-devel
mailing list