From 87b892caec352de7a8651fd3a02cc7331e61fee6 Mon Sep 17 00:00:00 2001 From: grendervill Date: Wed, 19 Aug 2026 23:15:10 +0300 Subject: [PATCH] =?UTF-8?q?AeroToss:=20=D0=B8=D1=81=D0=BF=D1=80=D0=B0?= =?UTF-8?q?=D0=B2=D0=BB=D0=B5=D0=BD=20hostAddress=20(127.0.0.1=20=E2=86=92?= =?UTF-8?q?=20192.168.1.107)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - handleDiscoveryRequest теперь возвращает реальный IP через findNetworkAddress() - findNetworkAddress() ищет приватный IPv4 адрес на не-loopback интерфейсе - IP адрес теперь корректно отображается на обоих устройствах --- .../com/aerotoss/discovery/TcpDiscovery.kt | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/app/src/commonMain/kotlin/com/aerotoss/discovery/TcpDiscovery.kt b/app/src/commonMain/kotlin/com/aerotoss/discovery/TcpDiscovery.kt index 5c0f376..a770627 100644 --- a/app/src/commonMain/kotlin/com/aerotoss/discovery/TcpDiscovery.kt +++ b/app/src/commonMain/kotlin/com/aerotoss/discovery/TcpDiscovery.kt @@ -113,7 +113,7 @@ class TcpDiscovery : DiscoveryManager { deviceName = deviceName, deviceType = "desktop", servicePort = servicePort, - hostAddress = sock.localAddress.hostAddress + hostAddress = findNetworkAddress() ) output.write(json.encodeToString(response)) output.newLine() @@ -123,6 +123,24 @@ class TcpDiscovery : DiscoveryManager { } catch (_: Exception) {} } + private fun findNetworkAddress(): String { + return try { + NetworkInterface.getNetworkInterfaces()?.toList() + ?.filter { it.isUp && !it.isLoopback } + ?.flatMap { it.inetAddresses.toList() } + ?.filterIsInstance() + ?.firstOrNull { isPrivate(it) } + ?.hostAddress ?: "127.0.0.1" + } catch (_: Exception) { "127.0.0.1" } + } + + private fun isPrivate(addr: java.net.InetAddress): Boolean { + val bytes = addr.address + return (bytes[0].toInt() and 0xFF == 192 && bytes[1].toInt() and 0xFF == 168) || + (bytes[0].toInt() and 0xFF == 10) || + (bytes[0].toInt() and 0xFF == 172 && (bytes[1].toInt() and 0xFF in 16..31)) + } + private fun sendBroadcast(socket: DatagramSocket, servicePort: Int) { try { val message = "AEROTOSS:$TCP_PORT:$servicePort:$deviceId:$deviceName"