Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-21 Thread Bruno Haible via Gnulib discussion list
> > Now the test failure produces this info:
> >
> > FAIL: test-getaddrinfo
> > ==
> >
> > Test case pass=3, host=www.gnu.org, service=http failed: expected 
> > EAI_NONAME, got -8
> > Test case pass=3, host=www.ibm.com, service=https failed: expected 
> > EAI_NONAME, got -8
> > Test case pass=3, host=microsoft.com, service=http failed: expected 
> > EAI_NONAME, got -8
> > Test case pass=3, host=google.org, service=ldap failed: expected 
> > EAI_NONAME, got -8
> > FAIL test-getaddrinfo (exit status: 4)
> >
> > Where -8 is EAI_SERVICE. This is on a Debian 12 system.
> >
> > This failure makes no sense to me. Any idea?
> 
> Is there a /etc/services file?

Of course there is an /etc/services file; otherwise, the other test cases
without AI_NUMERICHOST would have failed as well.

Meanwhile I have disabled the failing test cases, assuming it's a glibc bug
— either  or possibly
a different one.

Bruno






Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-21 Thread Simon Josefsson via Gnulib discussion list
Bruno Haible via Gnulib discussion list  writes:

>> 2025-02-17  Bruno Haible  
>> 
>>  getaddrinfo tests: Make failures more verbose.
>>  * tests/test-getaddrinfo.c (simple): Print some info before returning 1.
>
> Now the test failure produces this info:
>
> FAIL: test-getaddrinfo
> ==
>
> Test case pass=3, host=www.gnu.org, service=http failed: expected EAI_NONAME, 
> got -8
> Test case pass=3, host=www.ibm.com, service=https failed: expected 
> EAI_NONAME, got -8
> Test case pass=3, host=microsoft.com, service=http failed: expected 
> EAI_NONAME, got -8
> Test case pass=3, host=google.org, service=ldap failed: expected EAI_NONAME, 
> got -8
> FAIL test-getaddrinfo (exit status: 4)
>
> Where -8 is EAI_SERVICE. This is on a Debian 12 system.
>
> This failure makes no sense to me. Any idea?

Is there a /etc/services file?  Sometimes that file is not installed (it
is in the 'netbase' package), and a lot of things break in weirds way
related to service name lookups.

It would be nice to separate failures due to missing service names from
other failures in getaddrinfo(), but it can get a bit complex.

/Simon


signature.asc
Description: PGP signature


Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-18 Thread KO Myung-Hun
Hi/2.

Bruno Haible wrote:
>> 2025-02-17  Bruno Haible  
>>
>>  getaddrinfo tests: Make failures more verbose.
>>  * tests/test-getaddrinfo.c (simple): Print some info before returning 1.
> 
> Now the test failure produces this info:
> 
> FAIL: test-getaddrinfo
> ==
> 
> Test case pass=3, host=www.gnu.org, service=http failed: expected EAI_NONAME, 
> got -8
> Test case pass=3, host=www.ibm.com, service=https failed: expected 
> EAI_NONAME, got -8
> Test case pass=3, host=microsoft.com, service=http failed: expected 
> EAI_NONAME, got -8
> Test case pass=3, host=google.org, service=ldap failed: expected EAI_NONAME, 
> got -8
> FAIL test-getaddrinfo (exit status: 4)
> 
> Where -8 is EAI_SERVICE. This is on a Debian 12 system.
> 
> This failure makes no sense to me. Any idea?
> 
> Bruno
> 

Late but neither do I.

-- 
KO Myung-Hun

Korean OS/2 User Community : https://www.os2.kr/



Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-17 Thread Bruno Haible via Gnulib discussion list
> FAIL: test-getaddrinfo
> ==
> 
> Test case pass=3, host=www.gnu.org, service=http failed: expected EAI_NONAME, 
> got -8
> Test case pass=3, host=www.ibm.com, service=https failed: expected 
> EAI_NONAME, got -8
> Test case pass=3, host=microsoft.com, service=http failed: expected 
> EAI_NONAME, got -8
> Test case pass=3, host=google.org, service=ldap failed: expected EAI_NONAME, 
> got -8
> FAIL test-getaddrinfo (exit status: 4)
> 
> Where -8 is EAI_SERVICE. This is on a Debian 12 system.

Let's these 4 test cases.


2025-02-17  Bruno Haible  

getaddrinfo tests: Skip test cases that may fail on Debian 12.
* tests/test-getaddrinfo.c (main): Skip some test cases on glibc.

diff --git a/tests/test-getaddrinfo.c b/tests/test-getaddrinfo.c
index 4485d7dd10..dfa794791e 100644
--- a/tests/test-getaddrinfo.c
+++ b/tests/test-getaddrinfo.c
@@ -221,10 +221,14 @@ int main (void)
 #if HAVE_IPV6
   + simple (3, NUMERICHOSTV6, SERV1)
 #endif
+#if !defined __GLIBC__
+  /* avoid glibc bug, possibly
+  */
   + simple (3, HOST1, SERV1)
   + simple (3, HOST2, SERV2)
   + simple (3, HOST3, SERV3)
   + simple (3, HOST4, SERV4)
+#endif
   + simple (4, HOST1, SERV1)
   + simple (4, HOST1, "80")
   + simple (4, HOST2, SERV2)






Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-17 Thread Bruno Haible via Gnulib discussion list
> 2025-02-17  Bruno Haible  
> 
>   getaddrinfo tests: Make failures more verbose.
>   * tests/test-getaddrinfo.c (simple): Print some info before returning 1.

