Android: fix unicast discovery address resolution

This commit is contained in:
Peter Steinberger
2025-12-17 15:32:07 +01:00
parent 036bdde764
commit f5ab3e41c5

View File

@@ -168,9 +168,8 @@ class BridgeDiscovery(
val targetName = stripTrailingDot(srv.target.toString()) val targetName = stripTrailingDot(srv.target.toString())
val host = val host =
try { try {
InetAddress.getAllByName(targetName) val addrs = InetAddress.getAllByName(targetName).mapNotNull { it.hostAddress }
.map { it.hostAddress } addrs.firstOrNull { !it.contains(":") } ?: addrs.firstOrNull()
.firstOrNull { !it.contains(":") } ?: InetAddress.getAllByName(targetName).firstOrNull()?.hostAddress
} catch (_: Throwable) { } catch (_: Throwable) {
null null
} ?: continue } ?: continue
@@ -220,13 +219,13 @@ class BridgeDiscovery(
private fun txtValue(records: List<TXTRecord>, key: String): String? { private fun txtValue(records: List<TXTRecord>, key: String): String? {
val prefix = "$key=" val prefix = "$key="
for (r in records) { for (r in records) {
val strings = val strings: List<String> =
try { try {
r.strings r.strings.mapNotNull { it as? String }
} catch (_: Throwable) { } catch (_: Throwable) {
emptyList() emptyList()
} }
for (s in strings.filterNotNull()) { for (s in strings) {
val trimmed = s.trim() val trimmed = s.trim()
if (trimmed.startsWith(prefix)) { if (trimmed.startsWith(prefix)) {
return trimmed.removePrefix(prefix).trim().ifEmpty { null } return trimmed.removePrefix(prefix).trim().ifEmpty { null }