]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
getaddrinfo: Fix test failure on Solaris 10.
authorBruno Haible <bruno@clisp.org>
Fri, 23 Jan 2026 16:30:02 +0000 (17:30 +0100)
committerBruno Haible <bruno@clisp.org>
Fri, 23 Jan 2026 16:30:19 +0000 (17:30 +0100)
* m4/getaddrinfo.m4 (gl_GETADDRINFO): Test also whether getaddrinfo
supports AI_NUMERICHOST.
* lib/getaddrinfo.c (is_numeric_host): Define also on Solaris.
(getaddrinfo): Add a workaround for Solaris 10.
* doc/posix-functions/getaddrinfo.texi: Mention the Solaris 10 bug.

ChangeLog
doc/posix-functions/getaddrinfo.texi
lib/getaddrinfo.c
m4/getaddrinfo.m4

index 29bd6c6200912e3a77b795610061086ad2bfe08f..e8bc6c3341252ad07785295c80b21b4134ef12f8 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,12 @@
+2026-01-23  Bruno Haible  <bruno@clisp.org>
+
+       getaddrinfo: Fix test failure on Solaris 10.
+       * m4/getaddrinfo.m4 (gl_GETADDRINFO): Test also whether getaddrinfo
+       supports AI_NUMERICHOST.
+       * lib/getaddrinfo.c (is_numeric_host): Define also on Solaris.
+       (getaddrinfo): Add a workaround for Solaris 10.
+       * doc/posix-functions/getaddrinfo.texi: Mention the Solaris 10 bug.
+
 2026-01-22  Collin Funk  <collin.funk1@gmail.com>
 
        getdelim, getline: Don't replace these functions on glibc.
index dd216d23d87d772942c15c574ecf9bacd774499d..7b9479d013455ad7803a58c10a27edd23264e5cb 100644 (file)
@@ -21,6 +21,9 @@ the @code{AI_NUMERICSERV} hints flag.
 @item
 On native Windows, in 32-bit mode, this function is defined
 with a calling convention that is different from @code{cdecl}.
+@item
+On Solaris 10, this function does not support
+the @code{AI_NUMERICHOST} hints flag.
 @end itemize
 
 Portability problems not fixed by Gnulib:
index b497aa3e2d229b03d5d048b8b2f99eb6905ce535..2b60377bdb57df984eefbf28bebc4d11377970c9 100644 (file)
 # define PF_UNSPEC 0
 #endif
 
+#if defined __sun || !HAVE_GETADDRINFO
+
+static bool
+is_numeric_host (const char *host, int family)
+{
+# if HAVE_IPV4
+  if (family == PF_INET || family == PF_UNSPEC)
+    {
+      /* glibc supports IPv4 addresses in numbers-and-dots notation, that is,
+         also hexadecimal and octal number formats and formats that don't
+         require all four bytes to be explicitly written, via inet_aton().
+         But POSIX doesn't require support for these legacy formats.  Therefore
+         we are free to use inet_pton() instead of inet_aton().  */
+      struct in_addr addr;
+      if (inet_pton (AF_INET, host, &addr))
+        return true;
+    }
+# endif
+# if HAVE_IPV6
+  if (family == PF_INET6 || family == PF_UNSPEC)
+    {
+      struct in6_addr addr;
+      if (inet_pton (AF_INET6, host, &addr))
+        return true;
+    }
+# endif
+  return false;
+}
+
+#endif
+
 #if HAVE_GETADDRINFO
 