Now the test failure produces this info:

FAIL: test-getaddrinfo
==

Test case pass=3, host=www.gnu.org, service=http failed: expected EAI_NONAME, 
got -8
Test case pass=3, host=www.ibm.com, service=https failed: expected EAI_NONAME, 
got -8
Test case pass=3, host=microsoft.com, service=http failed: expected EAI_NONAME, 
got -8
Test case pass=3, host=google.org, service=ldap failed: expected EAI_NONAME, 
got -8
FAIL test-getaddrinfo (exit status: 4)

Where -8 is EAI_SERVICE. This is on a Debian 12 system.

This failure makes no sense to me. Any idea?

Bruno






Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-16 Thread Bruno Haible via Gnulib discussion list
> @@ -187,9 +192,13 @@ int main (void)
>(void) gl_sockets_startup (SOCKETS_1_1);
>  
>return (  simple (1, HOST1, SERV1)
> +  + simple (1, HOST1, "80")
>+ simple (1, HOST2, SERV2)
> +  + simple (1, HOST2, "443")
>+ simple (1, HOST3, SERV3)
> +  + simple (1, HOST3, "80")
>+ simple (1, HOST4, SERV4)
> +  + simple (1, HOST4, "389")
>+ simple (2, HOST1, SERV1)
>+ simple (2, HOST2, SERV2)
>+ simple (2, HOST3, SERV3)
> @@ -203,5 +212,13 @@ int main (void)
>+ simple (3, HOST1, SERV1)
>+ simple (3, HOST2, SERV2)
>+ simple (3, HOST3, SERV3)
> -  + simple (3, HOST4, SERV4));
> +  + simple (3, HOST4, SERV4)
> +  + simple (4, HOST1, SERV1)
> +  + simple (4, HOST1, "80")
> +  + simple (4, HOST2, SERV2)
> +  + simple (4, HOST2, "443")
> +  + simple (4, HOST3, SERV3)
> +  + simple (4, HOST3, "80")
> +  + simple (4, HOST4, SERV4)
> +  + simple (4, HOST4, "389"));
>  }

The CI reports a failure like this:


FAIL: test-getaddrinfo
==

FAIL test-getaddrinfo (exit status: 4)


"exit status: 4" only tells us that 4 among the added tests failed, but not
which ones. Let me add more info, for the next run.


2025-02-17  Bruno Haible  

getaddrinfo tests: Make failures more verbose.
* tests/test-getaddrinfo.c (simple): Print some info before returning 1.

diff --git a/tests/test-getaddrinfo.c b/tests/test-getaddrinfo.c
index 31e999cb0e..4485d7dd10 100644
--- a/tests/test-getaddrinfo.c
+++ b/tests/test-getaddrinfo.c
@@ -95,11 +95,19 @@ simple (int pass, char const *host, char const *service)
 
   dbgprintf ("res %d: %s\n", res, gai_strerror (res));
 
-  if (pass == 3 && ! isdigit (host[0]))
-return res != EAI_NONAME;
-
-  if (pass == 4 && ! isdigit (service[0]))
-return res != EAI_NONAME;
+  if ((pass == 3 && ! isdigit (host[0]))
+  || (pass == 4 && ! isdigit (service[0])))
+{
+  if (res != EAI_NONAME)
+{
+  fprintf (stderr,
+   "Test case pass=%d, host=%s, service=%s failed: "
+   "expected EAI_NONAME, got %d\n",
+   pass, host, service, res);
+  return 1;
+}
+  return 0;
+}
 
   if (res != 0)
 {
@@ -130,6 +138,10 @@ simple (int pass, char const *host, char const *service)
   if (res == EAI_SYSTEM)
 fprintf (stderr, "system error: %s\n", strerror (err));
 
+  fprintf (stderr,
+   "Test case pass=%d, host=%s, service=%s failed: "
+   "expected 0, got %d\n",
+   pass, host, service, res);
   return 1;
 }
 






Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-13 Thread Bruno Haible via Gnulib discussion list
> > It looks like REPLACE_GETADDRINFO ought to be 0, not 1. Can you try
> > this patch, please?
> 
> Thanks, it works!

Thanks for the confirmation. I committed the fix (with proper indentation).

Bruno






Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-13 Thread KO Myung-Hun



Bruno Haible wrote:
> KO Myung-Hun wrote:
>> S["REPLACE_GETADDRINFO"]="1"
>> S["HAVE_DECL_GETADDRINFO"]="0"
>> D["HAVE_GETADDRINFO"]=" 0"
>> D["HAVE_DECL_GETADDRINFO"]=" 0"
> 
> It looks like REPLACE_GETADDRINFO ought to be 0, not 1. Can you try
> this patch, please?
> 

Thanks, it works!

-- 
KO Myung-Hun

Korean OS/2 User Community : https://www.os2.kr/



Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-13 Thread KO Myung-Hun



Bruno Haible wrote:
> KO Myung-Hun wrote:
>> I've pulled the latest gnulib. And I've got the following error when
>> testing getaddrinfo module:
>>
>> ./../gllib/netdb.h:745:1: error: 'getaddrinfo' was not declared in this
>> scope
> 
> What's the result of
>   $ grep -i getaddrinfo config.status
> 
> Bruno
> 

Here it is:

