So, I saw that Niels had checked in my code to do IPv6 DNS lookups
with the comment:
    AAAA support for DNS; from Nick Mathewson.

    unfortunately, no regression test

"Oh dear!" I thought. "I'd better write a regression test, just to
prove that my code works."

Turns out, it had a couple of bugs.  This patch fixes those bugs, and
adds a regression test.  It also fixes a small bug in the IPv4 DNS
regression test, which would, if it received N A records, print the
first record N times.

many thanks, and apologies for the bugs,
-- 
Nick Mathewson
=== configure.in
==================================================================
--- configure.in        (revision 11547)
+++ configure.in        (local)
@@ -132,7 +132,7 @@
 AC_HEADER_TIME
 
 dnl Checks for library functions.
-AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep 
getaddrinfo getnameinfo strlcpy)
+AC_CHECK_FUNCS(gettimeofday vasprintf fcntl clock_gettime strtok_r strsep 
getaddrinfo getnameinfo strlcpy inet_ntop)
 
 if test "x$ac_cv_func_clock_gettime" = "xyes"; then
    AC_DEFINE(DNS_USE_CPU_CLOCK_FOR_ID, 1, [Define if clock_gettime is 
available in libc])
=== evdns.c
==================================================================
--- evdns.c     (revision 11547)
+++ evdns.c     (local)
@@ -596,6 +596,7 @@
                                                           req->user_pointer);
                else
                        req->user_callback(err, 0, 0, 0, NULL, 
req->user_pointer);
+                return;
        }
        assert(0);
 }
@@ -1783,7 +1784,7 @@
 
 static int
 search_request_new(int type, const char *const name, int flags, 
evdns_callback_type user_callback, void *user_arg) {
-       assert(type == TYPE_A);
+       assert(type == TYPE_A || type == TYPE_AAAA);
        if ( ((flags & DNS_QUERY_NO_SEARCH) == 0) &&
             global_search_state &&
                 global_search_state->num_domains) {
=== test/regress_dns.c
==================================================================
--- test/regress_dns.c  (revision 11547)
+++ test/regress_dns.c  (local)
@@ -47,6 +47,9 @@
 #include <arpa/inet.h>
 #include <unistd.h>
 #endif
+#ifdef HAVE_NETINET_IN6_H
+#include <netinet/in6.h>
+#endif
 #include <netdb.h>
 #include <fcntl.h>
 #include <stdlib.h>
@@ -72,6 +75,24 @@
        fprintf(stderr, "type: %d, count: %d, ttl: %d: ", type, count, ttl);
 
        switch (type) {
+       case DNS_IPv6_AAAA: {
+#if defined(HAVE_STRUCT_IN6_ADDR) && defined(HAVE_INET_NTOP)
+               struct in6_addr *in6_addrs = addresses;
+               char buf[INET6_ADDRSTRLEN+1];
+               int i;
+               /* a resolution that's not valid does not help */
+               if (ttl < 0)
+                       goto out;
+               for (i = 0; i < count; ++i) {
+                       const char *b = inet_ntop(AF_INET6, &in6_addrs[i], 
buf,sizeof(buf));
+                       if (b)
+                               fprintf(stderr, "%s ", b);
+                       else
+                               fprintf(stderr, "%s ", strerror(errno));
+               }
+#endif
+               break;
+       }
        case DNS_IPv4_A: {
                struct in_addr *in_addrs = addresses;
                int i;
@@ -79,7 +100,7 @@
                if (ttl < 0)
                        goto out;
                for (i = 0; i < count; ++i)
-                       fprintf(stderr, "%s ", inet_ntoa(in_addrs[0]));
+                       fprintf(stderr, "%s ", inet_ntoa(in_addrs[i]));
                break;
        }
        case DNS_PTR:
@@ -93,7 +114,7 @@
                goto out;
        }
 
-       dns_ok = 1;
+       dns_ok = type;
 
 out:
        event_loopexit(NULL);
@@ -107,7 +128,7 @@
        evdns_resolve_ipv4("www.monkey.org", 0, dns_gethostbyname_cb, NULL);
        event_dispatch();
 
-       if (dns_ok) {
+       if (dns_ok == DNS_IPv4_A) {
                fprintf(stdout, "OK\n");
        } else {
                fprintf(stdout, "FAILED\n");
@@ -116,6 +137,22 @@
 }
 
 void
+dns_gethostbyname6()
+{
+       fprintf(stdout, "IPv6 DNS resolve: ");
+       dns_ok = 0;
+       evdns_resolve_ipv6("www.ietf.org", 0, dns_gethostbyname_cb, NULL);
+       event_dispatch();
+
+       if (dns_ok == DNS_IPv6_AAAA) {
+               fprintf(stdout, "OK\n");
+       } else {
+               fprintf(stdout, "FAILED\n");
+               exit(1);
+       }
+}
+
+void
 dns_gethostbyaddr()
 {
        struct in_addr in;
@@ -125,7 +162,7 @@
        evdns_resolve_reverse(&in, 0, dns_gethostbyname_cb, NULL);
        event_dispatch();
 
-       if (dns_ok) {
+       if (dns_ok == DNS_PTR) {
                fprintf(stdout, "OK\n");
        } else {
                fprintf(stdout, "FAILED\n");
@@ -138,6 +175,7 @@
 {
        evdns_init();
        dns_gethostbyname();
+       dns_gethostbyname6();
        dns_gethostbyaddr();
 
        evdns_shutdown(0);

Attachment: pgpK6qhX2JnPn.pgp
Description: PGP signature

_______________________________________________
Libevent-users mailing list
Libevent-users@monkey.org
http://monkey.org/mailman/listinfo/libevent-users

Reply via email to