Mac (net_address v0.3.1) View Source
Mac Address value tool module.
Link to this section Summary
Functions
converts a mac address string and turns it into a proper mac address datatype. Supports standard colon format, BMC hyphen format, and arista/cisco switch dot format.
checks to see if a value is a local mac address, by convention it means it has been assigned by a VM system.
checks to see if a value is a mac address.
checks to see if a value is a local mac address, by convention it means it has been assigned by the hardware manufacturer
generates a mask for the first n bits of the mac address.
generates a random mac address from another, with a mask value
allows you to use the convenient ~m sigil to declare a Mac address in its normal string form, instead of using the tuple form.
Converts a mac address to a string
Link to this section Types
Specs
general mac addresses are six octets.
Link to this section Functions
Specs
converts a mac address string and turns it into a proper mac address datatype. Supports standard colon format, BMC hyphen format, and arista/cisco switch dot format.
iex> Mac.from_string!("06:AA:07:FB:B6:1E")
{0x06, 0xAA, 0x07, 0xFB, 0xB6, 0x1E}
iex> Mac.from_string!("06:aa:07:fb:b6:1e")
{0x06, 0xAA, 0x07, 0xFB, 0xB6, 0x1E}
iex> Mac.from_string!("06-AA-07-FB-B6-1E")
{0x06, 0xAA, 0x07, 0xFB, 0xB6, 0x1E}
iex> Mac.from_string!("06aa.07fb.b61e")
{0x06, 0xAA, 0x07, 0xFB, 0xB6, 0x1E}
Specs
Specs
checks to see if a value is a local mac address, by convention it means it has been assigned by a VM system.
usable in guards.
iex> Mac.is_local_mac({0xF2, 0, 0, 1, 1, 1})
true
iex> Mac.is_local_mac({0xF0, 0, 0, 1, 1, 1})
false
Specs
checks to see if a value is a mac address.
usable in guards.
iex> Mac.is_mac({10, 0, 0, 1, 1, 1})
true
iex> Mac.is_mac(:foo)
false
iex> Mac.is_mac({0x100, 0, 0, 1, 1, 1})
false
iex> Mac.is_mac({10, 0, 0, 1, 1, 1, 1})
false
Specs
checks to see if a value is a local mac address, by convention it means it has been assigned by the hardware manufacturer
usable in guards.
iex> Mac.is_universal_mac({0xF2, 0, 0, 1, 1, 1})
false
iex> Mac.is_universal_mac({0xF0, 0, 0, 1, 1, 1})
true
Specs
mask(0..48, :integer) :: 0..281_474_976_710_655
mask(0..48, :binary) :: <<_::48>>
mask(0..48, :mac) :: t()
generates a mask for the first n bits of the mac address.
iex> Mac.mask(1)
{0x80, 0, 0, 0, 0, 0}
iex> Mac.mask(16)
{0xFF, 0xFF, 0, 0, 0, 0}
you may pass another mode to the second parameter for other formats.
iex> Mac.mask(16, :binary)
<<0xFF, 0xFF, 0, 0, 0, 0>>
iex> Mac.mask(16, :integer)
0xFFFF_0000_0000
Specs
generates a random mac address from another, with a mask value
Specs
allows you to use the convenient ~m sigil to declare a Mac address in its normal string form, instead of using the tuple form.
iex> import Mac
iex> ~m"06:66:F4:12:34:56"
{0x06, 0x66, 0xF4, 0x12, 0x34, 0x56}
Specs
Converts a mac address to a string
iex> Mac.to_string({255, 255, 255, 255, 255, 255})
"FF:FF:FF:FF:FF:FF"
iex> Mac.to_string({6, 1, 2, 3, 4, 5})
"06:01:02:03:04:05"