ac_pwd='F:/lang/work/gnulib/gnulib.git/testdir-getaddrinfo'
S["GL_GNULIB_GETADDRINFO"]="1"
S["GL_COND_OBJ_GETADDRINFO_FALSE"]="#"
S["GL_COND_OBJ_GETADDRINFO_TRUE"]=""
S["GETADDRINFO_LIB"]=""
S["REPLACE_GETADDRINFO"]="1"
S["HAVE_DECL_GETADDRINFO"]="0"
S["install_sh"]="${SHELL}
F:/lang/work/gnulib/gnulib.git/testdir-getaddrinfo/build-aux/install-sh"
S["MAKEINFO"]="${SHELL}
'F:/lang/work/gnulib/gnulib.git/testdir-getaddrinfo/build-aux/missing'
makeinfo"
S["AUTOHEADER"]="${SHELL}
'F:/lang/work/gnulib/gnulib.git/testdir-getaddrinfo/build-aux/missing'
autoheader"
S["AUTOMAKE"]="${SHELL}
'F:/lang/work/gnulib/gnulib.git/testdir-getaddrinfo/build-aux/missing'
automake-1.17"
S["AUTOCONF"]="${SHELL}
'F:/lang/work/gnulib/gnulib.git/testdir-getaddrinfo/build-aux/missing'
autoconf"
S["ACLOCAL"]="${SHELL}
'F:/lang/work/gnulib/gnulib.git/testdir-getaddrinfo/build-aux/missing'
aclocal-1.17"
D["HAVE_GETADDRINFO"]=" 0"
D["HAVE_DECL_GETADDRINFO"]=" 0"
D["GNULIB_TEST_GETADDRINFO"]=" 1"



-- 
KO Myung-Hun

Korean OS/2 User Community : https://www.os2.kr/



Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-13 Thread Bruno Haible via Gnulib discussion list
KO Myung-Hun wrote:
> S["REPLACE_GETADDRINFO"]="1"
> S["HAVE_DECL_GETADDRINFO"]="0"
> D["HAVE_GETADDRINFO"]=" 0"
> D["HAVE_DECL_GETADDRINFO"]=" 0"

It looks like REPLACE_GETADDRINFO ought to be 0, not 1. Can you try
this patch, please?

