summaryrefslogtreecommitdiff
path: root/drivers/unix
diff options
context:
space:
mode:
authorFabio Alessandrelli <fabio.alessandrelli@gmail.com>2016-12-01 05:05:44 +0100
committerFabio Alessandrelli <fabio.alessandrelli@gmail.com>2016-12-09 18:24:59 +0100
commit4d90a4fcd5fcdca42df47062f94a1fa4e5635a94 (patch)
treea6c34254184674d532ce6ec1663ac72f1278426a /drivers/unix
parent9200da58e4c2498c833d9f2505600c7049e80940 (diff)
Move V6ONLY flag selection inside helpers
Diffstat (limited to 'drivers/unix')
-rw-r--r--drivers/unix/packet_peer_udp_posix.cpp8
-rw-r--r--drivers/unix/socket_helpers.h8
-rw-r--r--drivers/unix/tcp_server_posix.cpp7
3 files changed, 4 insertions, 19 deletions
diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp
index b1049582c4..44a3e65e00 100644
--- a/drivers/unix/packet_peer_udp_posix.cpp
+++ b/drivers/unix/packet_peer_udp_posix.cpp
@@ -127,14 +127,6 @@ Error PacketPeerUDPPosix::listen(int p_port, int p_recv_buffer_size) {
if (sock == -1 )
return ERR_CANT_CREATE;
- if(ip_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");
- }
- }
-
sockaddr_storage addr = {0};
size_t addr_size = _set_listen_sockaddr(&addr, p_port, ip_type, NULL);
diff --git a/drivers/unix/socket_helpers.h b/drivers/unix/socket_helpers.h
index a860c2f80e..aec4ec8843 100644
--- a/drivers/unix/socket_helpers.h
+++ b/drivers/unix/socket_helpers.h
@@ -78,10 +78,10 @@ static int _socket_create(IP_Address::AddrType p_type, int type, int protocol) {
ERR_FAIL_COND_V( sockfd == -1, -1 );
if(family == AF_INET6) {
- // Ensure IPv4 over IPv6 is enabled
- int no = 0;
- if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&no, sizeof(no)) != 0) {
- WARN_PRINT("Unable to set IPv4 address mapping over IPv6");
+ // Select IPv4 over IPv6 mapping
+ int opt = p_type != IP_Address::TYPE_ANY;
+ if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&opt, sizeof(opt)) != 0) {
+ WARN_PRINT("Unable to set/unset IPv4 address mapping over IPv6");
}
}
diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp
index e6f3614cb5..bf3b7369eb 100644
--- a/drivers/unix/tcp_server_posix.cpp
+++ b/drivers/unix/tcp_server_posix.cpp
@@ -75,13 +75,6 @@ Error TCPServerPosix::listen(uint16_t p_port,const List<String> *p_accepted_host
ERR_FAIL_COND_V(sockfd == -1, FAILED);
- if(ip_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