X-Git-Url: http://git.indexdata.com/?p=yaz-moved-to-github.git;a=blobdiff_plain;f=src%2Ftcpip.c;h=dcfec86cebd6ca82e67665b3924bbcd4efae6689;hp=c70ff4c90c2c01f33d730d1d66012d52409f1898;hb=4b0e4f2ebac2519c2e8a2034cb200dcd5bf0e532;hpb=0c46d2e66bdeea1600e700124a81a5d0a65d349e diff --git a/src/tcpip.c b/src/tcpip.c index c70ff4c..dcfec86 100644 --- a/src/tcpip.c +++ b/src/tcpip.c @@ -338,7 +338,8 @@ static int ssl_check_error(COMSTACK h, tcpip_state *sp, int res) #if HAVE_GETADDRINFO /* resolve using getaddrinfo */ -struct addrinfo *tcpip_getaddrinfo(const char *str, const char *port) +struct addrinfo *tcpip_getaddrinfo(const char *str, const char *port, + int *ipv6_only) { struct addrinfo hints, *res; int error; @@ -366,18 +367,28 @@ struct addrinfo *tcpip_getaddrinfo(const char *str, const char *port) if (!strcmp("@", host)) { hints.ai_flags = AI_PASSIVE; + hints.ai_family = AF_INET6; + error = getaddrinfo(0, port, &hints, &res); + *ipv6_only = 0; + } + else if (!strcmp("@4", host)) + { + hints.ai_flags = AI_PASSIVE; hints.ai_family = AF_INET; error = getaddrinfo(0, port, &hints, &res); + *ipv6_only = -1; } else if (!strcmp("@6", host)) { hints.ai_flags = AI_PASSIVE; hints.ai_family = AF_INET6; error = getaddrinfo(0, port, &hints, &res); + *ipv6_only = 1; } else { error = getaddrinfo(host, port, &hints, &res); + *ipv6_only = -1; } if (error) return 0; @@ -433,6 +444,7 @@ void *tcpip_straddr(COMSTACK h, const char *str) tcpip_state *sp = (tcpip_state *)h->cprivate; const char *port = "210"; struct addrinfo *ai = 0; + int ipv6_only = 0; if (h->protocol == PROTO_HTTP) { if (h->type == ssl_type) @@ -445,7 +457,7 @@ void *tcpip_straddr(COMSTACK h, const char *str) if (sp->ai) freeaddrinfo(sp->ai); - sp->ai = tcpip_getaddrinfo(str, port); + sp->ai = tcpip_getaddrinfo(str, port, &ipv6_only); if (sp->ai && h->state == CS_ST_UNBND) { int s = -1; @@ -459,7 +471,11 @@ void *tcpip_straddr(COMSTACK h, const char *str) return 0; assert(ai); h->iofile = s; - + if (ipv6_only >= 0 && + setsockopt(h->iofile, + IPPROTO_IPV6, + IPV6_V6ONLY, &ipv6_only, sizeof(ipv6_only))) + return 0; if (!tcpip_set_blocking(h, h->flags)) return 0; } @@ -1350,7 +1366,7 @@ void tcpip_close(COMSTACK h) { #if HAVE_GNUTLS_H if (sp->session) - gnutls_bye(sp->session, GNUTLS_SHUT_RDWR); + gnutls_bye(sp->session, GNUTLS_SHUT_WR); #elif HAVE_OPENSSL_SSL_H if (sp->ssl) {