From 6e7872e7862830b03d458fecaa8fbfa8128d0ef6 Mon Sep 17 00:00:00 2001 From: Cyenoch <1759761439@qq.com> Date: Wed, 11 Mar 2020 22:58:44 +0800 Subject: [PATCH] Addressed an exception that was thrown because InetAddress.getLocalHost().hostAddress might get an ipv6 address --- .../kotlin/net/mamoe/mirai/utils/platformAndroid.kt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/platformAndroid.kt b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/platformAndroid.kt index 54f7f60ba..d1e541de5 100644 --- a/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/platformAndroid.kt +++ b/mirai-core/src/androidMain/kotlin/net/mamoe/mirai/utils/platformAndroid.kt @@ -18,7 +18,7 @@ import kotlinx.io.pool.useInstance import net.mamoe.mirai.utils.io.ByteArrayPool import java.io.ByteArrayOutputStream import java.io.InputStream -import java.net.InetAddress +import java.net.Inet4Address import java.security.MessageDigest import java.util.zip.Deflater import java.util.zip.Inflater @@ -81,7 +81,7 @@ actual object MiraiPlatformUtils { * Localhost 解析 */ actual fun localIpAddress(): String = runCatching { - InetAddress.getLocalHost().hostAddress + Inet4Address.getLocalHost().hostAddress }.getOrElse { "192.168.1.123" } fun md5(stream: InputStream): ByteArray {