Pfx.padr
You're seeing just the function
padr
, go back to Pfx module for more information.
Specs
Right pad the pfx.bits
to its full length using 0
-bits.
The result is always a full prefix with maxlen
bits.
Examples
# already a full address
iex> padr("1.2.3.4")
"1.2.3.4"
# mask applied first, then padded with zero's
iex> padr("1.2.3.4/16")
"1.2.0.0"
# mask applied first, than padded with zero's
iex> padr({{1, 2, 0, 0}, 16})
{{1, 2, 0, 0}, 32}
iex> padr(%Pfx{bits: <<1, 2>>, maxlen: 32})
%Pfx{bits: <<1, 2, 0, 0>>, maxlen: 32}
Specs
Right pad the pfx.bits
to its full length using either 0
or 1
-bits.
Examples
iex> padr("1.2.0.0/16", 1)
"1.2.255.255"
iex> padr({{1, 2, 0, 0}, 16}, 1)
{{1, 2, 255, 255}, 32}
# nothing to padr, already a full prefix
iex> padr("1.2.0.0", 1)
"1.2.0.0"
iex> padr(%Pfx{bits: <<1, 2>>, maxlen: 32}, 1)
%Pfx{bits: <<1, 2, 255, 255>>, maxlen: 32}
Specs
padr(prefix(), 0 | 1, non_neg_integer()) :: prefix()
Right pad the pfx.bits
with n
bits of either 0
or 1
's.
The result is clipped at maxlen
bits without warning.
Examples
# expand a /16 to a /24
iex> padr("255.255.0.0/16", 0, 8)
"255.255.0.0/24"
iex> padr("255.255.0.0/16", 1, 8)
"255.255.255.0/24"
iex> padr({{255, 255, 0, 0}, 16}, 1, 8)
{{255, 255, 255, 0}, 24}
# results are clipped to maxlen
iex> padr("1.2.0.0/16", 1, 512)
"1.2.255.255"
iex> padr(%Pfx{bits: <<255, 255>>, maxlen: 32}, 0, 8)
%Pfx{bits: <<255, 255, 0>>, maxlen: 32}
iex> padr(%Pfx{bits: <<255, 255>>, maxlen: 32}, 1, 8)
%Pfx{bits: <<255, 255, 255>>, maxlen: 32}