Move V6ONLY flag selection inside helpers
This commit is contained in:
parent
9200da58e4
commit
4d90a4fcd5
5 changed files with 4 additions and 35 deletions
|
@ -127,14 +127,6 @@ Error PacketPeerUDPPosix::listen(int p_port, int p_recv_buffer_size) {
|
||||||
if (sock == -1 )
|
if (sock == -1 )
|
||||||
return ERR_CANT_CREATE;
|
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};
|
sockaddr_storage addr = {0};
|
||||||
size_t addr_size = _set_listen_sockaddr(&addr, p_port, ip_type, NULL);
|
size_t addr_size = _set_listen_sockaddr(&addr, p_port, ip_type, NULL);
|
||||||
|
|
||||||
|
|
|
@ -78,10 +78,10 @@ static int _socket_create(IP_Address::AddrType p_type, int type, int protocol) {
|
||||||
ERR_FAIL_COND_V( sockfd == -1, -1 );
|
ERR_FAIL_COND_V( sockfd == -1, -1 );
|
||||||
|
|
||||||
if(family == AF_INET6) {
|
if(family == AF_INET6) {
|
||||||
// Ensure IPv4 over IPv6 is enabled
|
// Select IPv4 over IPv6 mapping
|
||||||
int no = 0;
|
int opt = p_type != IP_Address::TYPE_ANY;
|
||||||
if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&no, sizeof(no)) != 0) {
|
if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&opt, sizeof(opt)) != 0) {
|
||||||
WARN_PRINT("Unable to set IPv4 address mapping over IPv6");
|
WARN_PRINT("Unable to set/unset IPv4 address mapping over IPv6");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -75,13 +75,6 @@ Error TCPServerPosix::listen(uint16_t p_port,const List<String> *p_accepted_host
|
||||||
|
|
||||||
ERR_FAIL_COND_V(sockfd == -1, FAILED);
|
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
|
#ifndef NO_FCNTL
|
||||||
fcntl(sockfd, F_SETFL, O_NONBLOCK);
|
fcntl(sockfd, F_SETFL, O_NONBLOCK);
|
||||||
#else
|
#else
|
||||||
|
|
|
@ -119,14 +119,6 @@ Error PacketPeerUDPWinsock::listen(int p_port, int p_recv_buffer_size) {
|
||||||
if (sock == -1 )
|
if (sock == -1 )
|
||||||
return ERR_CANT_CREATE;
|
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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
struct sockaddr_storage addr = {0};
|
struct sockaddr_storage addr = {0};
|
||||||
size_t addr_size = _set_listen_sockaddr(&addr, p_port, ip_type, NULL);
|
size_t addr_size = _set_listen_sockaddr(&addr, p_port, ip_type, NULL);
|
||||||
|
|
||||||
|
|
|
@ -69,14 +69,6 @@ Error TCPServerWinsock::listen(uint16_t p_port,const List<String> *p_accepted_ho
|
||||||
sockfd = _socket_create(ip_type, SOCK_STREAM, IPPROTO_TCP);
|
sockfd = _socket_create(ip_type, SOCK_STREAM, IPPROTO_TCP);
|
||||||
ERR_FAIL_COND_V(sockfd == INVALID_SOCKET, FAILED);
|
ERR_FAIL_COND_V(sockfd == INVALID_SOCKET, 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");
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
unsigned long par = 1;
|
unsigned long par = 1;
|
||||||
if (ioctlsocket(sockfd, FIONBIO, &par)) {
|
if (ioctlsocket(sockfd, FIONBIO, &par)) {
|
||||||
perror("setting non-block mode");
|
perror("setting non-block mode");
|
||||||
|
|
Loading…
Reference in a new issue