# HG changeset patch # User Igor Sysoev # Date 1257169870 0 # Node ID fb4f7605505f064ac04551e5d88f8c965a73bf9e # Parent 798141791ad384c3323ddc7b8c7d76ce668f4467 replace inet_addr() with ngx_inet_addr() diff -r 798141791ad3 -r fb4f7605505f src/core/ngx_inet.c --- a/src/core/ngx_inet.c Mon Nov 02 12:58:30 2009 +0000 +++ b/src/core/ngx_inet.c Mon Nov 02 13:51:10 2009 +0000 @@ -643,20 +643,21 @@ return NGX_OK; } - if (len++) { - - p = ngx_alloc(len, pool->log); - if (p == NULL) { - return NGX_ERROR; - } - - (void) ngx_cpystrn(p, host, len); - - sin->sin_addr.s_addr = inet_addr((const char *) p); + if (len) { + sin->sin_addr.s_addr = ngx_inet_addr(host, len); if (sin->sin_addr.s_addr == INADDR_NONE) { + p = ngx_alloc(++len, pool->log); + if (p == NULL) { + return NGX_ERROR; + } + + (void) ngx_cpystrn(p, host, len); + 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 @@ u->wildcard = 1; } - ngx_free(p); - } else { sin->sin_addr.s_addr = INADDR_ANY; u->wildcard = 1; @@ -815,20 +814,20 @@ 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 @@ } else { - ngx_free(host); - /* MP: ngx_shared_palloc() */ u->addrs = ngx_pcalloc(pool, sizeof(ngx_peer_addr_t)); diff -r 798141791ad3 -r fb4f7605505f src/http/modules/ngx_http_realip_module.c --- a/src/http/modules/ngx_http_realip_module.c Mon Nov 02 12:58:30 2009 +0000 +++ b/src/http/modules/ngx_http_realip_module.c Mon Nov 02 13:51:10 2009 +0000 @@ -226,7 +226,7 @@ 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 -r 798141791ad3 -r fb4f7605505f src/mail/ngx_mail_auth_http_module.c --- a/src/mail/ngx_mail_auth_http_module.c Mon Nov 02 12:58:30 2009 +0000 +++ b/src/mail/ngx_mail_auth_http_module.c Mon Nov 02 13:51:10 2009 +0000 @@ -795,8 +795,7 @@ 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 "