Mercurial > hg > nginx
diff src/http/ngx_http_core_module.c @ 2857:507fc5ac9839
use ngx_connection_local_sockaddr() instead of ngx_http_server_addr()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Mon, 18 May 2009 12:58:19 +0000 |
parents | 10d6b9950453 |
children | 13b63d682228 |
line wrap: on
line diff
--- a/src/http/ngx_http_core_module.c +++ b/src/http/ngx_http_core_module.c @@ -1828,68 +1828,6 @@ ngx_http_auth_basic_user(ngx_http_reques } -ngx_int_t -ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s) -{ - socklen_t len; - ngx_uint_t addr; - ngx_connection_t *c; - u_char sa[NGX_SOCKADDRLEN]; - struct sockaddr_in *sin; -#if (NGX_HAVE_INET6) - ngx_uint_t i; - struct sockaddr_in6 *sin6; -#endif - - c = r->connection; - - switch (c->local_sockaddr->sa_family) { - -#if (NGX_HAVE_INET6) - 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]; - } - - break; -#endif - - default: /* AF_INET */ - sin = (struct sockaddr_in *) c->local_sockaddr; - addr = sin->sin_addr.s_addr; - break; - } - - if (addr == 0) { - - len = NGX_SOCKADDRLEN; - - if (getsockname(c->fd, (struct sockaddr *) &sa, &len) == -1) { - ngx_connection_error(c, ngx_socket_errno, "getsockname() failed"); - return NGX_ERROR; - } - - c->local_sockaddr = ngx_palloc(r->connection->pool, len); - if (c->local_sockaddr == NULL) { - return NGX_ERROR; - } - - c->local_socklen = len; - ngx_memcpy(c->local_sockaddr, &sa, len); - } - - if (s == NULL) { - return NGX_OK; - } - - s->len = ngx_sock_ntop(c->local_sockaddr, s->data, s->len, 0); - - return NGX_OK; -} - - #if (NGX_HTTP_GZIP) ngx_int_t