Fix getByName returns null

This commit is contained in:
Mygod
2020-07-21 12:42:37 -04:00
committed by GitHub
parent c8d69b6059
commit 4fe1909800

View File

@@ -168,5 +168,5 @@ fun if_nametoindex(ifname: String) = if (Build.VERSION.SDK_INT >= 26) {
} else try {
File("/sys/class/net/$ifname/ifindex").inputStream().bufferedReader().use { it.readLine().toInt() }
} catch (_: FileNotFoundException) {
NetworkInterface.getByName(ifname).index
NetworkInterface.getByName(ifname)?.index ?: 0
}