From c780fed7ff7ff57328dc3386d666468e06ba8b9d Mon Sep 17 00:00:00 2001 From: Mygod Date: Mon, 10 Jun 2019 22:53:24 +0800 Subject: [PATCH] Avoid failing when multiple interface address was found --- mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt index 73979e1b..93460053 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/Routing.kt @@ -11,6 +11,7 @@ import be.mygod.vpnhotspot.room.AppDatabase import be.mygod.vpnhotspot.util.RootSession import be.mygod.vpnhotspot.util.computeIfAbsentCompat import be.mygod.vpnhotspot.widget.SmartSnackbar +import com.crashlytics.android.Crashlytics import kotlinx.coroutines.runBlocking import timber.log.Timber import java.io.IOException @@ -91,7 +92,12 @@ class Routing(private val caller: Any, private val downstream: String) : IpNeigh } private val hostAddress = try { - NetworkInterface.getByName(downstream)!!.interfaceAddresses!!.asSequence().single { it.address is Inet4Address } + val addresses = NetworkInterface.getByName(downstream)!!.interfaceAddresses!! + .filter { it.address is Inet4Address } + if (addresses.size > 1) { + Crashlytics.logException(IllegalArgumentException("More than one addresses was found: $addresses")) + } + addresses.first() } catch (e: Exception) { throw InterfaceNotFoundException(e) }