diff options
author | Igor Sysoev <igor@sysoev.ru> | 2009-11-02 13:51:10 +0000 |
---|---|---|
committer | Igor Sysoev <igor@sysoev.ru> | 2009-11-02 13:51:10 +0000 |
commit | 0f25ed3d779e3d31aff3c9484c77ccb8353fcdf4 (patch) | |
tree | cbaf1f579df0a818452b4fcc9e6b8e250833b224 /src | |
parent | 47c88464ebc3ddd7c2c31f5026fa7b9389f42cfa (diff) | |
download | nginx-0f25ed3d779e3d31aff3c9484c77ccb8353fcdf4.tar.gz nginx-0f25ed3d779e3d31aff3c9484c77ccb8353fcdf4.zip |
replace inet_addr() with ngx_inet_addr()
Diffstat (limited to 'src')
-rw-r--r-- | src/core/ngx_inet.c | 39 | ||||
-rw-r--r-- | src/http/modules/ngx_http_realip_module.c | 2 | ||||
-rw-r--r-- | src/mail/ngx_mail_auth_http_module.c | 3 |
3 files changed, 20 insertions, 24 deletions
diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c index c6f36fe9c..326383b8f 100644 --- a/src/core/ngx_inet.c +++ b/src/core/ngx_inet.c @@ -643,20 +643,21 @@ ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u) return NGX_OK; } - if (len++) { + if (len) { + sin->sin_addr.s_addr = ngx_inet_addr(host, len); - p = ngx_alloc(len, pool->log); - if (p == NULL) { - return NGX_ERROR; - } - - (void) ngx_cpystrn(p, host, len); + if (sin->sin_addr.s_addr == INADDR_NONE) { + p = ngx_alloc(++len, pool->log); + if (p == NULL) { + return NGX_ERROR; + } - sin->sin_addr.s_addr = inet_addr((const char *) p); + (void) ngx_cpystrn(p, host, len); - if (sin->sin_addr.s_addr == INADDR_NONE) { h = gethostbyname((const char *) p); + ngx_free(p); + if (h == NULL || h->h_addr_list[0] == NULL) { ngx_free(p); u->err = "host not found"; @@ -670,8 +671,6 @@ ngx_parse_inet_url(ngx_pool_t *pool, ngx_url_t *u) u->wildcard = 1; } - ngx_free(p); - } else { sin->sin_addr.s_addr = INADDR_ANY; u->wildcard = 1; @@ -815,20 +814,20 @@ ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u) struct hostent *h; struct sockaddr_in *sin; - 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); - /* AF_INET only */ port = htons(u->port); - in_addr = inet_addr((char *) host); + in_addr = ngx_inet_addr(u->host.data, u->host.len); if (in_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); @@ -883,8 +882,6 @@ ngx_inet_resolve_host(ngx_pool_t *pool, ngx_url_t *u) } else { - ngx_free(host); - /* MP: ngx_shared_palloc() */ u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t)); diff --git a/src/http/modules/ngx_http_realip_module.c b/src/http/modules/ngx_http_realip_module.c index 3b2cce679..927893bbb 100644 --- a/src/http/modules/ngx_http_realip_module.c +++ b/src/http/modules/ngx_http_realip_module.c @@ -226,7 +226,7 @@ found: ngx_http_set_ctx(r, ctx, ngx_http_realip_module); - addr = inet_addr((char *) ip); + addr = ngx_inet_addr(ip, len); if (addr == INADDR_NONE) { return NGX_DECLINED; diff --git a/src/mail/ngx_mail_auth_http_module.c b/src/mail/ngx_mail_auth_http_module.c index acd06656f..a27b11602 100644 --- a/src/mail/ngx_mail_auth_http_module.c +++ b/src/mail/ngx_mail_auth_http_module.c @@ -795,8 +795,7 @@ ngx_mail_auth_http_process_headers(ngx_mail_session_t *s, sin->sin_port = htons((in_port_t) port); - ctx->addr.data[ctx->addr.len] = '\0'; - sin->sin_addr.s_addr = inet_addr((char *) ctx->addr.data); + sin->sin_addr.s_addr = ngx_inet_addr(ctx->addr.data, ctx->addr.len); if (sin->sin_addr.s_addr == INADDR_NONE) { ngx_log_error(NGX_LOG_ERR, s->connection->log, 0, "auth http server %V sent invalid server " |