diff --git a/m4/getaddrinfo.m4 b/m4/getaddrinfo.m4
index 19ae42cc15..9fa815efb9 100644
--- a/m4/getaddrinfo.m4
+++ b/m4/getaddrinfo.m4
@@ -89,6 +89,7 @@ AC_DEFUN([gl_GETADDRINFO]
   HAVE_GETADDRINFO=0
 fi
   fi
+  if test $HAVE_GETADDRINFO != 0; then
   AC_CACHE_CHECK([whether getaddrinfo supports AI_NUMERICSERV],
 [gl_cv_func_getaddrinfo_works],
 [AC_RUN_IFELSE(
@@ -127,6 +128,7 @@ AC_DEFUN([gl_GETADDRINFO]
 *yes) ;;
 *) REPLACE_GETADDRINFO=1 ;;
   esac
+  fi
   AC_DEFINE_UNQUOTED([HAVE_GETADDRINFO], [$HAVE_GETADDRINFO],
 [Define to 1 if getaddrinfo exists, or to 0 otherwise.])
 







Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-13 Thread Bruno Haible via Gnulib discussion list
KO Myung-Hun wrote:
> I've pulled the latest gnulib. And I've got the following error when
> testing getaddrinfo module:
> 
> ./../gllib/netdb.h:745:1: error: 'getaddrinfo' was not declared in this
> scope

What's the result of
  $ grep -i getaddrinfo config.status

Bruno






Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-13 Thread KO Myung-Hun
Hi/2.

Bruno Haible wrote:
> Testing reveals that getaddrinfo does not support AI_NUMERICSERV on mingw.
> This patch adds the support for it.
> 
> 
> 2025-02-12  Bruno Haible  
> 
>   getaddrinfo: Support the AI_NUMERICSERV flag.
>   * m4/getaddrinfo.m4 (gl_GETADDRINFO): Require AC_CANONICAL_HOST. Test
>   whether getaddrinfo supports AI_NUMERICSERV.
>   * lib/getaddrinfo.c (getaddrinfo): Accept and implement the
>   AI_NUMERICSERV flag.
>   * tests/test-getaddrinfo.c (simple): In pass 4, pass the AI_NUMERICSERV
>   flag.
>   (main): Test numeric services in pass 1. Add pass 4.
>   * doc/posix-functions/getaddrinfo.texi: Mention the native Windows bug.
> 

I've pulled the latest gnulib. And I've got the following error when
testing getaddrinfo module:

-
g++ -DHAVE_CONFIG_H -I. -I..  -DGNULIB_STRICT_CHECKING=1
-DIN_GNULIB_TESTS=1 -I. -I. -I.. -I./.. -I../gllib -I./../gllib
-Wno-error -g -O2 -MT test-netinet_in-h-c++.o -MD -MP -MF
.deps/test-netinet_in-h-c++.Tpo -c -o test-netinet_in-h-c++.o
test-netinet_in-h-c++.cc
In file included from ./../gllib/netdb.h:47,
 from ../gllib/netdb.h:33,
 from test-netdb-h-c++.cc:22:
./../gllib/netdb.h:745:1: error: 'getaddrinfo' was not declared in this
scope; did you mean 'gnulib::getaddrinfo'?
  745 | _GL_CXXALIASWARN (getaddrinfo);
  | ^~~~
./../gllib/netdb.h:725:1: note: 'gnulib::getaddrinfo' declared here
  725 | _GL_CXXALIAS_RPL (getaddrinfo, int,
  | ^~~~
./../gllib/netdb.h:765:1: error: 'freeaddrinfo' was not declared in this
scope; did you mean 'gnulib::freeaddrinfo'?
  765 | _GL_CXXALIASWARN (freeaddrinfo);
  | ^~~~
./../gllib/netdb.h:757:1: note: 'gnulib::freeaddrinfo' declared here
  757 | _GL_CXXALIAS_RPL (freeaddrinfo, void, (struct addrinfo *ai));
  | ^~~~
make[4]: *** [Makefile:3189: test-netdb-h-c++.o] Error 1
-

-- 
KO Myung-Hun

Korean OS/2 User Community : https://www.os2.kr/



Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-12 Thread Bruno Haible via Gnulib discussion list
Testing reveals that getaddrinfo does not support AI_NUMERICSERV on mingw.
This patch adds the support for it.


2025-02-12  Bruno Haible  

getaddrinfo: Support the AI_NUMERICSERV flag.
* m4/getaddrinfo.m4 (gl_GETADDRINFO): Require AC_CANONICAL_HOST. Test
whether getaddrinfo supports AI_NUMERICSERV.
* lib/getaddrinfo.c (getaddrinfo): Accept and implement the
AI_NUMERICSERV flag.
* tests/test-getaddrinfo.c (simple): In pass 4, pass the AI_NUMERICSERV
flag.
(main): Test numeric services in pass 1. Add pass 4.
* doc/posix-functions/getaddrinfo.texi: Mention the native Windows bug.

diff --git a/doc/posix-functions/getaddrinfo.texi 
b/doc/posix-functions/getaddrinfo.texi
index 4038bf7349..dd216d23d8 100644
--- a/doc/posix-functions/getaddrinfo.texi
+++ b/doc/posix-functions/getaddrinfo.texi
@@ -13,11 +13,14 @@
 This function is missing on some platforms:
 HP-UX 11.11, Cygwin 1.5.x, mingw, MSVC 14.
 @item
-On Windows, this function is declared in @code{} rather than in
-@code{}.
+On native Windows, this function is declared in @code{}
+rather than in @code{}.
 @item
-On Windows, in 32-bit mode, this function is defined with a calling convention
-that is different from @code{cdecl}.
+On native Windows, this function does not support
+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}.
 @end itemize
 
 Portability problems not fixed by Gnulib:
diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c
index 4a0aeab9f1..a8c45c21c2 100644
--- a/lib/getaddrinfo.c
+++ b/lib/getaddrinfo.c
@@ -54,7 +54,7 @@
 
 #if HAVE_GETADDRINFO
 
-/* Override with cdecl calling convention.  */
+/* Override with cdecl calling convention and mingw fix.  */
 
 int
 getaddrinfo (const char *restrict nodename,
@@ -63,6 +63,10 @@ getaddrinfo (const char *restrict nodename,
  struct addrinfo **restrict res)
 # undef getaddrinfo
 {
+  if (hints && (hints->ai_flags & AI_NUMERICSERV) != 0
+  && servname && !(*servname >= '0' && *servname <= '9'))
+return EAI_NONAME;
+
   return getaddrinfo (nodename, servname, hints, res);
 }
 
@@ -237,10 +241,17 @@ getaddrinfo (const char *restrict nodename,
 
 # ifdef WINDOWS_NATIVE
   if (use_win32_p ())
-return getaddrinfo_ptr (nodename, servname, hints, res);
+{
+  if (hints && (hints->ai_flags & AI_NUMERICSERV) != 0
+  && servname && !(*servname >= '0' && *servname <= '9'))
+return EAI_NONAME;
+  return getaddrinfo_ptr (nodename, servname, hints, res);
+}
 # endif
 
-  if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE|AI_NUMERICHOST)))
+  if (hints
+  && (hints->ai_flags
+  & ~(AI_CANONNAME | AI_PASSIVE | AI_NUMERICHOST | AI_NUMERICSERV)))
 /* FIXME: Support more flags. */
 return EAI_BADFLAGS;
 
diff --git a/m4/getaddrinfo.m4 b/m4/getaddrinfo.m4
index 1e1fc48a59..19ae42cc15 100644
--- a/m4/getaddrinfo.m4
+++ b/m4/getaddrinfo.m4
@@ -1,5 +1,5 @@
 # getaddrinfo.m4
-# serial 35
+# serial 36
 dnl Copyright (C) 2004-2025 Free Software Foundation, Inc.
 dnl This file is free software; the Free Software Foundation
 dnl gives unlimited permission to copy and/or distribute it,
@@ -10,6 +10,7 @@ AC_DEFUN([gl_GETADDRINFO]
 [
   AC_REQUIRE([gl_SYS_SOCKET_H])dnl for HAVE_SYS_SOCKET_H, HAVE_WINSOCK2_H
   AC_REQUIRE([gl_NETDB_H])dnl for HAVE_NETDB_H
+  AC_REQUIRE([AC_CANONICAL_HOST])
   GETADDRINFO_LIB=
   gai_saved_LIBS="$LIBS"
 
@@ -88,6 +89,44 @@ AC_DEFUN([gl_GETADDRINFO]
   HAVE_GETADDRINFO=0
 fi
   fi
+  AC_CACHE_CHECK([whether getaddrinfo supports AI_NUMERICSERV],
+[gl_cv_func_getaddrinfo_works],
+[AC_RUN_IFELSE(
+   [AC_LANG_PROGRAM([[
+#include 
+#ifdef HAVE_SYS_SOCKET_H
+#include 
+#endif
+#ifdef HAVE_NETDB_H
+#include 
+#endif
+#ifdef HAVE_WS2TCPIP_H
+#include 
+#endif
+#include 
+#include 
+  ]], [[
+  struct addrinfo hints;
+  struct addrinfo ai;
+  memset (&hints, 0, sizeof (hints));
+  hints.ai_flags = AI_NUMERICSERV;
+  return getaddrinfo ("www.gnu.org", "http", &hints, &ai) != 
EAI_NONAME;
+  ]])
+   ],
+   [gl_cv_func_getaddrinfo_works=yes],
+   [gl_cv_func_getaddrinfo_works=no],
+   [case "$host_os" in
+ # Guess no on native Windows.
+  mingw* | windows*) gl_cv_func_getaddrinfo_works="guessing no" ;;
+ # Guess yes otherwise.
+  *) gl_cv_func_getaddrinfo_works="guessing yes" ;;
+esac
+   ])
+])
+  case "$gl_cv_func_getaddrinfo_works" in
+*yes) ;;
+*) REPLACE_GETADDRINFO=1 ;;
+  esac
   AC_DEFINE_UNQUOTED([HAVE_GETADDRINFO], [$HAVE_GETADDRINFO],
 [Define to 1 if getaddrinfo exists, or to 0 otherwise.])
 
diff --git a/tests/test-getaddrinfo.c b/tests/test-getaddrinfo.c
index 8f35e6abc6..31e999cb0e 100644
--- a/tests/test-getaddrinfo.c
++

Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-12 Thread Bruno Haible via Gnulib discussion list
KO Myung-Hun wrote:
> +  if (hints && (hints->ai_flags & AI_NUMERICHOST))
> +{
> +  int valid = 0;
> +
> +# ifdef HAVE_IPV6
> +  valid |= !valid &&
> +   (hints->ai_family == AF_INET6 ||
> +hints->ai_family == AF_UNSPEC) &&
> +   inet_pton (AF_INET6, nodename, &addr6) == 1;
> +# endif
> +# ifdef HAVE_IPV4
> +  valid |= !valid &&
> +   (hints->ai_family == AF_INET ||
> +hints->ai_family == AF_UNSPEC) &&
> +   inet_pton (AF_INET, nodename, &addr4) == 1;
> +# endif
> +  if (!valid)
> +return EAI_NONAME;
> +}

The logic seems right, but is hard to understand when written in this way.
With a separate function, it becomes much clearer.

>if (res == EAI_NONAME)
> -return 0;
> +return (flags & (AI_NUMERICHOST | AI_NUMERICSERV)) ? 2 : 0;

This does only part of the necessary checks.

I prefer to commit this patch. Tested on a glibc system, with
'gl_cv_func_getaddrinfo=no ./configure ...'


2025-02-12  Bruno Haible  

getaddrinfo: Support the AI_NUMERICHOST flag.
* lib/getaddrinfo.c (is_numeric_host): New function.
(getaddrinfo): Accept and implement the AI_NUMERICHOST flag.
* modules/getaddrinfo (Depends-on): Add inet_pton.
* tests/test-getaddrinfo.c: Include .
(simple): In pass 3, pass the AI_NUMERICHOST flag.
(main): Add a pass 3.

diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c
index cd045c5121..4a0aeab9f1 100644
--- a/lib/getaddrinfo.c
+++ b/lib/getaddrinfo.c
@@ -169,16 +169,43 @@ validate_family (int family)
 {
   /* FIXME: Support more families. */
 # if HAVE_IPV4
- if (family == PF_INET)
-   return true;
+   if (family == PF_INET)
+ return true;
 # endif
 # if HAVE_IPV6
- if (family == PF_INET6)
-   return true;
+   if (family == PF_INET6)
+ return true;
 # endif
- if (family == PF_UNSPEC)
-   return true;
- return false;
+   if (family == PF_UNSPEC)
+ return true;
+   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
@@ -213,7 +240,7 @@ getaddrinfo (const char *restrict nodename,
 return getaddrinfo_ptr (nodename, servname, hints, res);
 # endif
 
-  if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE)))
+  if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE|AI_NUMERICHOST)))
 /* FIXME: Support more flags. */
 return EAI_BADFLAGS;
 
