Mercurial > hg > nginx-quic
comparison 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 |
comparison
equal
deleted
inserted
replaced
2856:f9b5dfcc96d8 | 2857:507fc5ac9839 |
---|---|
1821 | 1821 |
1822 r->headers_in.user.len = len; | 1822 r->headers_in.user.len = len; |
1823 r->headers_in.user.data = auth.data; | 1823 r->headers_in.user.data = auth.data; |
1824 r->headers_in.passwd.len = auth.len - len - 1; | 1824 r->headers_in.passwd.len = auth.len - len - 1; |
1825 r->headers_in.passwd.data = &auth.data[len + 1]; | 1825 r->headers_in.passwd.data = &auth.data[len + 1]; |
1826 | |
1827 return NGX_OK; | |
1828 } | |
1829 | |
1830 | |
1831 ngx_int_t | |
1832 ngx_http_server_addr(ngx_http_request_t *r, ngx_str_t *s) | |
1833 { | |
1834 socklen_t len; | |
1835 ngx_uint_t addr; | |
1836 ngx_connection_t *c; | |
1837 u_char sa[NGX_SOCKADDRLEN]; | |
1838 struct sockaddr_in *sin; | |
1839 #if (NGX_HAVE_INET6) | |
1840 ngx_uint_t i; | |
1841 struct sockaddr_in6 *sin6; | |
1842 #endif | |
1843 | |
1844 c = r->connection; | |
1845 | |
1846 switch (c->local_sockaddr->sa_family) { | |
1847 | |
1848 #if (NGX_HAVE_INET6) | |
1849 case AF_INET6: | |
1850 sin6 = (struct sockaddr_in6 *) c->local_sockaddr; | |
1851 | |
1852 for (addr = 0, i = 0; addr == 0 && i < 16; i++) { | |
1853 addr |= sin6->sin6_addr.s6_addr[i]; | |
1854 } | |
1855 | |
1856 break; | |
1857 #endif | |
1858 | |
1859 default: /* AF_INET */ | |
1860 sin = (struct sockaddr_in *) c->local_sockaddr; | |
1861 addr = sin->sin_addr.s_addr; | |
1862 break; | |
1863 } | |
1864 | |
1865 if (addr == 0) { | |
1866 | |
1867 len = NGX_SOCKADDRLEN; | |
1868 | |
1869 if (getsockname(c->fd, (struct sockaddr *) &sa, &len) == -1) { | |
1870 ngx_connection_error(c, ngx_socket_errno, "getsockname() failed"); | |
1871 return NGX_ERROR; | |
1872 } | |
1873 | |
1874 c->local_sockaddr = ngx_palloc(r->connection->pool, len); | |
1875 if (c->local_sockaddr == NULL) { | |
1876 return NGX_ERROR; | |
1877 } | |
1878 | |
1879 c->local_socklen = len; | |
1880 ngx_memcpy(c->local_sockaddr, &sa, len); | |
1881 } | |
1882 | |
1883 if (s == NULL) { | |
1884 return NGX_OK; | |
1885 } | |
1886 | |
1887 s->len = ngx_sock_ntop(c->local_sockaddr, s->data, s->len, 0); | |
1888 | 1826 |
1889 return NGX_OK; | 1827 return NGX_OK; |
1890 } | 1828 } |
1891 | 1829 |
1892 | 1830 |