View Source Sonyflakex.IpAddress (Sonyflakex v0.2.0)
Helpers to handle IP address calculations.
Summary
Functions
Returns one of the machine's private IPv4 addresses.
Checks if tuple containing a IPv4 address is a private network address.
Extracts two lower octets as a 16 bit integer.
Types
@type t() :: {non_neg_integer(), non_neg_integer(), non_neg_integer(), non_neg_integer()}
Tuple containing octets that represent a IP v4 network address.
Functions
Returns one of the machine's private IPv4 addresses.
Args:
list_ips_func
: Function that returns IP addresses. Should follow the same contract as:inet.getif/0
. Used in tests to mock getting addresses.
Examples
iex> Sonyflakex.IpAddress.lower_16_bit_ip_address({192, 168, 1, 90})
346
Checks if tuple containing a IPv4 address is a private network address.
Args:
ip
: 4 item tuple containing the address octets.
Returns: true
if the address is used in private networks.
Examples
iex> Sonyflakex.IpAddress.is_private_ipv4({192, 168, 0, 90})
true
@spec lower_16_bit_ip_address(t()) :: non_neg_integer()
Extracts two lower octets as a 16 bit integer.
Args:
ip
: 4 item tuple containing the address octets.
Returns: Two lower octets as an integer.
Examples
iex> Sonyflakex.IpAddress.lower_16_bit_ip_address({192, 168, 1, 90})
346