]> git.ipfire.org Git - thirdparty/glibc.git/commitdiff
* posix/Makefile (tests): Add tst-getaddrinfo3.
authorUlrich Drepper <drepper@redhat.com>
Sun, 30 Apr 2006 20:19:09 +0000 (20:19 +0000)
committerUlrich Drepper <drepper@redhat.com>
Sun, 30 Apr 2006 20:19:09 +0000 (20:19 +0000)
* posix/tst-getaddrinfo3.c: New file.

* sysdeps/posix/getaddrinfo.c (gaih_inet): Add parenthesis in test
for better readability.

ChangeLog
posix/Makefile
posix/tst-getaddrinfo3.c [new file with mode: 0644]
sysdeps/posix/getaddrinfo.c

index dfb4bd188d612de0ed523e70763fe162e8ddc961..3760dc71e8c81f041cbf7720796b82d29e1117f6 100644 (file)
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,11 @@
 2006-04-30  Ulrich Drepper  <drepper@redhat.com>
 
+       * posix/Makefile (tests): Add tst-getaddrinfo3.
+       * posix/tst-getaddrinfo3.c: New file.
+
+       * sysdeps/posix/getaddrinfo.c (gaih_inet): Add parenthesis in test
+       for better readability.
+
        * nscd/nscd.h (struct database_dyn): Change filename to an array
        to avoid relocations.
 
index b722f97883c180f2bdc22c2680a6e6fe5828c987..418e1cbe5f5222296652cf535434ef0950642ddf 100644 (file)
@@ -88,7 +88,8 @@ tests         := tstgetopt testfnm runtests runptests      \
                   tst-execvp1 tst-execvp2 tst-execlp1 tst-execlp2 \
                   tst-execv1 tst-execv2 tst-execl1 tst-execl2 \
                   tst-execve1 tst-execve2 tst-execle1 tst-execle2 \
-                  tst-execvp3 tst-execvp4 tst-rfc3484 tst-rfc3484-2
+                  tst-execvp3 tst-execvp4 tst-rfc3484 tst-rfc3484-2 \
+                  tst-getaddrinfo3
 xtests         := bug-ga2
 ifeq (yes,$(build-shared))
 test-srcs      := globtest
