diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2016-10-31 08:00:54 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2016-10-31 08:00:54 +0100 |
commit | 434d120226c31fea9c1ff905c37486d6ed58633a (patch) | |
tree | f3d69229c6c14f8b5e84337b3ac8ad0f470e5548 /drivers/unix/tcp_server_posix.cpp | |
parent | de454318e72f5de13c5a1efff5811d41e360a8a2 (diff) | |
parent | bdc7ca84cac727f3f94663f23e1229450230bd2e (diff) |
Merge pull request #6981 from Faless/ipv6_fix
Use IPv6 dual stack socket by default. Allow restricting IP version for TCP/UDP.
Diffstat (limited to 'drivers/unix/tcp_server_posix.cpp')
-rw-r--r-- | drivers/unix/tcp_server_posix.cpp | 12 |
1 files changed, 10 insertions, 2 deletions
diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp index 05b739804c..7028c1a107 100644 --- a/drivers/unix/tcp_server_posix.cpp +++ b/drivers/unix/tcp_server_posix.cpp @@ -71,9 +71,17 @@ void TCPServerPosix::make_default() { Error TCPServerPosix::listen(uint16_t p_port, IP_Address::AddrType p_type, const List<String> *p_accepted_hosts) { int sockfd; - int family = p_type == IP_Address::TYPE_IPV6 ? AF_INET6 : AF_INET; - sockfd = socket(family, SOCK_STREAM, 0); + sockfd = _socket_create(p_type, SOCK_STREAM, IPPROTO_TCP); + ERR_FAIL_COND_V(sockfd == -1, FAILED); + + if(p_type == IP_Address::TYPE_IPV6) { + // Use IPv6 only socket + int yes = 1; + if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&yes, sizeof(yes)) != 0) { + WARN_PRINT("Unable to unset IPv4 address mapping over IPv6"); + } + } #ifndef NO_FCNTL fcntl(sockfd, F_SETFL, O_NONBLOCK); #else |