summaryrefslogtreecommitdiffstats
path: root/patches/source/gnutls/gnutls-2.10.5_ipv6.diff
blob: a96b1e629ecadd9dfacc5acf105c57eeee1cd09e (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
From 769faff8029083b43e8c4949ee9d7cd988f7ec01 Mon Sep 17 00:00:00 2001
From: mancha <mancha1@hush.com>
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.10.5.

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
@@ -701,6 +701,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];
@@ -717,6 +722,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)