Pfx.from_hex
You're seeing just the function
from_hex
, go back to Pfx module for more information.
Creates a Pfx
struct for given hexadecimal string
.
This always returns a Pfx.t/0
struct. A list of punctuation characters
can be supplied as a second argument and defaults to [?:, ?-, ?.]
. Note
that '/' should not be used as that separates the mask from the rest of the
binary. Punctuation characters are simply ignored and no positional checks
are performed.
Contrary to Pfx.from_mac/1
, this function turns a random hexadecimal into a
prefix. Do not use this to create a prefix out of an IPv6 address.
Examples
iex> from_hex("1-2:3.4:a-bcdef")
%Pfx{bits: <<0x12, 0x34, 0xAB, 0xCD, 0xEF>>, maxlen: 40}
iex> from_hex("1-2:3.4:a-bcdef/16")
%Pfx{bits: <<0x12, 0x34>>, maxlen: 40}
iex> from_hex("1|2|3|A|B|C|DEF", [?|])
%Pfx{bits: <<0x12, 0x3A, 0xBC, 0xDE, 0xF::4>>, maxlen: 36}
iex> from_hex("ABC")
%Pfx{bits: <<0xAB, 0xC::4>>, maxlen: 12}
# not for IPv6 addresses ..
iex> from_hex("2001::1")
%Pfx{bits: <<0x20, 0x01, 0x1::4>>, maxlen: 20}