#include <ngx_config.h>
#include <ngx_core.h>
static ngx_int_t ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u);
static ngx_int_t ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u);
static ngx_int_t ngx_parse_inet6_url(ngx_pool_t *pool, ngx_url_t *u);
static ngx_int_t ngx_inet_add_addr(ngx_pool_t *pool, ngx_url_t *u,
struct sockaddr *sockaddr, socklen_t socklen, ngx_uint_t total);
in_addr_t
ngx_inet_addr(u_char *text, size_t len)
{ … }
#if (NGX_HAVE_INET6)
ngx_int_t
ngx_inet6_addr(u_char *p, size_t len, u_char *addr)
{ … }
#endif
size_t
ngx_sock_ntop(struct sockaddr *sa, socklen_t socklen, u_char *text, size_t len,
ngx_uint_t port)
{ … }
size_t
ngx_inet_ntop(int family, void *addr, u_char *text, size_t len)
{ … }
#if (NGX_HAVE_INET6)
size_t
ngx_inet6_ntop(u_char *p, u_char *text, size_t len)
{ … }
#endif
ngx_int_t
ngx_ptocidr(ngx_str_t *text, ngx_cidr_t *cidr)
{ … }
ngx_int_t
ngx_cidr_match(struct sockaddr *sa, ngx_array_t *cidrs)
{ … }
ngx_int_t
ngx_parse_addr(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text, size_t len)
{ … }
ngx_int_t
ngx_parse_addr_port(ngx_pool_t *pool, ngx_addr_t *addr, u_char *text,
size_t len)
{ … }
ngx_int_t
ngx_parse_url(ngx_pool_t *pool, ngx_url_t *u)
{ … }
static ngx_int_t
ngx_parse_unix_domain_url(ngx_pool_t *pool, ngx_url_t *u)
{ … }
static ngx_int_t
ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u)
{ … }
static ngx_int_t
ngx_parse_inet6_url(ngx_pool_t *pool, ngx_url_t *u)
{ … }
#if (NGX_HAVE_GETADDRINFO && NGX_HAVE_INET6)
ngx_int_t
ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u)
{ … }
#else
ngx_int_t
ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u)
{
u_char *host;
ngx_uint_t i, n;
struct hostent *h;
struct sockaddr_in sin;
ngx_memzero(&sin, sizeof(struct sockaddr_in));
sin.sin_family = AF_INET;
sin.sin_addr.s_addr = ngx_inet_addr(u->host.data, u->host.len);
if (sin.sin_addr.s_addr == INADDR_NONE) {
host = ngx_alloc(u->host.len + 1, pool->log);
if (host == NULL) {
return NGX_ERROR;
}
(void) ngx_cpystrn(host, u->host.data, u->host.len + 1);
h = gethostbyname((char *) host);
ngx_free(host);
if (h == NULL || h->h_addr_list[0] == NULL) {
u->err = "host not found";
return NGX_ERROR;
}
for (n = 0; h->h_addr_list[n] != NULL; n++) { }
for (i = 0; i < n; i++) {
sin.sin_addr.s_addr = *(in_addr_t *) (h->h_addr_list[i]);
if (ngx_inet_add_addr(pool, u, (struct sockaddr *) &sin,
sizeof(struct sockaddr_in), n)
!= NGX_OK)
{
return NGX_ERROR;
}
}
} else {
if (ngx_inet_add_addr(pool, u, (struct sockaddr *) &sin,
sizeof(struct sockaddr_in), 1)
!= NGX_OK)
{
return NGX_ERROR;
}
}
return NGX_OK;
}
#endif
static ngx_int_t
ngx_inet_add_addr(ngx_pool_t *pool, ngx_url_t *u, struct sockaddr *sockaddr,
socklen_t socklen, ngx_uint_t total)
{ … }
ngx_int_t
ngx_cmp_sockaddr(struct sockaddr *sa1, socklen_t slen1,
struct sockaddr *sa2, socklen_t slen2, ngx_uint_t cmp_port)
{ … }
in_port_t
ngx_inet_get_port(struct sockaddr *sa)
{ … }
void
ngx_inet_set_port(struct sockaddr *sa, in_port_t port)
{ … }
ngx_uint_t
ngx_inet_wildcard(struct sockaddr *sa)
{ … }