Suppress reporting useless entries

This commit is contained in:
Mygod
2020-06-28 05:00:53 +08:00
parent e6f72df814
commit 6095185edf

View File

@@ -74,25 +74,27 @@ data class IpNeighbour(val ip: InetAddress, val dev: String, val lladdr: MacAddr
} }
// use ARP as fallback for IPv4, except for INCOMPLETE which by definition does not have arp entry, // use ARP as fallback for IPv4, except for INCOMPLETE which by definition does not have arp entry,
// or for DELETING, which we do not care about MAC not present // or for DELETING, which we do not care about MAC not present
if (ip is Inet4Address && lladdr == MacAddressCompat.ALL_ZEROS_ADDRESS && state != State.INCOMPLETE && if (lladdr == MacAddressCompat.ALL_ZEROS_ADDRESS && state != State.INCOMPLETE &&
state != State.DELETING) try { state != State.DELETING) {
val list = arp() if (ip is Inet4Address) try {
.asSequence() val list = arp()
.filter { parseNumericAddress(it[ARP_IP_ADDRESS]) == ip && it[ARP_DEVICE] in devs } .asSequence()
.map { it[ARP_HW_ADDRESS] } .filter { parseNumericAddress(it[ARP_IP_ADDRESS]) == ip && it[ARP_DEVICE] in devs }
.distinct() .map { it[ARP_HW_ADDRESS] }
.toList() .distinct()
when (list.size) { .toList()
1 -> lladdr = MacAddressCompat.fromString(list.single()) when (list.size) {
0 -> { } 1 -> lladdr = MacAddressCompat.fromString(list.single())
else -> throw IllegalArgumentException("Unexpected output in arp: ${list.joinToString()}") 0 -> { }
else -> throw IllegalArgumentException("Unexpected output in arp: ${list.joinToString()}")
}
} catch (e: IllegalArgumentException) {
Timber.w(e)
}
if (lladdr == MacAddressCompat.ALL_ZEROS_ADDRESS) {
Timber.d(line)
return emptyList()
} }
} catch (e: IllegalArgumentException) {
Timber.w(e)
}
if (lladdr == MacAddressCompat.ALL_ZEROS_ADDRESS) {
Timber.d(line)
return emptyList()
} }
devs.map { IpNeighbour(ip, it, lladdr, state) } devs.map { IpNeighbour(ip, it, lladdr, state) }
} catch (e: Exception) { } catch (e: Exception) {