From: Adam Dickmeiss Date: Wed, 15 May 2013 12:11:21 +0000 (+0200) Subject: COMSTACK: @ uses AF_UNSPEC X-Git-Tag: v4.2.57~1 X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=commitdiff_plain;h=d7971954990c423d60a52030f5dfa78d32003486;hp=8f7c9a27753894afb11d443b1c58419d81251bd1 COMSTACK: @ uses AF_UNSPEC But we prefer AF_INET6 over others when picking a socket. Problem is that some systems has IPV6 support, but we can't create sockets for them, so we pick AF_UNSPEC first. --- diff --git a/src/tcpip.c b/src/tcpip.c index 6bb8a90..e712c0e 100644 --- a/src/tcpip.c +++ b/src/tcpip.c @@ -367,7 +367,7 @@ struct addrinfo *tcpip_getaddrinfo(const char *str, const char *port, if (!strcmp("@", host)) { hints.ai_flags = AI_PASSIVE; - hints.ai_family = AF_INET6; + hints.ai_family = AF_UNSPEC; error = getaddrinfo(0, port, &hints, &res); *ipv6_only = 0; } @@ -463,15 +463,27 @@ void *tcpip_straddr(COMSTACK h, const char *str) int s = -1; for (ai = sp->ai; ai; ai = ai->ai_next) { - s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); - if (s != -1) - break; + if (ai->ai_family == AF_INET6) + { + s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + if (s != -1) + break; + } + } + if (s == -1) + { + for (ai = sp->ai; ai; ai = ai->ai_next) + { + s = socket(ai->ai_family, ai->ai_socktype, ai->ai_protocol); + if (s != -1) + break; + } } if (s == -1) return 0; assert(ai); h->iofile = s; - if (ipv6_only >= 0 && + if (ai->ai_family == AF_INET6 && ipv6_only >= 0 && setsockopt(h->iofile, IPPROTO_IPV6, IPV6_V6ONLY, &ipv6_only, sizeof(ipv6_only)))