From 35570716988ba70f28f9580818903437b6409bcb Mon Sep 17 00:00:00 2001 From: Nick Mathewson Date: Sat, 8 May 2010 19:16:47 -0400 Subject: [PATCH] Fix another nasty solaris getaddrinfo() behavior 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 | 24 +++++++++++++++++++++--- 1 file changed, 21 insertions(+), 3 deletions(-) diff --git a/evutil.c b/evutil.c index 5fc90a86..a2476a50 100644 --- 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 -- 2.40.0