diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp index 1becf3accbe..30d2377a040 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 *r_addresses) const { SOCKADDR_IN *ipv4 = reinterpret_cast(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(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 *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 *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/socket_helpers.h b/drivers/unix/socket_helpers.h index 8e54afcdba5..5fa727a9b92 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) { diff --git a/editor/editor_export.cpp b/editor/editor_export.cpp index 3774c8d4c38..cb1b958cca9 100644 --- a/editor/editor_export.cpp +++ b/editor/editor_export.cpp @@ -210,7 +210,7 @@ EditorExportPreset::EditorExportPreset() { void EditorExportPlatform::gen_debug_flags(Vector &r_flags, int p_flags) { - String host = EditorSettings::get_singleton()->get("network/debug_host"); + String host = EditorSettings::get_singleton()->get("network/debug/remote_host"); if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) host = "localhost"; @@ -620,7 +620,7 @@ Error EditorExportPlatform::save_zip(const Ref &p_preset, co void EditorExportPlatform::gen_export_flags(Vector &r_flags, int p_flags) { - String host = EditorSettings::get_singleton()->get("network/debug_host"); + String host = EditorSettings::get_singleton()->get("network/debug/remote_host"); if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST) host = "localhost"; @@ -2108,7 +2108,7 @@ static int _get_pad(int p_alignment, int p_n) { void EditorExportPlatform::gen_export_flags(Vector &r_flags, int p_flags) { - String host = EditorSettings::get_singleton()->get("network/debug_host"); + String host = EditorSettings::get_singleton()->get("network/debug/remote_host"); if (p_flags&EXPORT_REMOTE_DEBUG_LOCALHOST) host="localhost"; diff --git a/editor/editor_run.cpp b/editor/editor_run.cpp index d36b8cece5b..e0ebe985cd6 100644 --- a/editor/editor_run.cpp +++ b/editor/editor_run.cpp @@ -41,6 +41,7 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li List args; String resource_path = GlobalConfig::get_singleton()->get_resource_path(); + String remote_host = EditorSettings::get_singleton()->get("network/debug/remote_host"); if (resource_path != "") { args.push_back("-path"); @@ -49,7 +50,7 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li if (true) { args.push_back("-rdebug"); - args.push_back("localhost:" + String::num(GLOBAL_GET("network/debug/remote_port"))); + args.push_back(remote_host + ":" + String::num(GLOBAL_GET("network/debug/remote_port"))); } args.push_back("-epid"); diff --git a/editor/editor_settings.cpp b/editor/editor_settings.cpp index 9fd76590a66..0a46acddb2d 100644 --- a/editor/editor_settings.cpp +++ b/editor/editor_settings.cpp @@ -407,13 +407,12 @@ void EditorSettings::setup_network() { IP::get_singleton()->get_local_addresses(&local_ip); String lip; String hint; - String current = has("network/debug_host") ? get("network/debug_host") : ""; + String current = has("network/debug/remote_host") ? get("network/debug/remote_host") : ""; + int port = has("network/debug/remote_port") ? (int)get("network/debug/remote_port") : 6007; for (List::Element *E = local_ip.front(); E; E = E->next()) { String ip = E->get(); - if (ip == "127.0.0.1") - continue; if (lip == "") lip = ip; @@ -424,8 +423,11 @@ void EditorSettings::setup_network() { hint += ip; } - set("network/debug_host", lip); - add_property_hint(PropertyInfo(Variant::STRING, "network/debug_host", PROPERTY_HINT_ENUM, hint)); + set("network/debug/remote_host", lip); + add_property_hint(PropertyInfo(Variant::STRING, "network/debug/remote_host", PROPERTY_HINT_ENUM, hint)); + + set("network/debug/remote_port", port); + add_property_hint(PropertyInfo(Variant::INT, "network/debug/remote_port", PROPERTY_HINT_RANGE, "1,65535,1")); } void EditorSettings::save() { diff --git a/main/main.cpp b/main/main.cpp index 33095e85993..ea7d8e075cb 100644 --- a/main/main.cpp +++ b/main/main.cpp @@ -588,8 +588,9 @@ Error Main::setup(const char *execpath, int argc, char *argv[], bool p_second_ph ScriptDebuggerRemote *sdr = memnew(ScriptDebuggerRemote); uint16_t debug_port = GLOBAL_GET("network/debug/remote_port"); if (debug_host.find(":") != -1) { - debug_port = debug_host.get_slicec(':', 1).to_int(); - debug_host = debug_host.get_slicec(':', 0); + int sep_pos = debug_host.find_last(":"); + debug_port = debug_host.substr(sep_pos + 1, debug_host.length()).to_int(); + debug_host = debug_host.substr(0, sep_pos); } Error derr = sdr->connect_to_host(debug_host, debug_port);