From 63d59c896674ac9f386fe9dd13dce2316cf27db6 Mon Sep 17 00:00:00 2001 From: Raymond Lai Date: Fri, 29 Sep 2023 23:17:08 +0800 Subject: [PATCH] Force return IPv4 address when probing network interface for listening address Fixes #3928. --- .../main/java/com/amaze/filemanager/utils/NetworkUtil.kt | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/app/src/main/java/com/amaze/filemanager/utils/NetworkUtil.kt b/app/src/main/java/com/amaze/filemanager/utils/NetworkUtil.kt index 8bf5b4b4d6..ea501ea752 100644 --- a/app/src/main/java/com/amaze/filemanager/utils/NetworkUtil.kt +++ b/app/src/main/java/com/amaze/filemanager/utils/NetworkUtil.kt @@ -28,6 +28,7 @@ import android.net.wifi.WifiManager import android.os.Build import org.slf4j.Logger import org.slf4j.LoggerFactory +import java.net.Inet4Address import java.net.InetAddress import java.net.NetworkInterface import java.net.UnknownHostException @@ -97,7 +98,7 @@ object NetworkUtil { /** * Determine device's IP address. * - * Caveat: doesn't handle IPv6 addresses well. + * Caveat: doesn't handle IPv6 addresses well. Forcing return IPv4 if possible. */ @JvmStatic fun getLocalInetAddress(context: Context): InetAddress? { @@ -115,7 +116,8 @@ object NetworkUtil { netinterface.inetAddresses.iterator().forEach { address -> // this is the condition that sometimes gives problems if (!address.isLoopbackAddress && - !address.isLinkLocalAddress + !address.isLinkLocalAddress && + address is Inet4Address ) { return address }