From 2040d99b1844c60375e76148ea306637efd53383 Mon Sep 17 00:00:00 2001 From: mancha Date: Sun, 29 Sep 2013 Subject: Fix binding of IPV6 address in gnutls-serv On Linux with /proc/sys/net/ipv6/bindv6only == 0 (which is now the default), gnutls-serv cannot listen on ipv6. Fix adapted for use with GnuTLS 2.8.6. Relevant upstream commits: -------------------------- https://gitorious.org/gnutls/gnutls/commit/1c315602306afc https://gitorious.org/gnutls/gnutls/commit/9c1536d514dd83 --- serv.c | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) --- a/src/serv.c 2013-09-29 +++ b/src/serv.c 2013-09-29 @@ -677,6 +677,11 @@ listen_socket (const char *name, int lis for (ptr = res; ptr != NULL; ptr = ptr->ai_next) { +#ifndef HAVE_IPV6 + if (ptr->ai_family != AF_INET) + continue; +#endif + /* Print what we are doing. */ { char topbuf[512]; @@ -694,6 +699,17 @@ listen_socket (const char *name, int lis continue; } +#if defined(HAVE_IPV6) && !defined(_WIN32) + if (ptr->ai_family == AF_INET6) + { + yes = 1; + /* avoid listen on ipv6 addresses failing + * because already listening on ipv4 addresses: */ + setsockopt (s, IPPROTO_IPV6, IPV6_V6ONLY, + (const void *) &yes, sizeof (yes)); + } +#endif + yes = 1; if (setsockopt (s, SOL_SOCKET, SO_REUSEADDR, (const void *) &yes, sizeof (yes)) < 0)