fix: Certain single-label domain names can only be resolved by InetAddress.getAllByName() but not Network.getAllByName()

This commit is contained in:
Xu Yiming 2025-10-20 01:06:16 +08:00
parent 2d32653f5b
commit a4a3b18551

View File

@ -128,11 +128,11 @@ object LocalResolverImpl : LocalDNSTransport {
// 老版本系统,继续用阻塞的 InetAddress // 老版本系统,继续用阻塞的 InetAddress
try { try {
val u = SagerNet.underlyingNetwork val u = SagerNet.underlyingNetwork
val answer = if (u != null) { val answer = try {
u.getAllByName(domain) u?.getAllByName(domain)
} else { } catch (e: UnknownHostException) {
InetAddress.getAllByName(domain) null
} } ?: InetAddress.getAllByName(domain)
if (answer != null) { if (answer != null) {
ctx.success(answer.mapNotNull { it.hostAddress }.joinToString("\n")) ctx.success(answer.mapNotNull { it.hostAddress }.joinToString("\n"))
} else { } else {