diff options
author | Igor Sysoev <igor@sysoev.ru> | 2006-10-24 13:06:55 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2006-10-24 13:06:55 +0000 |
commit | 20bf47b73d9cd2edf81ea5fa3962f9684707b99a (patch) | |
tree | 55e98d92a2e3f1bf2aa3212ff8b7667ef733c1f7 /src/core/ngx_inet.c | |
parent | 70296c518a9dbf29a92159c62abd0624308cfacd (diff) | |
download | nginx-20bf47b73d9cd2edf81ea5fa3962f9684707b99a.tar.gz nginx-20bf47b73d9cd2edf81ea5fa3962f9684707b99a.zip |
now the "listen" directives use ngx_parse_url()
Diffstat (limited to 'src/core/ngx_inet.c')
-rw-r--r-- | src/core/ngx_inet.c | 49 |
1 files changed, 47 insertions, 2 deletions
diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c index cf4b8f699..32fc2c555 100644 --- a/src/core/ngx_inet.c +++ b/src/core/ngx_inet.c @@ -10,6 +10,9 @@ #include <ngx_event_connect.h> +static char *ngx_inet_parse_host_port(ngx_inet_upstream_t *u); + + /* * ngx_sock_ntop() and ngx_inet_ntop() may be implemented as * "ngx_sprintf(text, "%ud.%ud.%ud.%ud", p[0], p[1], p[2], p[3])", however, @@ -223,10 +226,11 @@ ngx_ptocidr(ngx_str_t *text, void *cidr) ngx_int_t ngx_parse_url(ngx_conf_t *cf, ngx_url_t *u) { - u_char *p; + u_char *p, *host; size_t len; ngx_int_t port; ngx_uint_t i; + struct hostent *h; #if (NGX_HAVE_UNIX_DOMAIN) struct sockaddr_un *saun; #endif @@ -390,6 +394,47 @@ ngx_parse_url(ngx_conf_t *cf, ngx_url_t *u) port: if (u->listen) { + if (u->portn == 0) { + if (u->default_portn == 0) { + u->err = "no port"; + return NGX_ERROR; + } + + u->portn = u->default_portn; + } + + if (u->host.len == 1 && u->host.data[0] == '*') { + u->host.len = 0; + } + + /* AF_INET only */ + + if (u->host.len) { + + host = ngx_palloc(cf->temp_pool, u->host.len + 1); + if (host == NULL) { + return NGX_ERROR; + } + + (void) ngx_cpystrn(host, u->host.data, u->host.len + 1); + + u->addr.in_addr = inet_addr((const char *) host); + + if (u->addr.in_addr == INADDR_NONE) { + h = gethostbyname((const char *) host); + + if (h == NULL || h->h_addr_list[0] == NULL) { + u->err = "host not found"; + return NGX_ERROR; + } + + u->addr.in_addr = *(in_addr_t *)(h->h_addr_list[0]); + } + + } else { + u->addr.in_addr = INADDR_ANY; + } + return NGX_OK; } @@ -737,7 +782,7 @@ ngx_inet_upstream_parse(ngx_conf_t *cf, ngx_inet_upstream_t *u) } -char * +static char * ngx_inet_parse_host_port(ngx_inet_upstream_t *u) { size_t i; |