summaryrefslogtreecommitdiff
path: root/patches/source/gnutls/gnutls-2.8.6_ipv6.diff
blob: ea32a20ad80b9aee6996c596cb8deba2357d625d (plain)
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 2040d99b1844c60375e76148ea306637efd53383 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.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)