mkEUI64Suffix
lib.mkEUI64Suffix
Docs pulled from | This Revision | 9 minutes ago
Converts a 48-bit MAC address into a EUI-64 IPv6 address suffix.
Example
mkEUI64Suffix "66:75:63:6B:20:75"
=> "6475:63ff:fe6b:2075"
Type
mkEUI64Suffix :: String -> String
Inputs
- mac
- The MAC address (may contain these delimiters:
:,-or.but it's not necessary)
Noogle detected
Implementation
The following is the current implementation of this function.
mkEUI64Suffix =
mac:
pipe mac [
# match mac address
(match "^([0-9A-Fa-f]{2})[-:.]?([0-9A-Fa-f]{2})[-:.]?([0-9A-Fa-f]{2})[-:.]?([0-9A-Fa-f]{2})[-:.]?([0-9A-Fa-f]{2})[-:.]?([0-9A-Fa-f]{2})$")
# check if there are matches
(
matches:
if matches == null then
throw ''"${mac}" is not a valid MAC address (expected 6 octets of hex digits)''
else
matches
)
# transform to result hextets
(octets: [
# combine 1st and 2nd octets into first hextet, flip U/L bit, 512 = 0x200
(toHexString (bitXor 512 (fromHexString ((elemAt octets 0) + (elemAt octets 1)))))
# combine 3rd and 4th octets, combine them, insert fffe pattern in between to get next two hextets
"${elemAt octets 2}ff"
"fe${elemAt octets 3}"
# combine 5th and 6th octets into the last hextet
((elemAt octets 4) + (elemAt octets 5))
])
# concat to result suffix
(concatStringsSep ":")
toLower
];