<html><head><style type='text/css'>p { margin: 0; }</style></head><body><div style='font-family: Times New Roman; font-size: 12pt; color: #000000'><span style="font-family: 'Times New Roman'; font-size: 12pt; "><meta charset="utf-8"><span class="Apple-style-span" style="font-family: Arial; font-size: medium; ">Hey, guys. I've implement a parse URL to IPv6 function which is discussed in "http://forum.nginx.org/read.php?2,177146,177190". I change "ngx_parse_url" and add an function "ngx_parse_host" to resolve a host (IP or text) to either IPv4 or IPv6 functions. And I change "ngx_inet_resolve_host" to let it accept IPv4/IPv6. Besides I add another function "ngx_inet_sock_addr" to parse string with format "ipv4:port" and "[ipv6]:port" to the addr structure. Seems I can't upload the attachment so I past them here. I've do the unit test to them. Hope you can take regression test and merge them to the nginx main branch.<br style="clear: both; "><br style="clear: both; ">If u wish, 
 I can also past the unit test I write. The change is a big one so I recommend directly submit a source code. But as convention, here is the diff:</span></span><div><font class="Apple-style-span" face="Arial"><br></font></div><div><font class="Apple-style-span" face="Arial">===============ngx_inet.c=====================<br></font><div><span id="c36bdcf5-53de-4e6c-8964-8cfc63e6a230"><font class="Apple-style-span" face="Arial"><div>12,13c12</div><div>&lt; static ngx_int_t ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u);</div><div>&lt; static ngx_int_t ngx_parse_inet6_url(ngx_pool_t *pool, ngx_url_t *u);</div><div>---</div><div>&gt; static ngx_int_t ngx_parse_host(ngx_pool_t *pool, ngx_url_t *u);</div><div>449d447</div><div>&lt;&nbsp;</div><div>509d506</div><div>&lt;&nbsp;</div><div>513c510,518</div><div>&lt; &nbsp; &nbsp; u_char &nbsp;*p;</div><div>---</div><div>&gt; &nbsp; &nbsp; u_char &nbsp; *p, *host, *port, *last, *uri, *args;</div><div>&gt; &nbsp; &nbsp; size_t &nbsp; 
 &nbsp;len;</div><div>&gt; &nbsp; &nbsp; ngx_int_t n;</div><div>&gt; &nbsp; &nbsp; struct sockaddr_in &nbsp;*sin;</div><div>&gt;&nbsp;</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp; struct sockaddr_in6 *sin6;</div><div>&gt; &nbsp; &nbsp; ngx_flag_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ipv6 = 0;</div><div>&gt; #endif</div><div>526,528c531</div><div>&lt; &nbsp; &nbsp; if (p[0] == '[') {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; return ngx_parse_inet6_url(pool, u);</div><div>&lt; &nbsp; &nbsp; }</div><div>---</div><div>&gt; &nbsp; &nbsp; host = u-&gt;url.data;</div><div>530,531c533</div><div>&lt; &nbsp; &nbsp; return ngx_parse_inet_url(pool, u);</div><div>&lt; }</div><div>---</div><div>&gt; &nbsp; &nbsp; last = host + u-&gt;url.len;</div><div>532a535</div><div>&gt; &nbsp; &nbsp; len = 0;</div><div>534,543c537,538</div><div>&lt; static ngx_int_t</div><div>&lt; ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u)</div><div>&lt; {</div><div>&lt; #if (NGX_HAVE_
 UNIX_DOMAIN)</div><div>&lt; &nbsp; &nbsp; u_char &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*path, *uri, *last;</div><div>&lt; &nbsp; &nbsp; size_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len;</div><div>&lt; &nbsp; &nbsp; struct sockaddr_un &nbsp;*saun;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; len = u-&gt;url.len;</div><div>&lt; &nbsp; &nbsp; path = u-&gt;url.data;</div><div>---</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp; if (host[0] == '[') {</div><div>545,546c540</div><div>&lt; &nbsp; &nbsp; path += 5;</div><div>&lt; &nbsp; &nbsp; len -= 5;</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; ipv6 = 1;</div><div>548c542</div><div>&lt; &nbsp; &nbsp; if (u-&gt;uri_part) {</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; host = u-&gt;url.data + 1;</div><div>550,551c544</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; last = path + len;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; uri = ngx_strlchr(path, last, ':');</div><div>---
 </div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; p = ngx_strlchr(host, last, ']');</div><div>553,557c546,548</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (uri) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len = uri - path;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uri++;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;uri.len = last - uri;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;uri.data = uri;</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (p == NULL) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "invalid host";</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>559,577d549</div><div>&lt; &nbsp; &nbsp; }</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; if (len == 0) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "no path in the unix domain socket";</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&lt; &nbsp; 
 &nbsp; }</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; u-&gt;host.len = len++;</div><div>&lt; &nbsp; &nbsp; u-&gt;host.data = path;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; if (len &gt; sizeof(saun-&gt;sun_path)) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "too long path in the unix domain socket";</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&lt; &nbsp; &nbsp; }</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; u-&gt;socklen = sizeof(struct sockaddr_un);</div><div>&lt; &nbsp; &nbsp; saun = (struct sockaddr_un *) &amp;u-&gt;sockaddr;</div><div>&lt; &nbsp; &nbsp; saun-&gt;sun_family = AF_UNIX;</div><div>&lt; &nbsp; &nbsp; (void) ngx_cpystrn((u_char *) saun-&gt;sun_path, path, len);</div><div>579,582c551</div><div>&lt; &nbsp; &nbsp; u-&gt;addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t));</div><div>&lt; &nbsp; &nbsp; if (u-&gt;addrs == NULL) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&lt; &nbsp; &nbs
 p; }</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;family = AF_INET6;</div><div>584,586d552</div><div>&lt; &nbsp; &nbsp; saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un));</div><div>&lt; &nbsp; &nbsp; if (saun == NULL) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>588,607d553</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; u-&gt;family = AF_UNIX;</div><div>&lt; &nbsp; &nbsp; u-&gt;naddrs = 1;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; saun-&gt;sun_family = AF_UNIX;</div><div>&lt; &nbsp; &nbsp; (void) ngx_cpystrn((u_char *) saun-&gt;sun_path, path, len);</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; u-&gt;addrs[0].sockaddr = (struct sockaddr *) saun;</div><div>&lt; &nbsp; &nbsp; u-&gt;addrs[0].socklen = sizeof(struct sockaddr_un);</div><div>&lt; &nbsp; &nbsp; u-&gt;addrs[0].name.len = len + 4;</div><div>&lt; &nbsp; &nbsp; u-&gt;addrs[0].name.data = u-&gt;url.data;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; ret
 urn NGX_OK;</div><div>&lt;&nbsp;</div><div>&lt; #else</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; u-&gt;err = "the unix domain sockets are not supported on this platform";</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; return NGX_ERROR;</div><div>&lt;&nbsp;</div><div>609,631d554</div><div>&lt; }</div><div>&lt;&nbsp;</div><div>&lt;&nbsp;</div><div>&lt; static ngx_int_t</div><div>&lt; ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u)</div><div>&lt; {</div><div>&lt; &nbsp; &nbsp; u_char &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*p, *host, *port, *last, *uri, *args;</div><div>&lt; &nbsp; &nbsp; size_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len;</div><div>&lt; &nbsp; &nbsp; ngx_int_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;n;</div><div>&lt; &nbsp; &nbsp; struct hostent &nbsp; &nbsp; &nbsp;*h;</div><div>&lt; &nbsp; &nbsp; struct sockaddr_in &nbsp;*sin;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; u-&gt;socklen = sizeof(struct sockaddr_in);</div><div
 >&lt; &nbsp; &nbsp; sin = (struct sockaddr_in *) &amp;u-&gt;sockaddr;</div><div>&lt; &nbsp; &nbsp; sin-&gt;sin_family = AF_INET;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; u-&gt;family = AF_INET;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; host = u-&gt;url.data;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; last = host + u-&gt;url.len;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; port = ngx_strlchr(host, last, ':');</div><div>633c556</div><div>&lt; &nbsp; &nbsp; uri = ngx_strlchr(host, last, '/');</div><div>---</div><div>&gt; &nbsp; &nbsp; port = ngx_strlchr(p, last, ':');</div><div>635c558</div><div>&lt; &nbsp; &nbsp; args = ngx_strlchr(host, last, '?');</div><div>---</div><div>&gt; &nbsp; &nbsp; uri = ngx_strlchr(p, last, '/');</div><div>637,639c560</div><div>&lt; &nbsp; &nbsp; if (args) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (uri == NULL) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uri = args;</div><div>---</div><div>&gt; &nbs
 p; &nbsp; args = ngx_strlchr(p, last, '?');</div><div>641,643c562,563</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; } else if (args &lt; uri) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uri = args;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>---</div><div>&gt; &nbsp; &nbsp; if (args &amp;&amp; (uri == NULL || args &lt; uri)) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; uri = args;</div><div>648c568</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "invalid host";</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "invalid url to listen";</div><div>680,681d599</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_port = htons((in_port_t) n);</div><div>&lt;&nbsp;</div><div>688,692c606,607</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (uri == NULL) {</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (u-&gt;listen) {</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &
 nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* test value as port only */</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (uri == NULL &amp;&amp; u-&gt;listen) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; /* test value as port only */</div><div>694c609</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n = ngx_atoi(host, last - host);</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n = ngx_atoi(u-&gt;url.data, u-&gt;url.len);</div><div>696,704c611,614</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (n != NGX_ERROR) {</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (n &lt; 1 || n &gt; 65536) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "invalid port";</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;
 </div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;port = (in_port_t) n;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_port = htons((in_port_t) n);</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (n &lt; 1 || n &gt; 65536) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "invalid port";</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>706,707c616,625</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;port_text.len = last - host;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;port_text.data = host;</div><div>---</div><div>&gt; &n
 bsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;family = AF_INET;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;port = (in_port_t) n;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sin = (struct sockaddr_in *)u-&gt;sockaddr;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_family = AF_INET;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_addr.s_addr = INADDR_ANY;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_port = htons((in_port_t) n);</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;port_text.len = len;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;port_text.data = port;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;socklen = sizeof (struct sockaddr_in);</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;wildcard = 1;</div><div>709c627</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;w
 ildcard = 1;</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_OK;</div><div>711,713c629,630</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_OK;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; } else {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;no_port = 1;</div><div>714a632</div><div>&gt; &nbsp; &nbsp; }</div><div>716c634,641</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;no_port = 1;</div><div>---</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp; if (ipv6) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (*(last - 1) == ']' &amp;&amp; last &gt; host) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; last--;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; } else {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbs
 p; u-&gt;err = "invalid host";</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>717a643</div><div>&gt; #endif</div><div>721,725d646</div><div>&lt; &nbsp; &nbsp; if (len == 0) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "no host";</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&lt; &nbsp; &nbsp; }</div><div>&lt;&nbsp;</div><div>727a649,654</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;family = AF_INET;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;socklen = sizeof (struct sockaddr_in);</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;wildcard = 1;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin = (struct sockaddr_in *)u-&gt;sockaddr;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_family = AF_INET;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_addr.s_addr = INADDR_ANY;</div><div>737,766c664,666</div><div>&lt; &nbsp; &nbsp; if (len) {</div>
 <div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_addr.s_addr = ngx_inet_addr(host, len);</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (sin-&gt;sin_addr.s_addr == INADDR_NONE) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p = ngx_alloc(++len, pool-&gt;log);</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (p == NULL) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; (void) ngx_cpystrn(p, host, len);</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; h = gethostbyname((const char *) p);</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ngx_free(p);</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (h == NULL || h-&gt;h_addr_list[0] == NULL) {</div><div>&lt; &nbsp; &nbsp; 
 &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "host not found";</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_addr.s_addr = *(in_addr_t *) (h-&gt;h_addr_list[0]);</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (sin-&gt;sin_addr.s_addr == INADDR_ANY) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;wildcard = 1;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; } else {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_addr.s_addr = INADDR_ANY;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;wildcard = 1;</div><div>---</div><div>&gt; &nbsp; &nbsp; if(u-&gt;host.len &gt; 0 &amp;&amp; ngx_parse_host(pool, u) == NGX_ERROR) {</div><div>&gt; &nbsp; &nbsp;
  &nbsp; &nbsp; u-&gt;err = "invalid host";</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>771c671,683</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_port = htons(u-&gt;default_port);</div><div>---</div><div>&gt; &nbsp; &nbsp; }</div><div>&gt;&nbsp;</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp; if (u-&gt;family == AF_INET6) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin6 = (struct sockaddr_in6 *)u-&gt;sockaddr;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin6-&gt;sin6_port = htons (u-&gt;port);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; }</div><div>&gt; &nbsp; &nbsp; else</div><div>&gt; #endif</div><div>&gt; &nbsp; &nbsp; {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin = (struct sockaddr_in *)u-&gt;sockaddr;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_port = htons (u-&gt;port);</div><div>787c699</div><div>&lt; ngx_parse_inet6_url(ngx_pool_t *pool, ngx_url_t *u)</div><div>---</div><div>&gt; ngx_parse_unix_d
 omain_url(ngx_pool_t *pool, ngx_url_t *u)</div><div>789,803c701,704</div><div>&lt; #if (NGX_HAVE_INET6)</div><div>&lt; &nbsp; &nbsp; u_char &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *p, *host, *port, *last, *uri;</div><div>&lt; &nbsp; &nbsp; size_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;len;</div><div>&lt; &nbsp; &nbsp; ngx_int_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n;</div><div>&lt; &nbsp; &nbsp; struct sockaddr_in6 &nbsp;*sin6;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; u-&gt;socklen = sizeof(struct sockaddr_in6);</div><div>&lt; &nbsp; &nbsp; sin6 = (struct sockaddr_in6 *) &amp;u-&gt;sockaddr;</div><div>&lt; &nbsp; &nbsp; sin6-&gt;sin6_family = AF_INET6;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; host = u-&gt;url.data + 1;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; last = u-&gt;url.data + u-&gt;url.len;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; p = ngx_strlchr(host, last, ']');</div><div>---</div><div>&gt; #if (NGX_H
 AVE_UNIX_DOMAIN)</div><div>&gt; &nbsp; &nbsp; u_char &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*path, *uri, *last;</div><div>&gt; &nbsp; &nbsp; size_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len;</div><div>&gt; &nbsp; &nbsp; struct sockaddr_un &nbsp;*saun;</div><div>805,808c706,707</div><div>&lt; &nbsp; &nbsp; if (p == NULL) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "invalid host";</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&lt; &nbsp; &nbsp; }</div><div>---</div><div>&gt; &nbsp; &nbsp; len = u-&gt;url.len;</div><div>&gt; &nbsp; &nbsp; path = u-&gt;url.data;</div><div>810c709,710</div><div>&lt; &nbsp; &nbsp; if (last - p) {</div><div>---</div><div>&gt; &nbsp; &nbsp; path += 5;</div><div>&gt; &nbsp; &nbsp; len -= 5;</div><div>812c712</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; port = p + 1;</div><div>---</div><div>&gt; &nbsp; &nbsp; if (u-&gt;uri_part) {</div><div>814c714,715</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u
 ri = ngx_strlchr(port, last, '/');</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; last = path + len;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; uri = ngx_strlchr(path, last, ':');</div><div>817,821c718,719</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (u-&gt;listen || !u-&gt;uri_part) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "invalid host";</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&lt;&nbsp;</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len = uri - path;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; uri++;</div><div>824a723</div><div>&gt; &nbsp; &nbsp; }</div><div>826,851c725,727</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (*port == ':') {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; port++;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nb
 sp; &nbsp; &nbsp; &nbsp; len = last - port;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (len == 0) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "invalid port";</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n = ngx_atoi(port, len);</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (n &lt; 1 || n &gt; 65536) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "invalid port";</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;port = (in_port_t) n;</div><div>&lt; &nbsp; &nbsp; &nbsp; &n
 bsp; &nbsp; &nbsp; sin6-&gt;sin6_port = htons((in_port_t) n);</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;port_text.len = len;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;port_text.data = port;</div><div>&lt;&nbsp;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; } else {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;no_port = 1;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>---</div><div>&gt; &nbsp; &nbsp; if (len == 0) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "no path in the unix domain socket";</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>854c730,731</div><div>&lt; &nbsp; &nbsp; len = p - host;</div><div>---</div><div>&gt; &nbsp; &nbsp; u-&gt;host.len = len++;</div><div>&gt; &nbsp; &nbsp; u-&gt;host.data = path;</div><div>856,857c733,734</div><div>&lt; &nbsp; &nbsp; if (len == 0) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "no host";</div><
 div>---</div><div>&gt; &nbsp; &nbsp; if (len &gt; sizeof(saun-&gt;sun_path)) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "too long path in the unix domain socket";</div><div>861,862c738,741</div><div>&lt; &nbsp; &nbsp; u-&gt;host.len = len;</div><div>&lt; &nbsp; &nbsp; u-&gt;host.data = host;</div><div>---</div><div>&gt; &nbsp; &nbsp; u-&gt;socklen = sizeof(struct sockaddr_un);</div><div>&gt; &nbsp; &nbsp; saun = (struct sockaddr_un *) &amp;u-&gt;sockaddr;</div><div>&gt; &nbsp; &nbsp; saun-&gt;sun_family = AF_UNIX;</div><div>&gt; &nbsp; &nbsp; (void) ngx_cpystrn((u_char *) saun-&gt;sun_path, path, len);</div><div>864,865c743,744</div><div>&lt; &nbsp; &nbsp; if (ngx_inet6_addr(host, len, sin6-&gt;sin6_addr.s6_addr) != NGX_OK) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "invalid IPv6 address";</div><div>---</div><div>&gt; &nbsp; &nbsp; u-&gt;addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t));</div><div>&gt; &nbsp; &nbsp; if (u-&gt;addrs == NULL) {</div><di
 v>869,870c748,750</div><div>&lt; &nbsp; &nbsp; if (IN6_IS_ADDR_UNSPECIFIED(&amp;sin6-&gt;sin6_addr)) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;wildcard = 1;</div><div>---</div><div>&gt; &nbsp; &nbsp; saun = ngx_pcalloc(pool, sizeof(struct sockaddr_un));</div><div>&gt; &nbsp; &nbsp; if (saun == NULL) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>873c753,754</div><div>&lt; &nbsp; &nbsp; u-&gt;family = AF_INET6;</div><div>---</div><div>&gt; &nbsp; &nbsp; u-&gt;family = AF_UNIX;</div><div>&gt; &nbsp; &nbsp; u-&gt;naddrs = 1;</div><div>875,877c756,757</div><div>&lt; &nbsp; &nbsp; if (u-&gt;no_resolve) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_OK;</div><div>&lt; &nbsp; &nbsp; }</div><div>---</div><div>&gt; &nbsp; &nbsp; saun-&gt;sun_family = AF_UNIX;</div><div>&gt; &nbsp; &nbsp; (void) ngx_cpystrn((u_char *) saun-&gt;sun_path, path, len);</div><div>879,882c759,762</div><div>&lt; &nbsp; &nbsp; if (u-&gt;no_port) {</div><div>&lt; &nb
 sp; &nbsp; &nbsp; &nbsp; u-&gt;port = u-&gt;default_port;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; sin6-&gt;sin6_port = htons(u-&gt;default_port);</div><div>&lt; &nbsp; &nbsp; }</div><div>---</div><div>&gt; &nbsp; &nbsp; u-&gt;addrs[0].sockaddr = (struct sockaddr *) saun;</div><div>&gt; &nbsp; &nbsp; u-&gt;addrs[0].socklen = sizeof(struct sockaddr_un);</div><div>&gt; &nbsp; &nbsp; u-&gt;addrs[0].name.len = len + 4;</div><div>&gt; &nbsp; &nbsp; u-&gt;addrs[0].name.data = u-&gt;url.data;</div><div>888c768</div><div>&lt; &nbsp; &nbsp; u-&gt;err = "the INET6 sockets are not supported on this platform";</div><div>---</div><div>&gt; &nbsp; &nbsp; u-&gt;err = "the unix domain sockets are not supported on this platform";</div><div>894a775,891</div><div>&gt; static ngx_int_t</div><div>&gt; ngx_parse_host(ngx_pool_t *pool, ngx_url_t *u) {</div><div>&gt; &nbsp; &nbsp; u_char &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;*p;</div><div>&gt; &nbsp; &nbsp; ngx_uint_t &nbsp; &nbs
 p; &nbsp; &nbsp; &nbsp; &nbsp;family, n;</div><div>&gt; &nbsp; &nbsp; in_addr_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inaddr;</div><div>&gt; &nbsp; &nbsp; struct sockaddr_in &nbsp; *sin;</div><div>&gt; &nbsp; &nbsp; struct addrinfo &nbsp; &nbsp; &nbsp; hints, *addrinfo;</div><div>&gt;&nbsp;</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp; struct in6_addr &nbsp; &nbsp; &nbsp; inaddr6;</div><div>&gt; &nbsp; &nbsp; struct sockaddr_in6 &nbsp;*sin6;</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp;if (u-&gt;family == AF_INET6) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;/* u-&gt;family has been set to AF_INET6 means the host</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; * to be parsed should be IPv6 address so no need to parse</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; * it as IPv4 or resolve host</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; */</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;ngx_memzero(inaddr6.s6_addr, sizeof(struct in6_addr));</div><div>&gt; &nbsp; &nb
 sp; &nbsp; &nbsp;if (ngx_inet6_addr(u-&gt;host.data, u-&gt;host.len, inaddr6.s6_addr) == NGX_OK) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;family = AF_INET6;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;goto done;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;} else {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;u-&gt;err = "invalid host";</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&gt; &nbsp; &nbsp;}</div><div>&gt; #endif</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp;inaddr = ngx_inet_addr(u-&gt;host.data, u-&gt;host.len);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp;if (inaddr != INADDR_NONE) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;family = AF_INET;</div><div>&gt;&nbsp;</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp;} else if (ngx_inet6_addr(u-&gt;host.data, u-&gt;host.len, inaddr6.s6_addr) == NGX_OK) {</div><div>&gt; &nbsp; &nb
 sp; &nbsp; &nbsp;family = AF_INET6;</div><div>&gt;&nbsp;</div><div>&gt; #endif</div><div>&gt; &nbsp; &nbsp;} else {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;/* resolve the IP address through host name</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; only the first IP address will be used &nbsp; */</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;p = ngx_alloc(u-&gt;host.len + 1, pool-&gt;log);</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;if (p == NULL) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;ngx_cpystrn(p, u-&gt;host.data, u-&gt;host.len + 1);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;ngx_memzero (&amp;hints, sizeof (struct addrinfo));</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;if (u-&gt;listen) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hints.ai_flags = AI_PASSIVE;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;} else
  {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;hints.ai_flags = AI_CANONNAME;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;hints.ai_protocol = IPPROTO_TCP;</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;n = getaddrinfo((const char *) p,</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;NULL, &amp;hints, &amp;addrinfo);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;ngx_free (p);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;if (n != NGX_OK) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;u-&gt;err = "error in host resolve";</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;if (addrinfo-&gt;ai_family == AF_INET) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;family = AF_INET;</div><div>
 &gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inaddr = ((struct sockaddr_in *) addrinfo-&gt;ai_addr)-&gt;sin_addr.s_addr;</div><div>&gt;&nbsp;</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;} else if (addrinfo-&gt;ai_family == AF_INET6) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;family = AF_INET6;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inaddr6 = ((struct sockaddr_in6 *) addrinfo-&gt;ai_addr)-&gt;sin6_addr;</div><div>&gt;&nbsp;</div><div>&gt; #endif</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;} else {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;u-&gt;err = "unknown address family";</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&gt; &nbsp; &nbsp;}</div><div>&gt;&nbsp;</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp;done:</div><div>&gt; #endif</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp;switch (family) {<
 /div><div>&gt;&nbsp;</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp;case AF_INET6:</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;sin6 = (struct sockaddr_in6 *) u-&gt;sockaddr;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;sin6-&gt;sin6_family = AF_INET6;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;u-&gt;family = AF_INET6;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;u-&gt;socklen = sizeof (struct sockaddr_in6);</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;ngx_memcpy(sin6-&gt;sin6_addr.s6_addr, inaddr6.s6_addr, 16);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;if (IN6_IS_ADDR_UNSPECIFIED(&amp;sin6-&gt;sin6_addr)) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;u-&gt;wildcard = 1;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div>&gt; #endif</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp;default: /* AF_INET */</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;sin = (struct sockaddr_in *) u-&gt;sockaddr
 ;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;sin-&gt;sin_family = AF_INET;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;u-&gt;family = AF_INET;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;u-&gt;socklen = sizeof (struct sockaddr_in);</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;sin-&gt;sin_addr.s_addr = inaddr;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;if (sin-&gt;sin_addr.s_addr == INADDR_ANY) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;u-&gt;wildcard = 1;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;}</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp;break;</div><div>&gt; &nbsp; &nbsp;}</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp;return NGX_OK;</div><div>&gt; }</div><div>902,904c899,901</div><div>&lt; &nbsp; &nbsp; in_addr_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;in_addr;</div><div>&lt; &nbsp; &nbsp; ngx_uint_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i;</div><div>&lt; &nbsp; &nbsp; struct hostent &nbsp; &nbsp; &nbsp;*h;</div><div>---</div><div>&gt; &nbsp; &nbsp; in_addr_t &nbsp
 ; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;inaddr;</div><div>&gt; &nbsp; &nbsp; ngx_uint_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i, n;</div><div>&gt; &nbsp; &nbsp; struct addrinfo &nbsp; &nbsp; &nbsp;hints, *addrinfo, *item;</div><div>907c904,913</div><div>&lt; &nbsp; &nbsp; /* AF_INET only */</div><div>---</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp; struct in6_addr &nbsp; &nbsp; &nbsp;inaddr6;</div><div>&gt; &nbsp; &nbsp; struct sockaddr_in6 *sin6;</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; /*</div><div>&gt; &nbsp; &nbsp; &nbsp;* prevent MSVC8 waring:</div><div>&gt; &nbsp; &nbsp; &nbsp;* &nbsp; &nbsp;potentially uninitialized local variable 'inaddr6' used</div><div>&gt; &nbsp; &nbsp; &nbsp;*/</div><div>&gt; &nbsp; &nbsp; ngx_memzero(inaddr6.s6_addr, sizeof(struct in6_addr));</div><div>&gt; #endif</div><div>911c917</div><div>&lt; &nbsp; &nbsp; in_addr = ngx_inet_addr(u-&gt;host.data, u-&gt;host.len);</div><div>---</div><div>&gt; &nbsp; &nbsp; inaddr = ngx_i
 net_addr(u-&gt;host.data, u-&gt;host.len);</div><div>913,915c919,923</div><div>&lt; &nbsp; &nbsp; if (in_addr == INADDR_NONE) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; host = ngx_alloc(u-&gt;host.len + 1, pool-&gt;log);</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (host == NULL) {</div><div>---</div><div>&gt; &nbsp; &nbsp; if (inaddr != INADDR_NONE) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; /* MP: ngx_shared_palloc() */</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t));</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (u-&gt;addrs == NULL) {</div><div>919c927,930</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; (void) ngx_cpystrn(host, u-&gt;host.data, u-&gt;host.len + 1);</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (sin == NULL) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERR
 OR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>921c932</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; h = gethostbyname((char *) host);</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;naddrs = 1;</div><div>923c934,936</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; ngx_free(host);</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_family = AF_INET;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_port = port;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_addr.s_addr = inaddr;</div><div>925,926c938,942</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (h == NULL || h-&gt;h_addr_list[0] == NULL) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "host not found";</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[0].sockaddr = (struct sockaddr *) sin;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[0].socklen = sizeof(struct sockaddr_in);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp
 ; &nbsp; &nbsp; p = ngx_pnalloc(pool, u-&gt;host.len + sizeof(":65535") - 1);</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (p == NULL) {</div><div>930,931c946,948</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (u-&gt;one_addr == 0) {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; h-&gt;h_addr_list[i] != NULL; i++) { /* void */ }</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[0].name.len = ngx_sprintf(p, "%V:%d",</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;u-&gt;host, ntohs(port)) - p;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[0].name.data = p;</div><div>933,934c950,957</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; } else {</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; i = 1;</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_OK;</div><div>&gt; &nbsp; &nbsp; }</div><di
 v>&gt;&nbsp;</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp; if(ngx_inet6_addr(u-&gt;host.data, u-&gt;host.len, inaddr6.s6_addr) == NGX_OK) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t));</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (u-&gt;addrs == NULL) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>937c960,963</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; /* MP: ngx_shared_palloc() */</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin6 = ngx_pcalloc(pool, sizeof(struct sockaddr_in6));</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (sin6 == NULL) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>939,940c965,974</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs = ngx_pcalloc(pool, i * sizeof(ngx_addr_t));</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (u-&gt;addrs == NULL) {</di
 v><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;naddrs = 1;</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin6-&gt;sin6_family = AF_INET6;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin6-&gt;sin6_port = port;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; ngx_memcpy(sin6-&gt;sin6_addr.s6_addr, inaddr6.s6_addr, 16);</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[0].sockaddr = (struct sockaddr *) sin6;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[0].socklen = sizeof(struct sockaddr_in6);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; p = ngx_pnalloc(pool, u-&gt;host.len + sizeof(":65535") - 1);</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (p == NULL) {</div><div>944c978,1007</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;naddrs = i;</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[0].name.len = ngx_sprintf(p, "[%V]:%d",</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbs
 p; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;u-&gt;host, ntohs(port)) - p;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[0].name.data = p;</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_OK;</div><div>&gt; &nbsp; &nbsp; }</div><div>&gt; #endif</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; /* resolve all the IP address for this host */</div><div>&gt; &nbsp; &nbsp; host = ngx_alloc(u-&gt;host.len + 1, pool-&gt;log);</div><div>&gt; &nbsp; &nbsp; if (host == NULL) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; }</div><div>&gt; &nbsp; &nbsp; ngx_cpystrn(host, u-&gt;host.data, u-&gt;host.len + 1);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; ngx_memzero (&amp;hints, sizeof (struct addrinfo));</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; /* if the address is for listen, it won't enter this reslove function */</div><div>&gt; &nbsp; &nbsp
 ; hints.ai_flags = AI_CANONNAME;</div><div>&gt; &nbsp; &nbsp; hints.ai_protocol = IPPROTO_TCP;</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; n = getaddrinfo((const char *) host,</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; NULL, &amp;hints, &amp;addrinfo);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; ngx_free (host);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; if (n != NGX_OK) {</div><div>&gt; &nbsp; &nbsp; &nbsp; u-&gt;err = "error in host resolve";</div><div>&gt; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; }</div><div>946c1009</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; h-&gt;h_addr_list[i] != NULL; i++) {</div><div>---</div><div>&gt; &nbsp; &nbsp; i = 0;</div><div>947a1011,1030</div><div>&gt; &nbsp; &nbsp; if (u-&gt;one_addr == 0) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; item = addrinfo;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; for (i = 0; item != NULL; i++, item = item-&gt;ai_next) { /* void */ }</div><div>&gt;
 &nbsp;</div><div>&gt; &nbsp; &nbsp; } else {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; i = 1;</div><div>&gt; &nbsp; &nbsp; }</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; /* MP: ngx_shared_palloc() */</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; u-&gt;addrs = ngx_pcalloc(pool, i * sizeof(ngx_addr_t));</div><div>&gt; &nbsp; &nbsp; if (u-&gt;addrs == NULL) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; }</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; u-&gt;naddrs = i;</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; for (i = 0; i &lt; u-&gt;naddrs; i++, addrinfo = addrinfo-&gt;ai_next) {</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (addrinfo-&gt;ai_family == AF_INET) {</div><div>955,956c1038,1039</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_addr.s_addr = *(in_addr_t *) (h-&gt;h_addr_list[i]);</div><div>&lt;&nbsp;</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbs
 p; &nbsp; inaddr = ((struct sockaddr_in *) addrinfo-&gt;ai_addr)-&gt;sin_addr.s_addr;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_addr.s_addr = inaddr;</div><div>960a1044,1052</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; p = ngx_pnalloc(pool, len);</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (p == NULL) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len = ngx_sock_ntop((struct sockaddr *) sin, p, len, sin-&gt;sin_port);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[i].name.len = len;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[i].name.data = p;</div><div>961a1054,1068</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; } else if (addrinfo-&gt;ai_famil
 y == AF_INET6) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sin6 = ngx_pcalloc(pool, sizeof(struct sockaddr_in6));</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; if (sin6 == NULL) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sin6-&gt;sin6_family = AF_INET6;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; sin6-&gt;sin6_port = port;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; inaddr6 = ((struct sockaddr_in6 *) addrinfo-&gt;ai_addr)-&gt;sin6_addr;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; ngx_memcpy(sin6-&gt;sin6_addr.s6_addr, inaddr6.s6_addr, 16);</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[i].sockaddr = (struct sockaddr *) sin6;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[i].socklen = si
 zeof(struct sockaddr_in6);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len = NGX_INET6_ADDRSTRLEN + sizeof(":65535") - 1;</div><div>967c1074</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len = ngx_sock_ntop((struct sockaddr *) sin, p, len, 1);</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; len = ngx_sock_ntop((struct sockaddr *) sin6, p, len, sin6-&gt;sin6_port);</div><div>970a1078,1081</div><div>&gt; #endif</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; } else {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;err = "unknown address family";</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>971a1083</div><div>&gt; &nbsp; &nbsp; }</div><div>973c1085,1086</div><div>&lt; &nbsp; &nbsp; } else {</div><div>---</div><div>&gt; &nbsp; &nbsp; return NGX_OK;</div><div>&gt; }</div><div>975c1088,1093</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; /* MP: ngx_shared_palloc() */</d
 iv><div>---</div><div>&gt; ngx_int_t</div><div>&gt; ngx_inet_sock_addr (u_char * p, size_t len, struct sockaddr * sockaddr)</div><div>&gt; {</div><div>&gt; &nbsp; &nbsp; u_char &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *port, *last;</div><div>&gt; &nbsp; &nbsp; ngx_int_t &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; n;</div><div>&gt; &nbsp; &nbsp; struct sockaddr_in &nbsp; *sin;</div><div>977,978c1095,1116</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs = ngx_pcalloc(pool, sizeof(ngx_addr_t));</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (u-&gt;addrs == NULL) {</div><div>---</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt; &nbsp; &nbsp; struct sockaddr_in6 &nbsp;*sin6;</div><div>&gt; &nbsp; &nbsp; u_char &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; *q;</div><div>&gt; #endif</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; if (len == 0) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; }</div><div>&gt;&nbsp;</div><di
 v>&gt; &nbsp; &nbsp; last = p + len;</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; port = NULL;</div><div>&gt;&nbsp;</div><div>&gt; #if (NGX_HAVE_INET6)</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; if (*p == '[') {</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; p++;</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; q = ngx_strlchr(p, last, ']');</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (q == NULL) {</div><div>982,983c1120,1122</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; sin = ngx_pcalloc(pool, sizeof(struct sockaddr_in));</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (sin == NULL) {</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (q &lt; last - 2 &amp;&amp; *(q + 1) == ':') {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; port = q + 2;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; } else {</div><div>987c1126,1152</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;naddrs = 1;</div><div>---</div>
 <div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin6 = (struct sockaddr_in6 *)sockaddr;</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin6-&gt;sin6_family = AF_INET6;</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (ngx_inet6_addr(p, q - p, sin6-&gt;sin6_addr.s6_addr) == NGX_ERROR) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; n = ngx_atoi(port, last - port);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (n == NGX_ERROR || n &lt; 1 || n &gt; 65535) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin6-&gt;sin6_port = htons(n);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; }</div><div>&gt; &nbsp; &nbsp; else</div><div>&gt; #endif</div><div>&gt; &nbsp; &
 nbsp; {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; port = ngx_strlchr(p, last, ':');</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (port == NULL) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; }</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin = (struct sockaddr_in *)sockaddr;</div><div>990,991d1154</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_port = port;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_addr.s_addr = in_addr;</div><div>993,994c1156</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[0].sockaddr = (struct sockaddr *) sin;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[0].socklen = sizeof(struct sockaddr_in);</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_addr.s_addr = ngx_inet_addr (p, port - p);</div><div>996,997c1158</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; p = ngx_pnalloc(pool, u-&gt;host.len +
  sizeof(":65535") - 1);</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; if (p == NULL) {</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (sin-&gt;sin_addr.s_addr == INADDR_NONE) {</div><div>1001,1003c1162,1171</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[0].name.len = ngx_sprintf(p, "%V:%d",</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp;&amp;u-&gt;host, ntohs(port)) - p;</div><div>&lt; &nbsp; &nbsp; &nbsp; &nbsp; u-&gt;addrs[0].name.data = p;</div><div>---</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; port++;</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; n = ngx_atoi(port, last - port);</div><div>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; if (n == NGX_ERROR || n &lt; 1 || n &gt; 65535) {</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; return NGX_ERROR;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; }</div><d
 iv>&gt;&nbsp;</div><div>&gt; &nbsp; &nbsp; &nbsp; &nbsp; sin-&gt;sin_port = htons(n);</div><div>&gt;&nbsp;</div></font><div><span id="c36bdcf5-53de-4e6c-8964-8cfc63e6a230"><br></span></div><div><span id="c36bdcf5-53de-4e6c-8964-8cfc63e6a230"><br></span></div><meta charset="utf-8"><span class="Apple-style-span" style="font-family: Arial; ">===============ngx_inet.h=====================</span></span></div><div><span id="c36bdcf5-53de-4e6c-8964-8cfc63e6a230"><font class="Apple-style-span" face="Arial">&nbsp;</font></span>110a111,112</div><div>&gt; ngx_int_t ngx_inet_sock_addr (u_char * p, size_t len,</div><div>&gt; &nbsp; &nbsp; struct sockaddr * sockaddr);</div><div><br></div><div><span id="c36bdcf5-53de-4e6c-8964-8cfc63e6a230"><font class="Apple-style-span" face="Arial"><br></font><font class="Apple-style-span" face="'Times New Roman'" size="3">-- </font><br><font class="Apple-style-span" face="'Times New Roman'" size="3"><span name="x"></span>Jiankuan Xing ~~<span name="x"><
 /span></font><br></span></div></div></div></body></html>