Переглянути джерело

Merge pull request #8699 from Faless/ipv6_disabled

Fix Editor/Debugger connection problems.
Rémi Verschelde 8 роки тому
батько
коміт
5e318493d1

+ 11 - 4
drivers/unix/ip_unix.cpp

@@ -77,7 +77,7 @@ static IP_Address _sockaddr2ip(struct sockaddr *p_addr) {
 	if (p_addr->sa_family == AF_INET) {
 	if (p_addr->sa_family == AF_INET) {
 		struct sockaddr_in *addr = (struct sockaddr_in *)p_addr;
 		struct sockaddr_in *addr = (struct sockaddr_in *)p_addr;
 		ip.set_ipv4((uint8_t *)&(addr->sin_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;
 		struct sockaddr_in6 *addr6 = (struct sockaddr_in6 *)p_addr;
 		ip.set_ipv6(addr6->sin6_addr.s6_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);
 				SOCKADDR_IN *ipv4 = reinterpret_cast<SOCKADDR_IN *>(address->Address.lpSockaddr);
 
 
 				ip.set_ipv4((uint8_t *)&(ipv4->sin_addr));
 				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);
 				SOCKADDR_IN6 *ipv6 = reinterpret_cast<SOCKADDR_IN6 *>(address->Address.lpSockaddr);
 
 
 				ip.set_ipv6(ipv6->sin6_addr.s6_addr);
 				ip.set_ipv6(ipv6->sin6_addr.s6_addr);
+				r_addresses->push_back(ip);
 			};
 			};
 
 
-			r_addresses->push_back(ip);
-
 			address = address->Next;
 			address = address->Next;
 		};
 		};
 		adapter = adapter->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 *ifAddrStruct = NULL;
 	struct ifaddrs *ifa = NULL;
 	struct ifaddrs *ifa = NULL;
+	int family;
 
 
 	getifaddrs(&ifAddrStruct);
 	getifaddrs(&ifAddrStruct);
 
 
@@ -212,6 +214,11 @@ void IP_Unix::get_local_addresses(List<IP_Address> *r_addresses) const {
 		if (!ifa->ifa_addr)
 		if (!ifa->ifa_addr)
 			continue;
 			continue;
 
 
+		family = ifa->ifa_addr->sa_family;
+
+		if (family != AF_INET && family != AF_INET6)
+			continue;
+
 		IP_Address ip = _sockaddr2ip(ifa->ifa_addr);
 		IP_Address ip = _sockaddr2ip(ifa->ifa_addr);
 		r_addresses->push_back(ip);
 		r_addresses->push_back(ip);
 	}
 	}

+ 9 - 1
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);
 	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) {

+ 3 - 3
editor/editor_export.cpp

@@ -210,7 +210,7 @@ EditorExportPreset::EditorExportPreset() {
 
 
 void EditorExportPlatform::gen_debug_flags(Vector<String> &r_flags, int p_flags) {
 void EditorExportPlatform::gen_debug_flags(Vector<String> &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)
 	if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST)
 		host = "localhost";
 		host = "localhost";
@@ -620,7 +620,7 @@ Error EditorExportPlatform::save_zip(const Ref<EditorExportPreset> &p_preset, co
 
 
 void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags) {
 void EditorExportPlatform::gen_export_flags(Vector<String> &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)
 	if (p_flags & DEBUG_FLAG_REMOTE_DEBUG_LOCALHOST)
 		host = "localhost";
 		host = "localhost";
@@ -2108,7 +2108,7 @@ static int _get_pad(int p_alignment, int p_n) {
 
 
 void EditorExportPlatform::gen_export_flags(Vector<String> &r_flags, int p_flags) {
 void EditorExportPlatform::gen_export_flags(Vector<String> &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)
 	if (p_flags&EXPORT_REMOTE_DEBUG_LOCALHOST)
 		host="localhost";
 		host="localhost";

+ 2 - 1
editor/editor_run.cpp

@@ -41,6 +41,7 @@ Error EditorRun::run(const String &p_scene, const String p_custom_args, const Li
 	List<String> args;
 	List<String> args;
 
 
 	String resource_path = GlobalConfig::get_singleton()->get_resource_path();
 	String resource_path = GlobalConfig::get_singleton()->get_resource_path();
+	String remote_host = EditorSettings::get_singleton()->get("network/debug/remote_host");
 
 
 	if (resource_path != "") {
 	if (resource_path != "") {
 		args.push_back("-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) {
 	if (true) {
 		args.push_back("-rdebug");
 		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");
 	args.push_back("-epid");

+ 7 - 5
editor/editor_settings.cpp

@@ -407,13 +407,12 @@ void EditorSettings::setup_network() {
 	IP::get_singleton()->get_local_addresses(&local_ip);
 	IP::get_singleton()->get_local_addresses(&local_ip);
 	String lip;
 	String lip;
 	String hint;
 	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<IP_Address>::Element *E = local_ip.front(); E; E = E->next()) {
 	for (List<IP_Address>::Element *E = local_ip.front(); E; E = E->next()) {
 
 
 		String ip = E->get();
 		String ip = E->get();
-		if (ip == "127.0.0.1")
-			continue;
 
 
 		if (lip == "")
 		if (lip == "")
 			lip = ip;
 			lip = ip;
@@ -424,8 +423,11 @@ void EditorSettings::setup_network() {
 		hint += ip;
 		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() {
 void EditorSettings::save() {

+ 3 - 2
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);
 		ScriptDebuggerRemote *sdr = memnew(ScriptDebuggerRemote);
 		uint16_t debug_port = GLOBAL_GET("network/debug/remote_port");
 		uint16_t debug_port = GLOBAL_GET("network/debug/remote_port");
 		if (debug_host.find(":") != -1) {
 		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);
 		Error derr = sdr->connect_to_host(debug_host, debug_port);