Compiling a testdir for module 'netdb-h' on mingw, I see this compilation error:
../../gltests/test-netdb-h.c:33:11: error: ‘AI_NUMERICSERV’ undeclared here
(not in a function); did you mean ‘NI_NUMERICSERV’?
33 | int ai2 = AI_NUMERICSERV;
| ^~~~~~~~~~~~~~
| NI_NUMERICSERV
make[4]: *** [Makefile:6098: test-netdb-h.o] Error 1
Fixed as follows:
2026-11-24 Bruno Haible <[email protected]>
netdb-h: Fix test compilation error on native Windows.
* m4/netdb_h.m4 (gl_NETDB_H): Test for 'struct addrinfo' here.
(gl_NETDB_H_DEFAULTS): Don't set HAVE_STRUCT_ADDRINFO here.
* m4/getaddrinfo.m4 (gl_PREREQ_GETADDRINFO): Don't test for
'struct addrinfo' here.
* lib/netdb.in.h (struct addrinfo, AI_*, EAI_*): Enable definitions also
when module 'getaddrinfo' is not in use.
diff --git a/lib/netdb.in.h b/lib/netdb.in.h
index 92f1220cee..9b6c94e68b 100644
--- a/lib/netdb.in.h
+++ b/lib/netdb.in.h
@@ -62,15 +62,13 @@
#undef NI_MAXSERV
#define NI_MAXSERV 32
-#if @GNULIB_GETADDRINFO@
-
-# if !@HAVE_STRUCT_ADDRINFO@
+#if !@HAVE_STRUCT_ADDRINFO@
-# ifdef __cplusplus
+# ifdef __cplusplus
extern "C" {
-# endif
+# endif
-# if !GNULIB_defined_struct_addrinfo
+# if !GNULIB_defined_struct_addrinfo
/* Structure to contain information about address of a service provider. */
struct addrinfo
{
@@ -83,92 +81,94 @@ struct addrinfo
char *ai_canonname; /* Canonical name for service location. */
struct addrinfo *ai_next; /* Pointer to next in list. */
};
-# define GNULIB_defined_struct_addrinfo 1
-# endif
+# define GNULIB_defined_struct_addrinfo 1
+# endif
-# ifdef __cplusplus
+# ifdef __cplusplus
}
-# endif
-
# endif
+#endif
+
/* Possible values for 'ai_flags' field in 'addrinfo' structure. */
-# ifndef AI_PASSIVE
-# define AI_PASSIVE 0x0001 /* Socket address is intended for 'bind'. */
-# endif
-# ifndef AI_CANONNAME
-# define AI_CANONNAME 0x0002 /* Request for canonical name. */
-# endif
-# ifndef AI_NUMERICHOST
-# define AI_NUMERICHOST 0x0004 /* Return numeric host address as name. */
-# endif
-# ifndef AI_NUMERICSERV
-# define AI_NUMERICSERV 0x0400 /* Return service number as service name. */
-# endif
+#ifndef AI_PASSIVE
+# define AI_PASSIVE 0x0001 /* Socket address is intended for 'bind'. */
+#endif
+#ifndef AI_CANONNAME
+# define AI_CANONNAME 0x0002 /* Request for canonical name. */
+#endif
+#ifndef AI_NUMERICHOST
+# define AI_NUMERICHOST 0x0004 /* Return numeric host address as name. */
+#endif
+#ifndef AI_NUMERICSERV
+# define AI_NUMERICSERV 0x0400 /* Return service number as service name. */
+#endif
/* These symbolic constants are required to be present by POSIX, but
our getaddrinfo replacement doesn't use them (yet). Setting them
to 0 on systems that doesn't have them avoids causing problems for
system getaddrinfo implementations that would be confused by
unknown values. */
-# ifndef AI_V4MAPPED
-# define AI_V4MAPPED 0 /* 0x0008: IPv4 mapped addresses are acceptable. */
-# endif
-# ifndef AI_ALL
-# define AI_ALL 0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */
-# endif
-# ifndef AI_ADDRCONFIG
-# define AI_ADDRCONFIG 0 /* 0x0020: Use configuration of this host to choose
- returned address type. */
-# endif
+#ifndef AI_V4MAPPED
+# define AI_V4MAPPED 0 /* 0x0008: IPv4 mapped addresses are acceptable. */
+#endif
+#ifndef AI_ALL
+# define AI_ALL 0 /* 0x0010: Return IPv4 mapped and IPv6 addresses. */
+#endif
+#ifndef AI_ADDRCONFIG
+# define AI_ADDRCONFIG 0 /* 0x0020: Use configuration of this host to choose
+ returned address type. */
+#endif
/* Error values for 'getaddrinfo' function. */
-# ifndef EAI_BADFLAGS
-# define EAI_BADFLAGS -1 /* Invalid value for 'ai_flags' field. */
-# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
-# define EAI_AGAIN -3 /* Temporary failure in name resolution. */
-# define EAI_FAIL -4 /* Non-recoverable failure in name res. */
-# define EAI_NODATA -5 /* No address associated with NAME. */
-# define EAI_FAMILY -6 /* 'ai_family' not supported. */
-# define EAI_SOCKTYPE -7 /* 'ai_socktype' not supported. */
-# define EAI_SERVICE -8 /* SERVICE not supported for 'ai_socktype'. */
-# define EAI_MEMORY -10 /* Memory allocation failure. */
-# endif
+#ifndef EAI_BADFLAGS
+# define EAI_BADFLAGS -1 /* Invalid value for 'ai_flags' field. */
+# define EAI_NONAME -2 /* NAME or SERVICE is unknown. */
+# define EAI_AGAIN -3 /* Temporary failure in name resolution. */
+# define EAI_FAIL -4 /* Non-recoverable failure in name res. */
+# define EAI_NODATA -5 /* No address associated with NAME. */
+# define EAI_FAMILY -6 /* 'ai_family' not supported. */
+# define EAI_SOCKTYPE -7 /* 'ai_socktype' not supported. */
+# define EAI_SERVICE -8 /* SERVICE not supported for 'ai_socktype'. */
+# define EAI_MEMORY -10 /* Memory allocation failure. */
+#endif
/* Since EAI_NODATA is deprecated by RFC3493, some systems (at least
FreeBSD, which does define EAI_BADFLAGS) have removed the definition
in favor of EAI_NONAME. */
-# if !defined EAI_NODATA && defined EAI_NONAME
-# define EAI_NODATA EAI_NONAME
-# endif
+#if !defined EAI_NODATA && defined EAI_NONAME
+# define EAI_NODATA EAI_NONAME
+#endif
-# ifndef EAI_OVERFLOW
+#ifndef EAI_OVERFLOW
/* Not defined on mingw32 and Haiku. */
-# define EAI_OVERFLOW -12 /* Argument buffer overflow. */
-# endif
-# ifndef EAI_ADDRFAMILY
+# define EAI_OVERFLOW -12 /* Argument buffer overflow. */
+#endif
+#ifndef EAI_ADDRFAMILY
/* Not defined on mingw32. */
-# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
-# endif
-# ifndef EAI_SYSTEM
+# define EAI_ADDRFAMILY -9 /* Address family for NAME not supported. */
+#endif
+#ifndef EAI_SYSTEM
/* Not defined on mingw32. */
-# define EAI_SYSTEM -11 /* System error returned in 'errno'. */
-# endif
+# define EAI_SYSTEM -11 /* System error returned in 'errno'. */
+#endif
-# if 0
+#if 0
/* The commented out definitions below are not yet implemented in the
GNULIB getaddrinfo() replacement, so are not yet needed.
If they are restored, be sure to protect the definitions with #ifndef. */
-# ifndef EAI_INPROGRESS
-# define EAI_INPROGRESS -100 /* Processing request in progress. */
-# define EAI_CANCELED -101 /* Request canceled. */
-# define EAI_NOTCANCELED -102 /* Request not canceled. */
-# define EAI_ALLDONE -103 /* All requests done. */
-# define EAI_INTR -104 /* Interrupted by a signal. */
-# define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
-# endif
+# ifndef EAI_INPROGRESS
+# define EAI_INPROGRESS -100 /* Processing request in progress. */
+# define EAI_CANCELED -101 /* Request canceled. */
+# define EAI_NOTCANCELED -102 /* Request not canceled. */
+# define EAI_ALLDONE -103 /* All requests done. */
+# define EAI_INTR -104 /* Interrupted by a signal. */
+# define EAI_IDN_ENCODE -105 /* IDN encoding failed. */
# endif
+#endif
+
+#if @GNULIB_GETADDRINFO@
/* Translate name of a service location and/or a service name to set of
socket addresses.
diff --git a/m4/getaddrinfo.m4 b/m4/getaddrinfo.m4
index 8a63600b83..f967cfa18d 100644
--- a/m4/getaddrinfo.m4
+++ b/m4/getaddrinfo.m4
@@ -1,5 +1,5 @@
# getaddrinfo.m4
-# serial 39
+# serial 40
dnl Copyright (C) 2004-2026 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -259,22 +259,6 @@ AC_DEFUN([gl_PREREQ_GETADDRINFO]
HAVE_DECL_GETNAMEINFO=0
fi
- AC_CHECK_TYPES([struct addrinfo],,,[
-#include <sys/types.h>
-#ifdef HAVE_SYS_SOCKET_H
-#include <sys/socket.h>
-#endif
-#ifdef HAVE_NETDB_H
-#include <netdb.h>
-#endif
-#ifdef HAVE_WS2TCPIP_H
-#include <ws2tcpip.h>
-#endif
-])
- if test $ac_cv_type_struct_addrinfo = no; then
- HAVE_STRUCT_ADDRINFO=0
- fi
-
dnl Append $HOSTENT_LIB to GETADDRINFO_LIB, avoiding gratuitous duplicates.
case " $GETADDRINFO_LIB " in
*" $HOSTENT_LIB "*) ;;
diff --git a/m4/netdb_h.m4 b/m4/netdb_h.m4
index bcf19b018f..2e471c2c5f 100644
--- a/m4/netdb_h.m4
+++ b/m4/netdb_h.m4
@@ -1,5 +1,5 @@
# netdb_h.m4
-# serial 15
+# serial 16
dnl Copyright (C) 2008-2026 Free Software Foundation, Inc.
dnl This file is free software; the Free Software Foundation
dnl gives unlimited permission to copy and/or distribute it,
@@ -21,6 +21,26 @@ AC_DEFUN_ONCE([gl_NETDB_H]
dnl corresponding gnulib module is not in use.
gl_WARN_ON_USE_PREPARE([[#include <netdb.h>]],
[getaddrinfo freeaddrinfo gai_strerror getnameinfo])
+
+ AC_REQUIRE([gl_SYS_SOCKET_H])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
+ AC_CHECK_TYPES([struct addrinfo],,,[
+#include <sys/types.h>
+#ifdef HAVE_SYS_SOCKET_H
+#include <sys/socket.h>
+#endif
+#ifdef HAVE_NETDB_H
+#include <netdb.h>
+#endif
+#ifdef HAVE_WS2TCPIP_H
+#include <ws2tcpip.h>
+#endif
+])
+ if test $ac_cv_type_struct_addrinfo = yes; then
+ HAVE_STRUCT_ADDRINFO=1
+ else
+ HAVE_STRUCT_ADDRINFO=0
+ fi
+ AC_SUBST([HAVE_STRUCT_ADDRINFO])
])
# gl_NETDB_MODULE_INDICATOR([modulename])
@@ -51,7 +71,6 @@ AC_DEFUN([gl_NETDB_H_REQUIRE_DEFAULTS]
AC_DEFUN([gl_NETDB_H_DEFAULTS],
[
dnl Assume proper GNU behavior unless another module says otherwise.
- HAVE_STRUCT_ADDRINFO=1; AC_SUBST([HAVE_STRUCT_ADDRINFO])
HAVE_DECL_FREEADDRINFO=1; AC_SUBST([HAVE_DECL_FREEADDRINFO])
HAVE_DECL_GAI_STRERROR=1; AC_SUBST([HAVE_DECL_GAI_STRERROR])
HAVE_DECL_GETADDRINFO=1; AC_SUBST([HAVE_DECL_GETADDRINFO])