Skip to content

Commit

Permalink
Merge pull request #3946 from TeamAmaze/bugfix/3928
Browse files Browse the repository at this point in the history
Force return IPv4 address when probing network interface for listening address
  • Loading branch information
VishalNehra authored Oct 29, 2023
2 parents 4453863 + 63d59c8 commit f6a23f5
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 f6a23f5

Please sign in to comment.