diff options
author | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2017-05-08 13:42:43 +0200 |
---|---|---|
committer | Fabio Alessandrelli <fabio.alessandrelli@gmail.com> | 2017-05-08 21:53:23 +0200 |
commit | 020f6a7f2082a6039ce6a5b4410dce47f6ea2607 (patch) | |
tree | df2508c94362d5ac7987e87f529b4ebd06187c0b | |
parent | 304a1f5b5a3ce6975952f5cd22d688a246367790 (diff) |
Socket helpers now fall back to ipv4 on systems where ipv6 is disabled.
-rw-r--r-- | drivers/unix/socket_helpers.h | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/drivers/unix/socket_helpers.h b/drivers/unix/socket_helpers.h index 8e54afcdba..5fa727a9b9 100644 --- a/drivers/unix/socket_helpers.h +++ b/drivers/unix/socket_helpers.h @@ -100,13 +100,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); int family = p_type == IP::TYPE_IPV4 ? AF_INET : AF_INET6; 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); if (family == AF_INET6) { |