]> git.ipfire.org Git - thirdparty/gnulib.git/commitdiff
getaddrinfo tests: Test both a NULL and a non-NULL hints argument.
authorBruno Haible <bruno@clisp.org>
Wed, 12 Feb 2025 18:05:20 +0000 (19:05 +0100)
committerBruno Haible <bruno@clisp.org>
Wed, 12 Feb 2025 18:05:20 +0000 (19:05 +0100)
* tests/test-getaddrinfo.c (simple): Add a 'pass' argument.
(main): Make two passes of 'simple' invocations.

ChangeLog
tests/test-getaddrinfo.c

index f842861f913e10596e0d8a7e1ae542ef79df7f1e..70d5334434a735879dce68c2add2650f13d0b8bf 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,9 @@
+2025-02-12  Bruno Haible  <bruno@clisp.org>
+
+       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.
+
 2025-02-12  Bruno Haible  <bruno@clisp.org>
 
        netdb-h: Ensure AI_NUMERICHOST and AI_NUMERICSERV are defined.
index 968e0052dc4beca84a401be593cd1baf8d22612d..d09c4c1a2410231404c813b7ce8b8b1de7276918 100644 (file)
@@ -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));
 }