From: Tim Waugh Date: Wed, 12 Nov 2014 12:31:51 +0000 (+0000) Subject: IPv6 loopback support too. X-Git-Tag: v1.3.90~5^2~3^2~2 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=6abf3f4c87a0309d5e7d436e4b72d26a08631ebf;p=tigervnc.git IPv6 loopback support too. --- 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