OSSP CVS Repository

ossp - Check-in [3181]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3181
Date: 2003-Feb-07 21:47:51 (local)
2003-Feb-07 20:47:51 (UTC)
User:rse
Branch:
Comment: Add internal address resolving support via the new IEEE Std 1003.1g-2000 ("POSIX.1") getaddrinfo(3) API. This especially provides more portable IPv6 address resolving.
Tickets:
Inspections:
Files:
ossp-pkg/sa/ChangeLog      1.23 -> 1.24     7 inserted, 0 deleted
ossp-pkg/sa/TODO      1.47 -> 1.48     0 inserted, 7 deleted
ossp-pkg/sa/sa.ac      1.13 -> 1.14     1 inserted, 1 deleted
ossp-pkg/sa/sa.c      1.73 -> 1.74     37 inserted, 1 deleted
ossp-pkg/sa/sa_test.c      1.24 -> 1.25     22 inserted, 13 deleted

ossp-pkg/sa/ChangeLog 1.23 -> 1.24

--- ChangeLog    2003/01/31 18:58:18     1.23
+++ ChangeLog    2003/02/07 20:47:51     1.24
@@ -11,6 +11,13 @@
   This is a list of all changes to OSSP sa.
   For a more brief summary please have a look at the NEWS file.
 
+  Changes between 1.0.5 and 1.1.0 (31-Jan-2003 to xx-Feb-2003)
+
+   o Added internal address resolving support via the new IEEE Std
+     1003.1g-2000 ("POSIX.1") getaddrinfo(3) API. This especially
+     provides more portable IPv6 address resolving.
+     [Ralf S. Engelschall <rse@engelschall.com>]
+
   Changes between 1.0.4 and 1.0.5 (28-Jan-2003 to 31-Jan-2003)
 
    o Fixed test suite library (ts.c): the ts_suite_free()


ossp-pkg/sa/TODO 1.47 -> 1.48

--- TODO 2002/11/07 13:05:43     1.47
+++ TODO 2003/02/07 20:47:51     1.48
@@ -33,13 +33,6 @@
   o Consistently use PF_XXX instead of AF_XXX whenever not directly
     address related things are done in order to even closer conform to POSIX.
 
-  o Support for newer DNS Resolving Functions.
-
-    In IPv6 land there are usually the newer DNS resolving functions
-    getaddrinfo(3) and getnameinfo(3). Perhaps we should support these in
-    favor of gethostbyname(3) and gethostbyaddr(3) because the chance is
-    higher that they support IPv6 in case we are in IPv6 land.
-
   o DNS Resolving and multiple results.
 
     On DNS resolving name, multiple result addresses can be returned.  Either


ossp-pkg/sa/sa.ac 1.13 -> 1.14

--- sa.ac        2003/01/06 13:11:23     1.13
+++ sa.ac        2003/02/07 20:47:51     1.14
@@ -72,7 +72,7 @@
     AC_CHECK_HEADERS(string.h sys/types.h sys/socket.h netdb.h netinet/in.h)
 
     #   check for system functions
-    AC_CHECK_FUNCS(inet_addr inet_aton inet_pton inet_ntoa inet_ntop snprintf)
+    AC_CHECK_FUNCS(inet_addr inet_aton inet_pton inet_ntoa inet_ntop snprintf getaddrinfo)
 
     dnl # check for network/socket size type
     SA_CHECK_TYPEDEF(socklen_t, sys/socket.h)


ossp-pkg/sa/sa.c 1.73 -> 1.74

--- sa.c 2003/01/06 13:11:23     1.73
+++ sa.c 2003/02/07 20:47:51     1.74
@@ -252,6 +252,7 @@
     ((tv).tv_sec == 0 && (tv).tv_usec == 0)
 
 /* convert Internet address from presentation to network format */
+#ifndef HAVE_GETADDRINFO
 static int sa_inet_pton(int family, const char *strptr, void *addrptr)
 {
 #ifdef HAVE_INET_PTON
@@ -278,6 +279,7 @@
     return 0;
 #endif
 }
+#endif /* !HAVE_GETADDRINFO */
 
 /* convert Internet address from network to presentation format */
 static const char *sa_inet_ntop(int family, const void *src, char *dst, size_t size)
@@ -481,13 +483,19 @@
     socklen_t sl;
     struct sockaddr *sa;
     struct sockaddr_un un;
+#ifdef HAVE_GETADDRINFO
+    struct addrinfo ai_hints;
+    struct addrinfo *ai = NULL;
+    int err;
+#else
     struct sockaddr_in sa4;
 #ifdef AF_INET6
     struct sockaddr_in6 sa6;
 #endif
-    int bIPv6;
     struct hostent *he;
+#endif
     struct servent *se;
+    int bIPv6;
     int bNumeric;
     char *cpHost;
     char *cpPort;
@@ -598,6 +606,28 @@
             nPort = ntohs(se->s_port);
         }
 
