cidr v1.1.0 CIDR View Source

Classless Inter-Domain Routing (CIDR)

Link to this section Summary

Functions

Checks if two cidr objects are equal

Returns a stream of all hosts in the range

Check whether the argument is a CIDR value

Checks if an IP address is in the provided CIDR

Throwing version of match/2, raises ArgumentError on error

Parses a bitstring into a CIDR struct

Splits an existing cidr into smaller blocks

Checks if a is a subnet of b

Checks if a is a supernet of b

Link to this section Functions

Checks if two cidr objects are equal

Examples

iex> d = CIDR.parse("10.0.0.0/24")
 %CIDR{first: {10, 0, 0, 0}, hosts: 256, last: {10, 0, 0, 255}, mask: 24}
 iex> c = CIDR.parse("10.0.0.0/24")
 %CIDR{first: {10, 0, 0, 0}, hosts: 256, last: {10, 0, 0, 255}, mask: 24}
 iex(21)> CIDR.equal?(d, c)
 true

Returns a stream of all hosts in the range

Examples

iex> CIDR.parse("192.168.0.0/31") |> CIDR.hosts |> Enum.map(fn(x) -> x end)
   [{192, 168, 0, 0}, {192, 168, 0, 1}]

Check whether the argument is a CIDR value.

Examples

iex> CIDR.is_cidr?("192.168.1.254/32")
true

Checks if an IP address is in the provided CIDR.

Returns {:ok, true} if the address is in the CIDR range, {:ok, false} if it’s not, and {:error, reason} if the second argument isn’t a valid IP address.

Throwing version of match/2, raises ArgumentError on error.

Link to this function number2list(x, s, d, i, m) View Source

Parses a bitstring into a CIDR struct

Splits an existing cidr into smaller blocks

Examples

iex> CIDR.parse("192.168.0.0/24") |> CIDR.split(25) |> Enum.map(&(&1))
   [%CIDR{first: {192, 168, 0, 0}, hosts: 128, last: {192, 168, 0, 127}, mask: 25},
    %CIDR{first: {192, 168, 0, 128}, hosts: 128, last: {192, 168, 0, 255}, mask: 25}]

Checks if a is a subnet of b

Checks if a is a supernet of b