Skip to content

Commit

Permalink
Force return IPv4 address when probing network interface for listenin…
Browse files Browse the repository at this point in the history
…g address

Fixes #3928.
  • Loading branch information
TranceLove committed Sep 29, 2023
1 parent 6783e4d commit 63d59c8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions app/src/main/java/com/amaze/filemanager/utils/NetworkUtil.kt
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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? {
Expand All @@ -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
}
Expand Down

0 comments on commit 63d59c8

Please sign in to comment.