comparison src/core/ngx_connection.c @ 501:98143f74eb3d NGINX_0_7_58

nginx 0.7.58 *) Feature: a "listen" directive of the mail proxy module supports IPv6. *) Feature: the "image_filter_jpeg_quality" directive. *) Feature: the "client_body_in_single_buffer" directive. *) Feature: the $request_body variable. *) Bugfix: in ngx_http_autoindex_module in file name links having a ":" symbol in the name. *) Bugfix: "make upgrade" procedure did not work; the bug had appeared in 0.7.53. Thanks to Denis F. Latypoff.
author Igor Sysoev <http://sysoev.ru>
date Mon, 18 May 2009 00:00:00 +0400
parents 6484cbba0222
children 207ae3ff0444
comparison
equal deleted inserted replaced
500:bb2281a3edb6 501:98143f74eb3d
809 } 809 }
810 } 810 }
811 811
812 812
813 ngx_int_t 813 ngx_int_t
814 ngx_connection_local_sockaddr(ngx_connection_t *c, ngx_str_t *s,
815 ngx_uint_t port)
816 {
817 socklen_t len;
818 ngx_uint_t addr;
819 u_char sa[NGX_SOCKADDRLEN];
820 struct sockaddr_in *sin;
821 #if (NGX_HAVE_INET6)
822 ngx_uint_t i;
823 struct sockaddr_in6 *sin6;
824 #endif
825
826 switch (c->local_sockaddr->sa_family) {
827
828 #if (NGX_HAVE_INET6)
829 case AF_INET6:
830 sin6 = (struct sockaddr_in6 *) c->local_sockaddr;
831
832 for (addr = 0, i = 0; addr == 0 && i < 16; i++) {
833 addr |= sin6->sin6_addr.s6_addr[i];
834 }
835
836 break;
837 #endif
838
839 default: /* AF_INET */
840 sin = (struct sockaddr_in *) c->local_sockaddr;
841 addr = sin->sin_addr.s_addr;
842 break;
843 }
844
845 if (addr == 0) {
846
847 len = NGX_SOCKADDRLEN;
848
849 if (getsockname(c->fd, (struct sockaddr *) &sa, &len) == -1) {
850 ngx_connection_error(c, ngx_socket_errno, "getsockname() failed");
851 return NGX_ERROR;
852 }
853
854 c->local_sockaddr = ngx_palloc(c->pool, len);
855 if (c->local_sockaddr == NULL) {
856 return NGX_ERROR;
857 }
858
859 c->local_socklen = len;
860 ngx_memcpy(c->local_sockaddr, &sa, len);
861 }
862
863 if (s == NULL) {
864 return NGX_OK;
865 }
866
867 s->len = ngx_sock_ntop(c->local_sockaddr, s->data, s->len, port);
868
869 return NGX_OK;
870 }
871
872
873 ngx_int_t
814 ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text) 874 ngx_connection_error(ngx_connection_t *c, ngx_err_t err, char *text)
815 { 875 {
816 ngx_uint_t level; 876 ngx_uint_t level;
817 877
818 /* Winsock may return NGX_ECONNABORTED instead of NGX_ECONNRESET */ 878 /* Winsock may return NGX_ECONNABORTED instead of NGX_ECONNRESET */