@@ -225,12 +252,18 @@ getaddrinfo (const char *restrict nodename,
 /* FIXME: Support other socktype. */
 return EAI_SOCKTYPE; /* FIXME: Better return code? */
 
-  if (!nodename)
+  if (nodename != NULL)
+{
+  if (hints && (hints->ai_flags & AI_NUMERICHOST) != 0
+  && !is_numeric_host (nodename, hints->ai_family))
+return EAI_NONAME;
+}
+  else
 {
   if (!(hints->ai_flags & AI_PASSIVE))
 return EAI_NONAME;
 
-# ifdef HAVE_IPV6
+# if HAVE_IPV6
   nodename = (hints->ai_family == AF_INET6) ? "::" : "0.0.0.0";
 # else
   nodename = "0.0.0.0";
diff --git a/modules/getaddrinfo b/modules/getaddrinfo
index b31d395635..265886e6c0 100644
--- a/modules/getaddrinfo
+++ b/modules/getaddrinfo
@@ -13,6 +13,7 @@ extensions
 gettext-h   [test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1 
|| test $HAVE_DECL_GAI_STRERROR = 0 || test $REPLACE_GAI_STRERROR = 1]
 gnulib-i18n [test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1 
|| test $HAVE_DECL_GAI_STRERROR = 0 || test $REPLACE_GAI_STRERROR = 1]
 inet_ntop   [test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1]
+inet_pton   [test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1]
 snprintf[test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1]
 bool[test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1]
 strdup  [test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1]
diff --git a/tests/test-getaddrinfo.c b/tests/test-getaddrinfo.c
index d09c4c1a24..8f35e6abc6 100644
--- a/tests/test-getaddrinfo.c
+++ b/tests/test-getaddrinfo.c
@@ -34,6 +34,7 @@ SIGNATURE_CHECK (getaddrinfo, int, (char

Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-12 Thread Bruno Haible via Gnulib discussion list
KO Myung-Hun wrote:
> -  res = getaddrinfo (host, service, NULL, &ai0);
> +  res = getaddrinfo (host, service, &hints, &ai0);

This removes a useful test, namely whether getaddrinfo() works with a
NULL hints pointer. The proper way to fix this test is like this:


2025-02-12  Bruno Haible  

getaddrinfo tests: Test both a NULL and a non-NULL hints argument.
* tests/test-getaddrinfo.c (simple): Add a 'pass' argument.
(main): Make two passes of 'simple' invocations.

diff --git a/tests/test-getaddrinfo.c b/tests/test-getaddrinfo.c
index 968e0052dc..d09c4c1a24 100644
--- a/tests/test-getaddrinfo.c
+++ b/tests/test-getaddrinfo.c
@@ -60,11 +60,12 @@ SIGNATURE_CHECK (getaddrinfo, int, (char const *, char 
const *,
 #endif
 
 static int
-simple (char const *host, char const *service)
+simple (int pass, char const *host, char const *service)
 {
   char buf[BUFSIZ];
   static int skip = 0;
   struct addrinfo hints;
+  struct addrinfo *hints_p;
   struct addrinfo *ai0, *ai;
   int res;
   int err;
@@ -75,14 +76,18 @@ simple (char const *host, char const *service)
 
   dbgprintf ("Finding %s service %s...\n", host, service);
 
-  /* This initializes "hints" but does not use it.  Is there a reason
- for this?  If so, please fix this comment.  */
-  memset (&hints, 0, sizeof (hints));
-  hints.ai_flags = AI_CANONNAME;
-  hints.ai_family = AF_UNSPEC;
-  hints.ai_socktype = SOCK_STREAM;
+  if (pass == 1)
+hints_p = NULL;
+  else
+{
+  memset (&hints, 0, sizeof (hints));
+  hints.ai_flags = AI_CANONNAME;
+  hints.ai_family = AF_UNSPEC;
+  hints.ai_socktype = SOCK_STREAM;
+  hints_p = &hints;
+}
 
-  res = getaddrinfo (host, service, NULL, &ai0);
+  res = getaddrinfo (host, service, hints_p, &ai0);
   err = errno;
 
   dbgprintf ("res %d: %s\n", res, gai_strerror (res));
@@ -171,8 +176,12 @@ int main (void)
 {
   (void) gl_sockets_startup (SOCKETS_1_1);
 
-  return simple (HOST1, SERV1)
-+ simple (HOST2, SERV2)
-+ simple (HOST3, SERV3)
-+ simple (HOST4, SERV4);
+  return (  simple (1, HOST1, SERV1)
+  + simple (1, HOST2, SERV2)
+  + simple (1, HOST3, SERV3)
+  + simple (1, HOST4, SERV4)
+  + simple (2, HOST1, SERV1)
+  + simple (2, HOST2, SERV2)
+  + simple (2, HOST3, SERV3)
+  + simple (2, HOST4, SERV4));
 }






Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-12 Thread Bruno Haible via Gnulib discussion list
KO Myung-Hun wrote:
> diff --git a/lib/netdb.in.h b/lib/netdb.in.h
> index e8ba8f0978..9cad2d937a 100644
> --- a/lib/netdb.in.h
> +++ b/lib/netdb.in.h
> @@ -103,7 +103,7 @@ struct addrinfo
>  #  define AI_NUMERICSERV0x0400  /* Don't use name resolution.  */
>  # endif
>  
> -# if 0
> +# ifndef AI_NUMERICHOST
>  #  define AI_NUMERICHOST0x0004  /* Don't use name resolution.  */
>  # endif

This lacks test and documentation. Let me start by adding that, consistently.


2025-02-12  Bruno Haible  

netdb-h: Ensure AI_NUMERICHOST and AI_NUMERICSERV are defined.
* lib/netdb.in.h (AI_NUMERICHOST): New macro.
* tests/test-netdb-h.c: Verify that AI_NUMERICHOST and AI_NUMERICSERV
are defined.
* doc/posix-headers/netdb.texi: Mention the platform support for
AI_NUMERICHOST and AI_NUMERICSERV.

diff --git a/doc/posix-headers/netdb.texi b/doc/posix-headers/netdb.texi
index aaaf05b23f..be1d8491c3 100644
--- a/doc/posix-headers/netdb.texi
+++ b/doc/posix-headers/netdb.texi
@@ -25,6 +25,14 @@
 This header file does not define @code{AI_ADDRCONFIG} on some platforms:
 NetBSD 5.0.
 
+@item
+This header file does not define @code{AI_NUMERICHOST} on some platforms:
+HP-UX 11.11.
+
+@item
+This header file does not define @code{AI_NUMERICSERV} on some platforms:
+macOS 10.5, HP-UX 11.11, mingw.
+
 @item
 @c Defined in RFC 2553.
 This header file incorrectly defines @code{NI_MAXHOST} on some platforms:
diff --git a/lib/netdb.in.h b/lib/netdb.in.h
index e8ba8f0978..22059ea044 100644
--- a/lib/netdb.in.h
+++ b/lib/netdb.in.h
@@ -99,12 +99,11 @@ struct addrinfo
 # ifndef AI_CANONNAME
 #  define AI_CANONNAME  0x0002  /* Request for canonical name.  */
 # endif
-# ifndef AI_NUMERICSERV
-#  define AI_NUMERICSERV0x0400  /* Don't use name resolution.  */
+# ifndef AI_NUMERICHOST
+#  define AI_NUMERICHOST 0x0004  /* Return numeric host address as name.  */
 # endif
-
-# if 0
-#  define AI_NUMERICHOST0x0004  /* Don't use name resolution.  */
+# 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
diff --git a/tests/test-netdb-h.c b/tests/test-netdb-h.c
index cebd54855a..d2be1c8cc9 100644
--- a/tests/test-netdb-h.c
+++ b/tests/test-netdb-h.c
@@ -29,6 +29,9 @@ struct hostent t1;
 /* Check that the 'socklen_t' type is defined.  */
 socklen_t t2;
 
+int ai1 = AI_NUMERICHOST;
+int ai2 = AI_NUMERICSERV;
+
 int
 main (void)
 {






Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-12 Thread KO Myung-Hun
Hi/2.

Bruno Haible wrote:
> KO Myung-Hun wrote:
>> These are the patches to support AI_NUMERICSERV and AI_NUMERICHOST flag
>> to getaddrinfo().
>>
>> Review, please...
>>
>> [PATCH 1/2] getaddrinfo: Add AI_NUMERICSERV to the supported flags
>> [PATCH 2/2] getaddrinfo: Add AI_NUMERICHOST flag support
> 
> Your patches don't contain actual portable support for these flags
> (on platforms where the native function does not implement it).
> 
> POSIX [1] specifies the meaning of these two flags. So, if you encountered
> a program which uses them, that is OK and I have no objection to Gnulib
> supporting them.
> 
> But the way to do so is in several steps, for each of the flags:
>   1) Prepare a patch to tests/test-getaddrinfo.c that verifies the behaviour
>  of the flag.
>   2) Send us this patch, so that we can run the modified test on many
>  platforms (including native Windows).
>  Also, run the modified test yourself, on OS/2.
>   3) Then it will be clear which parts of lib/getaddrinfo.c need to be 
> extended.
> 
> Bruno
> 
> [1] 
> https://pubs.opengroup.org/onlinepubs/9799919799/functions/getaddrinfo.html
> 

Done.

-- 
KO Myung-Hun

Korean OS/2 User Community : https://www.os2.kr/
From e9de288c29df326e552f70de269192494bc2d57a Mon Sep 17 00:00:00 2001
From: KO Myung-Hun 
Date: Mon, 10 Feb 2025 20:39:05 +0900
Subject: [PATCH v2] getaddrinfo: Supports AI_NUMERICHOST and AI_NUMERICSERV
 flags

* lib/getaddrinfo.c (getaddrinfo): Add AI_NUMERICHOST and AI_NUMERICSERV
as supported flags.
* lib/netdb.in.h: Define AI_NUMERICHOST if not defined yet.
* modules/getaddrinfo (Depends-on): Add inet_pton module.
* tests/test-getaddrinfo.c: Add tests for AI_NUMERICHOST and
AI_NUMERICSERV flags.
---
 lib/getaddrinfo.c| 26 +-
 lib/netdb.in.h   |  2 +-
 modules/getaddrinfo  |  1 +
 tests/test-getaddrinfo.c | 34 ++
 4 files changed, 53 insertions(+), 10 deletions(-)

diff --git a/lib/getaddrinfo.c b/lib/getaddrinfo.c
index cd045c5121..03a93f311d 100644
--- a/lib/getaddrinfo.c
+++ b/lib/getaddrinfo.c
@@ -200,12 +200,14 @@ getaddrinfo (const char *restrict nodename,
 struct addrinfo addrinfo;
 struct sockaddr_in6 sockaddr_in6;
   };
+  struct in6_addr addr6;
 # endif
 # if HAVE_IPV4
   struct v4_pair {
 struct addrinfo addrinfo;
 struct sockaddr_in sockaddr_in;
   };
+  struct in_addr addr4;
 # endif
 
 # ifdef WINDOWS_NATIVE
@@ -213,7 +215,8 @@ getaddrinfo (const char *restrict nodename,
 return getaddrinfo_ptr (nodename, servname, hints, res);
 # endif
 
-  if (hints && (hints->ai_flags & ~(AI_CANONNAME|AI_PASSIVE)))
+  if (hints && (hints->ai_flags &
+~(AI_CANONNAME|AI_PASSIVE|AI_NUMERICHOST|AI_NUMERICSERV)))
 /* FIXME: Support more flags. */
 return EAI_BADFLAGS;
 
@@ -237,6 +240,26 @@ getaddrinfo (const char *restrict nodename,
 # endif
 }
 
+  if (hints && (hints->ai_flags & AI_NUMERICHOST))
+{
+  int valid = 0;
+
+# ifdef HAVE_IPV6
+  valid |= !valid &&
+   (hints->ai_family == AF_INET6 ||
+hints->ai_family == AF_UNSPEC) &&
+   inet_pton (AF_INET6, nodename, &addr6) == 1;
+# endif
+# ifdef HAVE_IPV4
+  valid |= !valid &&
+   (hints->ai_family == AF_INET ||
+hints->ai_family == AF_UNSPEC) &&
+   inet_pton (AF_INET, nodename, &addr4) == 1;
+# endif
+  if (!valid)
+return EAI_NONAME;
+}
+
   if (servname)
 {
   struct servent *se = NULL;
@@ -261,6 +284,7 @@ getaddrinfo (const char *restrict nodename,
 port = se->s_port;
 }
 
+  /* FIXME: Assume gethostbyname can accept a numeric address string. */
   /* FIXME: Use gethostbyname_r if available. */
   he = gethostbyname (nodename);
   if (!he || he->h_addr_list[0] == NULL)
diff --git a/lib/netdb.in.h b/lib/netdb.in.h
index e8ba8f0978..9cad2d937a 100644
--- a/lib/netdb.in.h
+++ b/lib/netdb.in.h
@@ -103,7 +103,7 @@ struct addrinfo
 #  define AI_NUMERICSERV0x0400  /* Don't use name resolution.  */
 # endif
 
-# if 0
+# ifndef AI_NUMERICHOST
 #  define AI_NUMERICHOST0x0004  /* Don't use name resolution.  */
 # endif
 
diff --git a/modules/getaddrinfo b/modules/getaddrinfo
index b31d395635..265886e6c0 100644
--- a/modules/getaddrinfo
+++ b/modules/getaddrinfo
@@ -13,6 +13,7 @@ extensions
 gettext-h   [test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1 || test $HAVE_DECL_GAI_STRERROR = 0 || test $REPLACE_GAI_STRERROR = 1]
 gnulib-i18n [test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1 || test $HAVE_DECL_GAI_STRERROR = 0 || test $REPLACE_GAI_STRERROR = 1]
 inet_ntop   [test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1]
+inet_pton   [test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1]
 snprintf[test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1]
 bool[test $HAVE_GETADDRINFO = 0 || test $REPLACE_GETADDRINFO = 1]
 strdup  

Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-10 Thread KO Myung-Hun
Hi/2.

Bruno Haible wrote:
> KO Myung-Hun wrote:
>> These are the patches to support AI_NUMERICSERV and AI_NUMERICHOST flag
>> to getaddrinfo().
>>
>> Review, please...
>>
>> [PATCH 1/2] getaddrinfo: Add AI_NUMERICSERV to the supported flags
>> [PATCH 2/2] getaddrinfo: Add AI_NUMERICHOST flag support
> 
> Your patches don't contain actual portable support for these flags
> (on platforms where the native function does not implement it).
> 

In case of AI_NUMERICSERV, getaddrinfo.c already has codes for it.
In case of AI_NUMERICHOST, gethostbyname() will do it. But, some error
checks are necessary.

> POSIX [1] specifies the meaning of these two flags. So, if you encountered
> a program which uses them, that is OK and I have no objection to Gnulib
> supporting them.
> 
> But the way to do so is in several steps, for each of the flags:
>   1) Prepare a patch to tests/test-getaddrinfo.c that verifies the behaviour
>  of the flag.
>   2) Send us this patch, so that we can run the modified test on many
>  platforms (including native Windows).
>  Also, run the modified test yourself, on OS/2.
>   3) Then it will be clear which parts of lib/getaddrinfo.c need to be 
> extended.
> 
> Bruno
> 
> [1] 
> https://pubs.opengroup.org/onlinepubs/9799919799/functions/getaddrinfo.html
> 
> 

Ok, I'll try.

Thanks!

-- 
KO Myung-Hun

Korean OS/2 User Community : https://www.os2.kr/



Re: [PATCH 0/2] getaddrinfo: Add AI_NUMERICSERV and AI_NUMERICHOST flag support

2025-02-10 Thread Bruno Haible via Gnulib discussion list
KO Myung-Hun wrote:
> These are the patches to support AI_NUMERICSERV and AI_NUMERICHOST flag
> to getaddrinfo().
> 
> Review, please...
> 
> [PATCH 1/2] getaddrinfo: Add AI_NUMERICSERV to the supported flags
> [PATCH 2/2] getaddrinfo: Add AI_NUMERICHOST flag support

Your patches don't contain actual portable support for these flags
(on platforms where the native function does not implement it).

POSIX [1] specifies the meaning of these two flags. So, if you encountered
a program which uses them, that is OK and I have no objection to Gnulib
supporting them.

But the way to do so is in several steps, for each of the flags:
  1) Prepare a patch to tests/test-getaddrinfo.c that verifies the behaviour
 of the flag.
  2) Send us this patch, so that we can run the modified test on many
 platforms (including native Windows).
 Also, run the modified test yourself, on OS/2.
  3) Then it will be clear which parts of lib/getaddrinfo.c need to be extended.

Bruno

[1] https://pubs.opengroup.org/onlinepubs/9799919799/functions/getaddrinfo.html