Use all zeros for wtf MAC

This commit is contained in:
Mygod
2019-02-01 21:37:00 +08:00
parent 0de9b55e23
commit 7248193232

View File

@@ -43,7 +43,11 @@ data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: Long, v
.filter { parseNumericAddress(it[ARP_IP_ADDRESS]) == ip && it[ARP_DEVICE] == dev } .filter { parseNumericAddress(it[ARP_IP_ADDRESS]) == ip && it[ARP_DEVICE] == dev }
.map { it[ARP_HW_ADDRESS] } .map { it[ARP_HW_ADDRESS] }
.singleOrNull() ?: "") .singleOrNull() ?: "")
if (lladdr.isEmpty()) return emptyList() val mac = if (lladdr.isEmpty()) {
if (match.groups[4] == null) return emptyList()
Timber.w(IOException("Failed to find MAC address for $line"))
0
} else lladdr.macToLong()
val state = if (match.groupValues[1].isNotEmpty()) State.DELETING else val state = if (match.groupValues[1].isNotEmpty()) State.DELETING else
when (match.groupValues[7]) { when (match.groupValues[7]) {
"", "INCOMPLETE" -> State.INCOMPLETE "", "INCOMPLETE" -> State.INCOMPLETE
@@ -52,13 +56,13 @@ data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: Long, v
"NOARP" -> return emptyList() // skip "NOARP" -> return emptyList() // skip
else -> throw IllegalArgumentException("Unknown state encountered: ${match.groupValues[7]}") else -> throw IllegalArgumentException("Unknown state encountered: ${match.groupValues[7]}")
} }
val result = IpNeighbour(ip, dev, lladdr.macToLong(), state) val result = IpNeighbour(ip, dev, mac, state)
val devParser = devFallback.matchEntire(dev) val devParser = devFallback.matchEntire(dev)
if (devParser != null) try { if (devParser != null) try {
val index = devParser.groupValues[1].toInt() val index = devParser.groupValues[1].toInt()
val iface = NetworkInterface.getByIndex(index) val iface = NetworkInterface.getByIndex(index)
if (iface == null) Timber.w("Failed to find network interface #$index") if (iface == null) Timber.w("Failed to find network interface #$index")
else return listOf(IpNeighbour(ip, iface.name, lladdr.macToLong(), state), result) else return listOf(IpNeighbour(ip, iface.name, mac, state), result)
} catch (_: SocketException) { } } catch (_: SocketException) { }
listOf(result) listOf(result)
} catch (e: Exception) { } catch (e: Exception) {