diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt index 1570fcb1..f9b5244e 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/MacAddressCompat.kt @@ -56,13 +56,22 @@ inline class MacAddressCompat(val addr: Long) { */ fun fromString(addr: String) = ByteBuffer.allocate(Long.SIZE_BYTES).run { order(ByteOrder.LITTLE_ENDIAN) - val bytes = try { - addr.split(':').map { Integer.parseInt(it, 16).toByte() }.toByteArray() - } catch (e: NumberFormatException) { - throw IllegalArgumentException(e) + var start = 0 + var i = 0 + while (position() < ETHER_ADDR_LEN && start < addr.length) { + val end = i + if (addr.getOrElse(i) { ':' } == ':') ++i else if (i < start + 2) { + ++i + continue + } + put(if (start == end) 0 else try { + Integer.parseInt(addr.substring(start, end), 16).toByte() + } catch (e: NumberFormatException) { + throw IllegalArgumentException(e) + }) + start = i } - require(bytes.size == ETHER_ADDR_LEN) - put(bytes) + require(position() == ETHER_ADDR_LEN) { "MAC address too short" } rewind() MacAddressCompat(long) } diff --git a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApDialogFragment.kt b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApDialogFragment.kt index 7e630d32..0fd804ad 100644 --- a/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApDialogFragment.kt +++ b/mobile/src/main/java/be/mygod/vpnhotspot/net/wifi/WifiApDialogFragment.kt @@ -4,7 +4,6 @@ import android.annotation.SuppressLint import android.annotation.TargetApi import android.content.ClipData import android.content.DialogInterface -import android.net.MacAddress import android.net.wifi.SoftApConfiguration import android.os.Build import android.os.Parcelable @@ -130,9 +129,9 @@ class WifiApDialogFragment : AlertDialogFragment