diff --git a/posix/tst-getaddrinfo3.c b/posix/tst-getaddrinfo3.c
new file mode 100644 (file)
index 0000000..5077f31
--- /dev/null
@@ -0,0 +1,151 @@
+#include <mcheck.h>
+#include <netdb.h>
+#include <stdio.h>
+#include <string.h>
+#include <arpa/inet.h>
+#include <arpa/nameser.h>
+
+
+static int
+do_test (void)
+{
+  mtrace ();
+
+  int result = 0;
+  struct addrinfo hints;
+  struct addrinfo *ai_res;
+  int s;
+
+#define T(no, fail, addr, fam, coraddr)                                              \
+  s = getaddrinfo (addr, NULL, &hints, &ai_res);                             \
+  if (s != 0)                                                                \
+    {                                                                        \
+      if (s != fail)                                                         \
+       {                                                                     \
+         printf ("getaddrinfo test %d failed: %s\n", no, gai_strerror (s));  \
+         result = 1;                                                         \
+       }                                                                     \
+      ai_res = NULL;                                                         \
+    }                                                                        \
+  else if (fail)                                                             \
+    {                                                                        \
+      printf ("getaddrinfo test %d should have failed but did not\n", no);    \
+      result = 1;                                                            \
+    }                                                                        \
+  else if (ai_res->ai_family != fam)                                         \
+    {                                                                        \
+      printf ("\
+getaddrinfo test %d return address of family %d, expected %d\n",             \
+             no, ai_res->ai_family, fam);                                    \
+      result = 1;                                                            \
+    }                                                                        \
+  else if (fam == AF_INET)                                                   \
+    {                                                                        \
+      if (ai_res->ai_addrlen != sizeof (struct sockaddr_in))                 \
+       {                                                                     \
+         printf ("getaddrinfo test %d: address size %zu, expected %zu\n",    \
+                 no, (size_t) ai_res->ai_addrlen,                            \
+                 sizeof (struct sockaddr_in));                               \
+         result = 1;                                                         \
+       }                                                                     \
+      else if (strcmp (coraddr, \
+                      inet_ntoa (((struct sockaddr_in *) ai_res->ai_addr)->sin_addr))\
+              != 0)                                                          \
+       {                                                                     \
+         printf ("getaddrinfo test %d: got value %s, expected %s\n",         \
+                 no,                                                         \
+                 inet_ntoa (((struct sockaddr_in *) ai_res->ai_addr)->sin_addr), \
+                 coraddr);                                                   \
+         result = 1;                                                         \
+       }                                                                     \
+    }                                                                        \
+  else                                                                       \
+    {                                                                        \
+      char buf[100];                                                         \
+                                                                             \
+      if (ai_res->ai_addrlen != sizeof (struct sockaddr_in6))                \
+       {                                                                     \
+         printf ("getaddrinfo test %d: address size %zu, expected %zu\n",    \
+                 no, (size_t) ai_res->ai_addrlen,                            \
+                 sizeof (struct sockaddr_in6));                              \
+         result = 1;                                                         \
+       }                                                                     \
+      else if (strcmp (coraddr, \
+                      inet_ntop (AF_INET6,                                   \
+                                 &((struct sockaddr_in6 *) ai_res->ai_addr)->sin6_addr,\
+                                 buf, sizeof (buf)))                         \
+              != 0)                                                          \
+       {                                                                     \
+         printf ("getaddrinfo test %d: got value %s, expected %s\n",         \
+                 no,                                                         \
+                 inet_ntop (AF_INET6,                                        \
+                            & ((struct sockaddr_in6 *) ai_res->ai_addr)->sin6_addr, \
+                            buf, sizeof (buf)),                              \
+                 coraddr);                                                   \
+         result = 1;                                                         \
+       }                                                                     \
+    }                                                                        \
+  if (ai_res != NULL && ai_res->ai_next != NULL)                             \
+    {                                                                        \
+      puts ("expected only one result");                                     \
+      result = 1;                                                            \
+    }                                                                        \
+  freeaddrinfo (ai_res)
+
+
+  memset (&hints, '\0', sizeof (hints));
+  hints.ai_family = AF_UNSPEC;
+  hints.ai_socktype = SOCK_STREAM;
+  T (1, 0, "127.0.0.1", AF_INET, "127.0.0.1");
+
+  memset (&hints, '\0', sizeof (hints));
+  hints.ai_family = AF_INET;
+  hints.ai_socktype = SOCK_STREAM;
+  T (2, 0, "127.0.0.1", AF_INET, "127.0.0.1");
+
+  memset (&hints, '\0', sizeof (hints));
+  hints.ai_family = AF_INET6;
+  hints.ai_socktype = SOCK_STREAM;
+  hints.ai_flags = AI_V4MAPPED;
+  T (3, 0, "127.0.0.1", AF_INET6, "::ffff:127.0.0.1");
+
+  memset (&hints, '\0', sizeof (hints));
+  hints.ai_family = AF_INET6;
+  hints.ai_socktype = SOCK_STREAM;
+  T (4, EAI_ADDRFAMILY, "127.0.0.1", AF_INET6, "");
+
+  memset (&hints, '\0', sizeof (hints));
+  hints.ai_family = AF_UNSPEC;
+  hints.ai_socktype = SOCK_STREAM;
+  T (5, 0, "::1", AF_INET6, "::1");
+
+  memset (&hints, '\0', sizeof (hints));
+  hints.ai_family = AF_INET;
+  hints.ai_socktype = SOCK_STREAM;
+  T (6, EAI_ADDRFAMILY, "::1", AF_INET6, "");
+
+  memset (&hints, '\0', sizeof (hints));
+  hints.ai_family = AF_INET6;
+  hints.ai_socktype = SOCK_STREAM;
+  T (7, 0, "::1", AF_INET6, "::1");
+
+  memset (&hints, '\0', sizeof (hints));
+  hints.ai_family = AF_UNSPEC;
+  hints.ai_socktype = SOCK_STREAM;
+  T (8, 0, "::ffff:127.0.0.1", AF_INET6, "::ffff:127.0.0.1");
+
+  memset (&hints, '\0', sizeof (hints));
+  hints.ai_family = AF_INET;
+  hints.ai_socktype = SOCK_STREAM;
+  T (9, 0, "::ffff:127.0.0.1", AF_INET, "127.0.0.1");
+
+  memset (&hints, '\0', sizeof (hints));
+  hints.ai_family = AF_INET6;
+  hints.ai_socktype = SOCK_STREAM;
+  T (10, 0, "::ffff:127.0.0.1", AF_INET6, "::ffff:127.0.0.1");
+
+  return result;
+}
+
+#define TEST_FUNCTION do_test ()
+#include "../test-skeleton.c"
index 03d26086ac68a7503a2badf6d833d0c0d1e46669..fa3bbe44cff9c23d1f181090244dd662e672bab0 100644 (file)
@@ -529,7 +529,7 @@ gaih_inet (const char *name, const struct gaih_service *service,
        {
          if (req->ai_family == AF_UNSPEC || req->ai_family == AF_INET)
            at->family = AF_INET;
-         else if (req->ai_family == AF_INET6 && req->ai_flags & AI_V4MAPPED)
+         else if (req->ai_family == AF_INET6 && (req->ai_flags & AI_V4MAPPED))
            {
              at->addr[3] = at->addr[0];
              at->addr[2] = htonl (0xffff);