Pfx.mask
You're seeing just the function
mask
, go back to Pfx module for more information.
Specs
Returns the mask for given pfx
.
The result is always a full length prefix.
Examples
iex> mask("10.10.10.0/25")
"255.255.255.128"
iex> mask({10, 10, 10, 0})
{255, 255, 255, 255}
iex> mask({{10, 10, 10, 0}, 25})
{{255, 255, 255, 128}, 32}
iex> mask("acdc:1976::/32")
"ffff:ffff:0:0:0:0:0:0"
# some prefix with some other maxlen
iex> mask(%Pfx{bits: <<10, 10, 0::1>>, maxlen: 20})
%Pfx{bits: <<255, 255, 8::4>>, maxlen: 20}
Specs
Applies mask
to given prefix
.
Applying a mask may trim off bits from given prefix
depending on the mask.
A mask can never add bits to the prefix.bits
though. The representation of
the result mirrors that of given prefix
. Note that both prefix
and
mask
must be of the same type (same maxlen).
Examples
iex> mask("1.1.1.1", "255.255.255.0")
"1.1.1.0"
iex> mask("1.1.1.1", "255.0.0.255")
"1.0.0.1"
iex> mask({1, 1, 1, 1}, {255, 0, 0, 255})
{1, 0, 0, 1}
iex> mask({1, 1, 1, 1}, "255.0.0.255")
{1, 0, 0, 1}
iex> mask("1.1.1.1", "255.255.0.0/16")
"1.1.0.0/16"
iex> mask("1.1.1.0/24", "255.255.0.0/16")
"1.1.0.0/16"
# this mask has no effect
iex> mask("1.1.0.0/16", "255.255.255.0/24")
"1.1.0.0/16"