Require complete MacAddressCompat

This commit is contained in:
Mygod
2020-06-05 13:46:48 -04:00
parent e6da1a911e
commit 478ed93a10

View File

@@ -58,11 +58,13 @@ inline class MacAddressCompat(val addr: Long) {
*/
fun fromString(addr: String) = ByteBuffer.allocate(Long.SIZE_BYTES).run {
order(ByteOrder.LITTLE_ENDIAN)
try {
put(addr.split(':').map { Integer.parseInt(it, 16).toByte() }.toByteArray())
val bytes = try {
addr.split(':').map { Integer.parseInt(it, 16).toByte() }.toByteArray()
} catch (e: NumberFormatException) {
throw IllegalArgumentException(e)
}
require(bytes.size == ETHER_ADDR_LEN)
put(bytes)
rewind()
MacAddressCompat(long)
}