]> granicus.if.org Git - libevent/commitdiff
Fix another nasty solaris getaddrinfo() behavior
authorNick Mathewson <nickm@torproject.org>
Sat, 8 May 2010 23:16:47 +0000 (19:16 -0400)
committerNick Mathewson <nickm@torproject.org>
Sat, 8 May 2010 23:34:10 +0000 (19:34 -0400)
Everybody else thinks that when you getaddrinfo() on an ip address
and don't specify the protocol and the socktype, it should give you
multiple answers , one for each protocol/socktype implementation.

OpenSolaris takes a funny view of RFC3493, and leaves the results set
to 0.

This patch post-processes the getaddrinfo() results for consistency.

evutil.c

index 5fc90a8637225818758452f8be15ed9c8c991a1f..a2476a50c8e3d9025c6a0f648ede5477af8a8290 100644 (file)
--- a/evutil.c
+++ b/evutil.c
@@ -1055,6 +1055,26 @@ apply_numeric_port_hack(int port, struct evutil_addrinfo **ai)
                }
        }
 }
+
+static void
+apply_socktype_protocol_hack(struct evutil_addrinfo *ai)
+{
+       struct evutil_addrinfo *ai_new;
+       for (; ai; ai = ai->ai_next) {
+               evutil_getaddrinfo_infer_protocols(ai);
+               if (ai->ai_socktype || ai->ai_protocol)
+                       continue;
+               ai_new = mm_malloc(sizeof(*ai_new));
+               memcpy(ai_new, ai, sizeof(*ai_new));
+               ai->ai_socktype = SOCK_STREAM;
+               ai->ai_protocol = IPPROTO_TCP;
+               ai_new->ai_socktype = SOCK_DGRAM;
+               ai_new->ai_protocol = IPPROTO_UDP;
+       
+               ai_new->ai_next = ai->ai_next;
+               ai->ai_next = ai_new;
+       }
+}
 #endif
 
 int
@@ -1144,9 +1164,7 @@ evutil_getaddrinfo(const char *nodename, const char *servname,
                apply_numeric_port_hack(portnum, res);
 
        if (need_socktype_protocol_hack()) {
-               struct evutil_addrinfo *ai;
-               for (ai = *res; ai; ai = ai->ai_next)
-                       evutil_getaddrinfo_infer_protocols(ai);
+               apply_socktype_protocol_hack(*res);
        } 
        return err;
 #else