aboutsummaryrefslogtreecommitdiffstats
path: root/common/network
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 /common/network
parent4561f7e9c63c6ca2859da9b9fa75f64a1a8c2a81 (diff)
downloadtigervnc-6abf3f4c87a0309d5e7d436e4b72d26a08631ebf.tar.gz
tigervnc-6abf3f4c87a0309d5e7d436e4b72d26a08631ebf.zip
IPv6 loopback support too.
Diffstat (limited to 'common/network')
-rw-r--r--common/network/TcpSocket.cxx29
1 files changed, 21 insertions, 8 deletions
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);