+#ifdef HAVE_GETADDRINFO
+        memset(&ai_hints, 0, sizeof(ai_hints));
+        ai_hints.ai_family = PF_UNSPEC;
+        if ((err = getaddrinfo(cpHost, NULL, &ai_hints, &ai)) != 0) {
+            if (err == EAI_MEMORY)
+                return SA_RC(SA_ERR_MEM);
+            else if (err == EAI_SYSTEM)
+                return SA_RC(SA_ERR_SYS);
+            else
+                return SA_RC(SA_ERR_ARG);
+        }
+        sa = ai->ai_addr;
+        sl = ai->ai_addrlen;
+        sf = ai->ai_family;
+        if (sf == AF_INET)
+            ((struct sockaddr_in *)sa)->sin_port = htons(nPort);
+        else if (sf == AF_INET6)
+            ((struct sockaddr_in6 *)sa)->sin6_port = htons(nPort);
+        else
+            return SA_RC(SA_ERR_ARG);
+#else /* !HAVE_GETADDRINFO */
+
         /* mandatory(!) socket address structure initialization */
         memset(&sa4, 0, sizeof(sa4));
 #ifdef AF_INET6
@@ -648,6 +678,7 @@
         }
         else
             return SA_RC(SA_ERR_ARG);
+#endif /* !HAVE_GETADDRINFO */
     }
     else
         return SA_RC(SA_ERR_ARG);
@@ -661,6 +692,11 @@
     saa->slBuf = sl;
     saa->nFamily = (int)sf;
 
+#ifdef HAVE_GETADDRINFO
+    if (ai != NULL)
+        freeaddrinfo(ai);
+#endif
+
     return SA_OK;
 }
 


ossp-pkg/sa/sa_test.c 1.24 -> 1.25

--- sa_test.c    2003/01/31 18:34:06     1.24
+++ sa_test.c    2003/02/07 20:47:51     1.25
@@ -56,18 +56,19 @@
         char *in;
         sa_rc_t rv;
         char *out;
+        char *out_alt;
     } table[] = {
         /* positive tests */
-        { "inet://0.0.0.0:0", SA_OK, "inet://0.0.0.0:0" },
-        { "inet://127.0.0.1:514", SA_OK, "inet://127.0.0.1:514" },
-        { "inet://localhost:syslog#udp", SA_OK, "inet://127.0.0.1:514" },
-        { "inet://localhost:smtp", SA_OK, "inet://127.0.0.1:25" },
-        { "unix:/tmp/socket", SA_OK, "unix:/tmp/socket" },
+        { "inet://0.0.0.0:0", SA_OK, "inet://0.0.0.0:0", NULL },
+        { "inet://127.0.0.1:514", SA_OK, "inet://127.0.0.1:514", NULL },
+        { "inet://localhost:syslog#udp", SA_OK, "inet://127.0.0.1:514", "inet://[::1]:514" },
+        { "inet://localhost:smtp", SA_OK, "inet://127.0.0.1:25", "inet://[::1]:25" },
+        { "unix:/tmp/socket", SA_OK, "unix:/tmp/socket", NULL },
         /* negative tests */
-        { "inet:", SA_ERR_ARG, NULL },
-        { "inet://1.2.3.4.5:0", SA_ERR_ARG, NULL },
-        { "inet://just-hostname", SA_ERR_ARG, NULL },
-        { "unix:", SA_ERR_ARG, NULL }
+        { "inet:", SA_ERR_ARG, NULL, NULL },
+        { "inet://1.2.3.4.5:0", SA_ERR_ARG, NULL, NULL },
+        { "inet://just-hostname", SA_ERR_ARG, NULL, NULL },
+        { "unix:", SA_ERR_ARG, NULL, NULL }
     };
 
     ts_test_check(TS_CTX, "sa_addr_create");
@@ -83,10 +84,18 @@
         if ((rv = sa_addr_a2u(saa, &cp)) != SA_OK)
             ts_test_fail(TS_CTX, "sa_addr_u2a -> %d[%s] (expected %d[%s])",
                          rv, sa_error(rv), SA_OK, sa_error(SA_OK));
-        if (table[i].rv == SA_OK)
-            if (strcmp(cp, table[i].out) != 0)
-                ts_test_fail(TS_CTX, "sa_addr_a2u -> \"%s\" (expected \"%s\")",
-                             cp, table[i].out);
+        if (table[i].rv == SA_OK) {
+            if (table[i].out_alt != NULL) {
+                if (strcmp(cp, table[i].out) != 0 && strcmp(cp, table[i].out_alt) != 0)
+                    ts_test_fail(TS_CTX, "sa_addr_a2u -> \"%s\" (expected \"%s\" or \"%s\")",
+                                 cp, table[i].out, table[i].out_alt);
+            }
+            else {
+                if (strcmp(cp, table[i].out) != 0)
+                    ts_test_fail(TS_CTX, "sa_addr_a2u -> \"%s\" (expected \"%s\")",
+                                 cp, table[i].out);
+            }
+        }
     }
     ts_test_check(TS_CTX, "sa_addr_destroy");
     if ((rv = sa_addr_destroy(saa)) != SA_OK)

CVSTrac 2.0.1