1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-06 12:20:30 +00:00

Socket helpers now fall back to ipv4 on systems where ipv6 is disabled.

(cherry picked from commit 020f6a7f20)
This commit is contained in:
Fabio Alessandrelli
2017-05-08 13:42:43 +02:00
parent 56e23624bf
commit 0dc62633e6

View File

@@ -71,13 +71,21 @@ static size_t _set_listen_sockaddr(struct sockaddr_storage *p_addr, int p_port,
}; };
}; };
static int _socket_create(IP::Type p_type, int type, int protocol) { static int _socket_create(IP::Type &p_type, int type, int protocol) {
ERR_FAIL_COND_V(p_type > IP::TYPE_ANY || p_type < IP::TYPE_NONE, ERR_INVALID_PARAMETER); ERR_FAIL_COND_V(p_type > IP::TYPE_ANY || p_type < IP::TYPE_NONE, ERR_INVALID_PARAMETER);
int family = p_type == IP::TYPE_IPV4 ? AF_INET : AF_INET6; int family = p_type == IP::TYPE_IPV4 ? AF_INET : AF_INET6;
int sockfd = socket(family, type, protocol); int sockfd = socket(family, type, protocol);
if (sockfd == -1 && p_type == IP::TYPE_ANY) {
// Careful here, changing the referenced parameter so the caller knows that we are using an IPv4 socket
// in place of a dual stack one, and further calls to _set_sock_addr will work as expected.
p_type = IP::TYPE_IPV4;
family = AF_INET;
sockfd = socket(family, type, protocol);
}
ERR_FAIL_COND_V(sockfd == -1, -1); ERR_FAIL_COND_V(sockfd == -1, -1);
if (family == AF_INET6) { if (family == AF_INET6) {