diff options
Diffstat (limited to 'drivers/unix')
-rw-r--r-- | drivers/unix/ip_unix.cpp | 15 | ||||
-rw-r--r-- | drivers/unix/packet_peer_udp_posix.cpp | 2 | ||||
-rw-r--r-- | drivers/unix/socket_helpers.h | 10 |
3 files changed, 22 insertions, 5 deletions
diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index 1becf3accb..30d2377a04 100644 --- a/drivers/unix/ip_unix.cpp +++ b/drivers/unix/ip_unix.cpp @@ -77,7 +77,7 @@ static IP_Address _sockaddr2ip(struct sockaddr *p_addr) { if (p_addr->sa_family == AF_INET) { struct sockaddr_in *addr = (struct sockaddr_in *)p_addr; ip.set_ipv4((uint8_t *)&(addr->sin_addr)); - } else { + } else if (p_addr->sa_family == AF_INET6) { struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)p_addr; ip.set_ipv6(addr6->sin6_addr.s6_addr); }; @@ -180,15 +180,16 @@ void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const { SOCKADDR_IN *ipv4 = reinterpret_cast<SOCKADDR_IN *>(address->Address.lpSockaddr); ip.set_ipv4((uint8_t *)&(ipv4->sin_addr)); - } else { // ipv6 + r_addresses->push_back(ip); + + } else if (address->Address.lpSockaddr->sa_family == AF_INET6) { // ipv6 SOCKADDR_IN6 *ipv6 = reinterpret_cast<SOCKADDR_IN6 *>(address->Address.lpSockaddr); ip.set_ipv6(ipv6->sin6_addr.s6_addr); + r_addresses->push_back(ip); }; - r_addresses->push_back(ip); - address = address->Next; }; adapter = adapter->Next; @@ -205,6 +206,7 @@ void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const { struct ifaddrs *ifAddrStruct = NULL; struct ifaddrs *ifa = NULL; + int family; getifaddrs(&ifAddrStruct); @@ -212,6 +214,11 @@ void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const { if (!ifa->ifa_addr) continue; + family = ifa->ifa_addr->sa_family; + + if (family != AF_INET && family != AF_INET6) + continue; + IP_Address ip = _sockaddr2ip(ifa->ifa_addr); r_addresses->push_back(ip); } diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp index 5dbccd4b63..74ceb3946a 100644 --- a/drivers/unix/packet_peer_udp_posix.cpp +++ b/drivers/unix/packet_peer_udp_posix.cpp @@ -216,6 +216,8 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) { len = sizeof(struct sockaddr_storage); ++queue_count; + if (p_wait) + break; }; // TODO: Should ECONNRESET be handled here? 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) { |