summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTim Waugh <twaugh@redhat.com>2014-11-12 12:31:51 +0000
committerTim Waugh <twaugh@redhat.com>2014-11-12 12:31:51 +0000
commit6abf3f4c87a0309d5e7d436e4b72d26a08631ebf (patch)
tree22b65b6afbd6840b3ffcb43d7d207038dbef06bc
parent4561f7e9c63c6ca2859da9b9fa75f64a1a8c2a81 (diff)
downloadtigervnc-6abf3f4c87a0309d5e7d436e4b72d26a08631ebf.tar.gz
tigervnc-6abf3f4c87a0309d5e7d436e4b72d26a08631ebf.zip
IPv6 loopback support too.
-rw-r--r--CMakeLists.txt1
-rw-r--r--common/network/TcpSocket.cxx29
-rw-r--r--config.h.in1
3 files changed, 23 insertions, 8 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index 1dcfd9ed..01b14e1f 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -321,6 +321,7 @@ else()
set(CMAKE_EXTRA_INCLUDE_FILES sys/socket.h)
endif()
check_function_exists(inet_aton HAVE_INET_ATON)
+check_function_exists(inet_pton HAVE_INET_PTON)
check_function_exists(getaddrinfo HAVE_GETADDRINFO)
set(CMAKE_EXTRA_INCLUDE_FILES)
set(CMAKE_REQUIRED_LIBRARIES)
diff --git a/common/network/TcpSocket.cxx b/common/network/TcpSocket.cxx
index 052360bb..65a1a993 100644
--- a/common/network/TcpSocket.cxx
+++ b/common/network/TcpSocket.cxx
@@ -356,14 +356,11 @@ TcpListener::TcpListener(const char *listenaddr, int port, bool localhostOnly,
return;
}
- // - localhostOnly will mean "127.0.0.1 only", no IPv6
- bool use_ipv6 = !localhostOnly;
+ bool use_ipv6;
int af;
#ifdef AF_INET6
- if (use_ipv6)
- af = AF_INET6;
- else
- af = AF_INET;
+ use_ipv6 = true;
+ af = AF_INET6;
#else
use_ipv6 = false;
af = AF_INET;
@@ -411,8 +408,24 @@ TcpListener::TcpListener(const char *listenaddr, int port, bool localhostOnly,
memset(&addr6, 0, (sa_len = sizeof(addr6)));
addr6.sin6_family = af;
addr6.sin6_port = htons(port);
- sa = (struct sockaddr *)&addr6;
- } else {
+
+ if (localhostOnly)
+ addr6.sin6_addr = in6addr_loopback;
+ else if (listenaddr != NULL) {
+#ifdef HAVE_INET_PTON
+ if (inet_pton(AF_INET6, listenaddr, &addr6.sin6_addr) != 1)
+ use_ipv6 = false;
+#else
+ // Unable to parse without inet_pton
+ use_ipv6 = false;
+#endif
+ }
+
+ if (use_ipv6)
+ sa = (struct sockaddr *)&addr6;
+ }
+
+ if (!use_ipv6) {
memset(&addr, 0, (sa_len = sizeof(addr)));
addr.sin_family = af;
addr.sin_port = htons(port);
diff --git a/config.h.in b/config.h.in
index a50e723d..490d7f6d 100644
--- a/config.h.in
+++ b/config.h.in
@@ -2,6 +2,7 @@
#define PACKAGE_VERSION "@VERSION@"
#cmakedefine HAVE_INET_ATON
+#cmakedefine HAVE_INET_PTON
#cmakedefine HAVE_GETADDRINFO
#cmakedefine HAVE_GNUTLS_SET_GLOBAL_ERRNO
#cmakedefine HAVE_GNUTLS_SET_ERRNO