Fix byte orders in mac address

This commit is contained in:
Mygod
2021-05-19 16:17:04 -04:00
parent 68f8ac5c92
commit 0b6e5e39c0
2 changed files with 19 additions and 25 deletions

View File

@@ -91,12 +91,10 @@ fun makeMacSpan(mac: String) = if (app.hasTouch) SpannableString(mac).apply {
fun NetworkInterface.formatAddresses(macOnly: Boolean = false) = SpannableStringBuilder().apply {
try {
val address = hardwareAddress
if (address != null && try {
MacAddressCompat.fromBytes(address) == MacAddressCompat.ANY_ADDRESS
} catch (_: IllegalArgumentException) { true }) {
appendLine(makeMacSpan(MacAddressCompat.bytesToString(address)))
}
val address = hardwareAddress?.let(MacAddressCompat::fromBytes)
if (address != null && address != MacAddressCompat.ANY_ADDRESS) appendLine(makeMacSpan(address.toString()))
} catch (e: IllegalArgumentException) {
Timber.w(e)
} catch (_: SocketException) { }
if (!macOnly) for (address in interfaceAddresses) {
append(makeIpSpan(address.address))