-/* Override with cdecl calling convention and mingw fix.  */
+/* Override with cdecl calling convention and Windows and Solaris 10 fixes.  */
 
 int
 getaddrinfo (const char *restrict nodename,
@@ -63,10 +94,18 @@ getaddrinfo (const char *restrict nodename,
              struct addrinfo **restrict res)
 # undef getaddrinfo
 {
+  /* Workaround for native Windows.  */
   if (hints && (hints->ai_flags & AI_NUMERICSERV) != 0
       && servname && !(*servname >= '0' && *servname <= '9'))
     return EAI_NONAME;
 
+# ifdef __sun
+  /* Workaround for Solaris 10.  */
+  if (hints && (hints->ai_flags & AI_NUMERICHOST)
+      && nodename && !is_numeric_host (nodename, hints->ai_family))
+    return EAI_NONAME;
+# endif
+
   return getaddrinfo (nodename, servname, hints, res);
 }
 
@@ -184,33 +223,6 @@ validate_family (int family)
    return false;
 }
 
-static bool
-is_numeric_host (const char *host, int family)
-{
-# if HAVE_IPV4
-  if (family == PF_INET || family == PF_UNSPEC)
-    {
-      /* glibc supports IPv4 addresses in numbers-and-dots notation, that is,
-         also hexadecimal and octal number formats and formats that don't
-         require all four bytes to be explicitly written, via inet_aton().
-         But POSIX doesn't require support for these legacy formats.  Therefore
-         we are free to use inet_pton() instead of inet_aton().  */
-      struct in_addr addr;
-      if (inet_pton (AF_INET, host, &addr))
-        return true;
-    }
-# endif
-# if HAVE_IPV6
-  if (family == PF_INET6 || family == PF_UNSPEC)
-    {
-      struct in6_addr addr;
-      if (inet_pton (AF_INET6, host, &addr))
-        return true;
-    }
-# endif
-  return false;
-}
-
 /* Translate name of a service location and/or a service name to set of
    socket addresses. */
 int
index 20363bf743818484ec6f4259dd03407187d90afd..8a63600b83677274ce0f882bfb671c1535cdd1e2 100644 (file)
@@ -1,5 +1,5 @@
 # getaddrinfo.m4
-# serial 38
+# serial 39
 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,
@@ -90,7 +90,7 @@ int getaddrinfo (const char *, const char *, const struct addrinfo *, struct add
     fi
   fi
   if test $HAVE_GETADDRINFO != 0; then
-    AC_CACHE_CHECK([whether getaddrinfo supports AI_NUMERICSERV],
+    AC_CACHE_CHECK([whether getaddrinfo supports AI_NUMERICHOST and AI_NUMERICSERV],
       [gl_cv_func_getaddrinfo_works],
       [AC_RUN_IFELSE(
          [AC_LANG_PROGRAM([[
@@ -107,16 +107,30 @@ int getaddrinfo (const char *, const char *, const struct addrinfo *, struct add
 #include <stddef.h>
 #include <string.h>
             ]], [[
-              struct addrinfo hints;
+              int result = 0;
               struct addrinfo *ai;
-              memset (&hints, 0, sizeof (hints));
-              hints.ai_flags = AI_NUMERICSERV;
-              return getaddrinfo ("www.gnu.org", "http", &hints, &ai) != EAI_NONAME;
+              {
+                struct addrinfo hints;
+                memset (&hints, 0, sizeof (hints));
+                hints.ai_flags = AI_NUMERICHOST;
+                if (getaddrinfo ("www.gnu.org", "http", &hints, &ai) != EAI_NONAME)
+                  result |= 1;
+              }
+              {
+                struct addrinfo hints;
+                memset (&hints, 0, sizeof (hints));
+                hints.ai_flags = AI_NUMERICSERV;
+                if (getaddrinfo ("www.gnu.org", "http", &hints, &ai) != EAI_NONAME)
+                  result |= 2;
+              }
+              return result;
             ]])
          ],
          [gl_cv_func_getaddrinfo_works=yes],
          [gl_cv_func_getaddrinfo_works=no],
          [case "$host_os" in
+                               # Guess no on Solaris.
+            solaris*)          gl_cv_func_getaddrinfo_works="guessing no" ;;
                                # Guess no on native Windows.
             mingw* | windows*) gl_cv_func_getaddrinfo_works="guessing no" ;;
                                # Guess yes otherwise.