IP addresses and CIDR blocks: parsing, membership and normalization.
An IPv4 address that arrives in IPv4-mapped IPv6 form (::ffff:203.0.113.5,
as a dual-stack listener can report its peer) is normalized to its IPv4
form, so a trusted IPv4 proxy matches however the socket reported it.
Summary
Functions
Whether ip is in any of the CIDRs.
Whether ip is in the CIDR {network, prefix}. Families never match each other.
An IPv4-mapped IPv6 address as its IPv4 form; any other address unchanged.
Parses an address string to a normalized tuple, or returns nil.
Parses a CIDR ("10.0.0.0/8", "2001:db8::/32") or a single address
("192.0.2.1", a /32 or /128) to {network, prefix}, or returns an error
naming what is wrong.
Formats an address.
Types
@type cidr() :: {ip(), 0..128}
@type ip() :: :inet.ip_address()
Functions
Whether ip is in any of the CIDRs.
Whether ip is in the CIDR {network, prefix}. Families never match each other.
An IPv4-mapped IPv6 address as its IPv4 form; any other address unchanged.
Parses an address string to a normalized tuple, or returns nil.
Parses a CIDR ("10.0.0.0/8", "2001:db8::/32") or a single address
("192.0.2.1", a /32 or /128) to {network, prefix}, or returns an error
naming what is wrong.
Formats an address.