TCP/UDP Listen sockets can now be set to IPv6 only

This commit is contained in:
Fabio Alessandrelli
2016-10-28 23:11:53 +02:00
parent 2f1c859272
commit eb27e993f0
6 changed files with 50 additions and 8 deletions

View File

@ -69,6 +69,14 @@ Error TCPServerWinsock::listen(uint16_t p_port, IP_Address::AddrType p_type,cons
sockfd = _socket_create(p_type, SOCK_STREAM, IPPROTO_TCP);
ERR_FAIL_COND_V(sockfd == INVALID_SOCKET, 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");
}
}
unsigned long par = 1;
if (ioctlsocket(sockfd, FIONBIO, &par)) {
perror("setting non-block mode");