ip v0.1.0 IP.Prefix
Defines an IP prefix, otherwise known as a subnet.
Link to this section Summary
Functions
Returns true
or false
depending on whether the supplied address
is
contained within prefix
Returns true
or false
depending on whether the supplied inside
is
completely contained by outside
Generate an EUI-64 host address within the specifed IPv6 prefix
Generate an EUI-64 host address within the specifed IPv6 prefix
Returns the first address in the prefix
Create a prefix by attempting to parse a string of unknown version
Create a prefix by attempting to parse a string of specified IP version
Create a prefix by attempting to parse a string of unknown version
Create a prefix by attempting to parse a string of specified IP version
Returns the last address in the prefix
Returns the bit-length of the prefix
Alter the bit-length
of the prefix
Returns the calculated mask of the prefix
Create an IP prefix from an IP.Address
and length
Return the address space within this address
Returns an old-fashioned subnet mask for IPv4 prefixes
Return the usable IP address space within this address
Returns an “cisco style” wildcard mask for IPv4 prefixes
Link to this section Types
Link to this section Functions
Returns true
or false
depending on whether the supplied address
is
contained within prefix
.
Examples
iex> IP.Prefix.from_string!("192.0.2.0/24")
...> |> IP.Prefix.contains_address?(IP.Address.from_string!("192.0.2.127"))
true
iex> IP.Prefix.from_string!("192.0.2.0/24")
...> |> IP.Prefix.contains_address?(IP.Address.from_string!("198.51.100.1"))
false
iex> IP.Prefix.from_string!("2001:db8::/64")
...> |> IP.Prefix.contains_address?(IP.Address.from_string!("2001:db8::1"))
true
iex> IP.Prefix.from_string!("2001:db8::/64")
...> |> IP.Prefix.contains_address?(IP.Address.from_string!("2001:db8:1::1"))
false
iex> outside = IP.Prefix.from_string!("2001:db8::/64")
...> inside = IP.Prefix.eui_64!(outside, "60:f8:1d:ad:d8:90")
...> IP.Prefix.contains_address?(outside, inside)
true
Returns true
or false
depending on whether the supplied inside
is
completely contained by outside
.
Examples
iex> outside = IP.Prefix.from_string!("192.0.2.0/24")
...> inside = IP.Prefix.from_string!("192.0.2.128/25")
...> IP.Prefix.contains_prefix?(outside, inside)
true
iex> outside = IP.Prefix.from_string!("192.0.2.128/25")
...> inside = IP.Prefix.from_string!("192.0.2.0/24")
...> IP.Prefix.contains_prefix?(outside, inside)
false
iex> outside = IP.Prefix.from_string!("2001:db8::/64")
...> inside = IP.Prefix.from_string!("2001:db8::/128")
...> IP.Prefix.contains_prefix?(outside, inside)
true
iex> outside = IP.Prefix.from_string!("2001:db8::/128")
...> inside = IP.Prefix.from_string!("2001:db8::/64")
...> IP.Prefix.contains_prefix?(outside, inside)
false
Generate an EUI-64 host address within the specifed IPv6 prefix
.
EUI-64 addresses can only be generated for 64 bit long IPv6 prefixes.
Examples
iex> "2001:db8::/64"
...> |> IP.Prefix.from_string!
...> |> IP.Prefix.eui_64("60:f8:1d:ad:d8:90")
...> |> inspect()
"{:ok, #IP.Address<2001:db8::62f8:1dff:fead:d890 DOCUMENTATION>}"
Generate an EUI-64 host address within the specifed IPv6 prefix
.
EUI-64 addresses can only be generated for 64 bit long IPv6 prefixes.
Examples
iex> "2001:db8::/64"
...> |> IP.Prefix.from_string!
...> |> IP.Prefix.eui_64!("60:f8:1d:ad:d8:90")
#IP.Address<2001:db8::62f8:1dff:fead:d890 DOCUMENTATION>
Returns the first address in the prefix.
Examples
iex> IP.Prefix.from_string!("192.0.2.128/24")
...> |> IP.Prefix.first()
#IP.Address<192.0.2.0 DOCUMENTATION>
iex> IP.Prefix.from_string!("2001:db8::128/64")
...> |> IP.Prefix.first()
#IP.Address<2001:db8:: DOCUMENTATION>
Create a prefix by attempting to parse a string of unknown version.
Calling from_string/2
is faster if you know the IP version of the prefix.
Examples
iex> "192.0.2.1/24"
...> |> IP.Prefix.from_string()
...> |> inspect()
"{:ok, #IP.Prefix<192.0.2.0/24>}"
iex> "192.0.2.1/255.255.255.0"
...> |> IP.Prefix.from_string()
...> |> inspect()
"{:ok, #IP.Prefix<192.0.2.0/24>}"
iex> "2001:db8::/64"
...> |> IP.Prefix.from_string()
...> |> inspect()
"{:ok, #IP.Prefix<2001:db8::/64>}"
from_string(binary, 4 | 6) :: {:ok, t} | {:error, term}
Create a prefix by attempting to parse a string of specified IP version.
Examples
iex> "192.0.2.1/24"
...> |> IP.Prefix.from_string(4)
...> |> inspect()
"{:ok, #IP.Prefix<192.0.2.0/24>}"
iex> "192.0.2.1/255.255.255.0"
...> |> IP.Prefix.from_string(4)
...> |> inspect()
"{:ok, #IP.Prefix<192.0.2.0/24>}"
iex> "2001:db8::/64"
...> |> IP.Prefix.from_string(4)
{:error, "Error parsing IPv4 prefix"}
Create a prefix by attempting to parse a string of unknown version.
Calling from_string!/2
is faster if you know the IP version of the prefix.
Examples
iex> "192.0.2.1/24"
...> |> IP.Prefix.from_string!()
#IP.Prefix<192.0.2.0/24>
iex> "192.0.2.1/255.255.255.0"
...> |> IP.Prefix.from_string!()
#IP.Prefix<192.0.2.0/24>
iex> "2001:db8::/64"
...> |> IP.Prefix.from_string!()
#IP.Prefix<2001:db8::/64>
Create a prefix by attempting to parse a string of specified IP version.
Examples
iex> "192.0.2.1/24"
...> |> IP.Prefix.from_string!(4)
#IP.Prefix<192.0.2.0/24>
iex> "192.0.2.1/255.255.255.0"
...> |> IP.Prefix.from_string!(4)
#IP.Prefix<192.0.2.0/24>
Returns the last address in the prefix.
Examples
iex> IP.Prefix.from_string!("192.0.2.128/24")
...> |> IP.Prefix.last()
#IP.Address<192.0.2.255 DOCUMENTATION>
iex> IP.Prefix.from_string!("2001:db8::128/64")
...> |> IP.Prefix.last()
#IP.Address<2001:db8::ffff:ffff:ffff:ffff DOCUMENTATION>
Returns the bit-length of the prefix.
Example
iex> "192.0.2.1/24"
...> |> IP.Prefix.from_string!()
...> |> IP.Prefix.length()
24
length(t, ipv4_prefix_length | ipv6_prefix_length) :: t
Alter the bit-length
of the prefix
.
Example
iex> "192.0.2.0/24"
...> |> IP.Prefix.from_string!()
...> |> IP.Prefix.length(25)
#IP.Prefix<192.0.2.0/25>
Returns the calculated mask of the prefix.
Example
iex> IP.Prefix.from_string!("192.0.2.1/24")
...> |> IP.Prefix.mask()
0b11111111111111111111111100000000
new(IP.Address.t, ipv4_prefix_length | ipv6_prefix_length) :: t
Create an IP prefix from an IP.Address
and length
.
Examples
iex> IP.Prefix.new(IP.Address.from_string!("192.0.2.1"), 24)
#IP.Prefix<192.0.2.0/24>
iex> IP.Prefix.new(IP.Address.from_string!("2001:db8::1"), 64)
#IP.Prefix<2001:db8::/64>
Return the address space within this address.
Examples
iex> "192.0.2.0/24"
...> |> IP.Prefix.from_string!()
...> |> IP.Prefix.space()
256
iex> "2001:db8::/64"
...> |> IP.Prefix.from_string!()
...> |> IP.Prefix.space()
18446744073709551616
Returns an old-fashioned subnet mask for IPv4 prefixes.
Example
iex> IP.Prefix.from_string!("192.0.2.0/24")
...> |> IP.Prefix.subnet_mask()
#IP.Address<255.255.255.0 RESERVED>
Return the usable IP address space within this address.
Examples
iex> "192.0.2.0/24"
...> |> IP.Prefix.from_string!()
...> |> IP.Prefix.usable()
254
iex> "2001:db8::/64"
...> |> IP.Prefix.from_string!()
...> |> IP.Prefix.usable()
18446744073709551616