Mercurial > hg > nginx-quic
comparison src/core/ngx_inet.c @ 804:472cd9768ac2
now the "listen" directives use ngx_parse_url()
author | Igor Sysoev <igor@sysoev.ru> |
---|---|
date | Tue, 24 Oct 2006 13:06:55 +0000 |
parents | 2452d89efea9 |
children | eef6d9cc45da |
comparison
equal
deleted
inserted
replaced
803:134a3c12d298 | 804:472cd9768ac2 |
---|---|
6 | 6 |
7 #include <ngx_config.h> | 7 #include <ngx_config.h> |
8 #include <ngx_core.h> | 8 #include <ngx_core.h> |
9 #include <ngx_event.h> | 9 #include <ngx_event.h> |
10 #include <ngx_event_connect.h> | 10 #include <ngx_event_connect.h> |
11 | |
12 | |
13 static char *ngx_inet_parse_host_port(ngx_inet_upstream_t *u); | |
11 | 14 |
12 | 15 |
13 /* | 16 /* |
14 * ngx_sock_ntop() and ngx_inet_ntop() may be implemented as | 17 * ngx_sock_ntop() and ngx_inet_ntop() may be implemented as |
15 * "ngx_sprintf(text, "%ud.%ud.%ud.%ud", p[0], p[1], p[2], p[3])", however, | 18 * "ngx_sprintf(text, "%ud.%ud.%ud.%ud", p[0], p[1], p[2], p[3])", however, |
221 | 224 |
222 | 225 |
223 ngx_int_t | 226 ngx_int_t |
224 ngx_parse_url(ngx_conf_t *cf, ngx_url_t *u) | 227 ngx_parse_url(ngx_conf_t *cf, ngx_url_t *u) |
225 { | 228 { |
226 u_char *p; | 229 u_char *p, *host; |
227 size_t len; | 230 size_t len; |
228 ngx_int_t port; | 231 ngx_int_t port; |
229 ngx_uint_t i; | 232 ngx_uint_t i; |
233 struct hostent *h; | |
230 #if (NGX_HAVE_UNIX_DOMAIN) | 234 #if (NGX_HAVE_UNIX_DOMAIN) |
231 struct sockaddr_un *saun; | 235 struct sockaddr_un *saun; |
232 #endif | 236 #endif |
233 | 237 |
234 len = u->url.len; | 238 len = u->url.len; |
388 u->portn = (in_port_t) port; | 392 u->portn = (in_port_t) port; |
389 | 393 |
390 port: | 394 port: |
391 | 395 |
392 if (u->listen) { | 396 if (u->listen) { |
397 if (u->portn == 0) { | |
398 if (u->default_portn == 0) { | |
399 u->err = "no port"; | |
400 return NGX_ERROR; | |
401 } | |
402 | |
403 u->portn = u->default_portn; | |
404 } | |
405 | |
406 if (u->host.len == 1 && u->host.data[0] == '*') { | |
407 u->host.len = 0; | |
408 } | |
409 | |
410 /* AF_INET only */ | |
411 | |
412 if (u->host.len) { | |
413 | |
414 host = ngx_palloc(cf->temp_pool, u->host.len + 1); | |
415 if (host == NULL) { | |
416 return NGX_ERROR; | |
417 } | |
418 | |
419 (void) ngx_cpystrn(host, u->host.data, u->host.len + 1); | |
420 | |
421 u->addr.in_addr = inet_addr((const char *) host); | |
422 | |
423 if (u->addr.in_addr == INADDR_NONE) { | |
424 h = gethostbyname((const char *) host); | |
425 | |
426 if (h == NULL || h->h_addr_list[0] == NULL) { | |
427 u->err = "host not found"; | |
428 return NGX_ERROR; | |
429 } | |
430 | |
431 u->addr.in_addr = *(in_addr_t *)(h->h_addr_list[0]); | |
432 } | |
433 | |
434 } else { | |
435 u->addr.in_addr = INADDR_ANY; | |
436 } | |
437 | |
393 return NGX_OK; | 438 return NGX_OK; |
394 } | 439 } |
395 | 440 |
396 if (u->default_port) { | 441 if (u->default_port) { |
397 | 442 |
735 | 780 |
736 return peers; | 781 return peers; |
737 } | 782 } |
738 | 783 |
739 | 784 |
740 char * | 785 static char * |
741 ngx_inet_parse_host_port(ngx_inet_upstream_t *u) | 786 ngx_inet_parse_host_port(ngx_inet_upstream_t *u) |
742 { | 787 { |
743 size_t i; | 788 size_t i; |
744 ngx_int_t port; | 789 ngx_int_t port; |
745 ngx_str_t *url; | 790 ngx_str_t *url; |