View Source hackney_cidr (hackney v1.23.0)

Summary

Functions

return the number of IP addresses included in the CIDR block
return true if the CIDR block contains the IP address or CIDR block, false otherwise.
return true if the value is an ipv4 address
return true if the value is an ipv6 address
Unique sort and merge a list of CIDR blocks, ordering IPv4 ranges before IPv6 ranges. For merging, CIDR blocks that are contained by other CIDR blocks are removed and adjacent CIDR blocks are merged into larger ones.
parses S as a CIDR notation IP address and mask
parses S as a CIDR notation IP address and mask. If Adjust = true, allow the IP to contain values beyond the mask and silently ignore them. Otherwise, enforce that the IP address is fully inside the specified mask (the default behavior of parse/1).
return a CIDR block as a binary string.
return a CIDR block as a string.
Unique sort a list of CIDR blocks, ordering IPv4 ranges before IPv6 ranges

Types

cidr/0

-type cidr() ::
          {Start :: inet:ip4_address(), End :: inet:ip4_address(), MaskLen :: 0..32} |
          {Start :: inet:ip6_address(), End :: inet:ip6_address(), MaskLen :: 0..128}.

Functions

address_count(IP, MaskLen)

-spec address_count(inet:ip4_address(), MaskLen :: 0..32) -> pos_integer();
                   (inet:ip6_address(), MaskLen :: 0..128) -> pos_integer().
return the number of IP addresses included in the CIDR block

contains(_, Addr)

-spec contains(cidr(), inet:ip_address() | cidr()) -> boolean().
return true if the CIDR block contains the IP address or CIDR block, false otherwise.

ip_gte(_, _)

ip_lte(_, _)

is_ipv4(_)

-spec is_ipv4(inet:ip_address()) -> boolean().
return true if the value is an ipv4 address

is_ipv6(_)

-spec is_ipv6(inet:ip_address()) -> boolean().
return true if the value is an ipv6 address

merge_cidrs(CIDRs)

-spec merge_cidrs([cidr()]) -> [cidr()].
Unique sort and merge a list of CIDR blocks, ordering IPv4 ranges before IPv6 ranges. For merging, CIDR blocks that are contained by other CIDR blocks are removed and adjacent CIDR blocks are merged into larger ones.

parse(S)

-spec parse(string() | binary()) -> cidr().
parses S as a CIDR notation IP address and mask

parse(B, Adjust)

-spec parse(string() | binary(), Adjust :: boolean()) -> cidr().
parses S as a CIDR notation IP address and mask. If Adjust = true, allow the IP to contain values beyond the mask and silently ignore them. Otherwise, enforce that the IP address is fully inside the specified mask (the default behavior of parse/1).

to_binary(_)

-spec to_binary(cidr()) -> binary().
return a CIDR block as a binary string.

to_string(_)

-spec to_string(cidr()) -> string().
return a CIDR block as a string.

usort_cidrs(CIDRs)

-spec usort_cidrs([cidr()]) -> [cidr()].
Unique sort a list of CIDR blocks, ordering IPv4 ranges before IPv6 ranges