[PATCH] Core: guard use of AI_ADDRCONFIG

Ruslan Ermilov ru at nginx.com
Mon Aug 5 09:28:48 UTC 2013


On Mon, Aug 05, 2013 at 12:45:11AM -0700, Piotr Sikora wrote:
> # HG changeset patch
> # User Piotr Sikora <piotr at cloudflare.com>
> # Date 1375688648 0
> #      Mon Aug 05 07:44:08 2013 +0000
> # Node ID c9e0a2f54810335ba91b86fdb92ef63571680dae
> # Parent  ec8594b9bf11de3599af15de8e73e41bf7a8b42c
> Core: guard use of AI_ADDRCONFIG.
> 
> AI_ADDRCONFIG is not available on all operating systems (e.g. OpenBSD)
> and using it without a guard results in dropped getaddrinfo() support.
> 
> Signed-off-by: Piotr Sikora <piotr at cloudflare.com>

Thanks.  I suggest a different patch instead:

# HG changeset patch
# User Ruslan Ermilov <ru at nginx.com>
# Date 1375694198 -14400
#      Mon Aug 05 13:16:38 2013 +0400
# Node ID 294cead2bb846e1f6cf1469af14c9221adac74d3
# Parent  ec8594b9bf11de3599af15de8e73e41bf7a8b42c
Core: guard use of AI_ADDRCONFIG.

Some systems (notably NetBSD and OpenBSD) lack AI_ADDRCONFIG support.

Reported by Piotr Sikora.

diff --git a/auto/unix b/auto/unix
--- a/auto/unix
+++ b/auto/unix
@@ -788,11 +788,7 @@ ngx_feature_incs="#include <sys/types.h>
                   #include <netdb.h>"
 ngx_feature_path=
 ngx_feature_libs=
-ngx_feature_test='struct addrinfo hints, *res;
-                  hints.ai_family = AF_UNSPEC;
-                  hints.ai_socktype = SOCK_STREAM;
-                  hints.ai_flags = AI_ADDRCONFIG;
-                  if (getaddrinfo("localhost", NULL, &hints, &res) != 0)
-                      return 1;
+ngx_feature_test='struct addrinfo *res;
+                  if (getaddrinfo("localhost", NULL, NULL, &res) != 0) return 1;
                   freeaddrinfo(res)'
 . auto/feature
diff --git a/src/core/ngx_inet.c b/src/core/ngx_inet.c
--- a/src/core/ngx_inet.c
+++ b/src/core/ngx_inet.c
@@ -963,7 +963,9 @@ ngx_inet_resolve_host(ngx_pool_t *pool, 
     ngx_memzero(&hints, sizeof(struct addrinfo));
     hints.ai_family = AF_UNSPEC;
     hints.ai_socktype = SOCK_STREAM;
+#ifdef AI_ADDRCONFIG
     hints.ai_flags = AI_ADDRCONFIG;
+#endif
 
     if (getaddrinfo((char *) host, NULL, &hints, &res) != 0) {
         u->err = "host not found";



More information about the nginx-devel mailing list