View Source Sonyflakex.IpAddress (Sonyflakex v0.2.0)

Helpers to handle IP address calculations.

Summary

Types

t()

Tuple containing octets that represent a IP v4 network address.

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

Tuple containing octets that represent a IP v4 network address.

Functions

Link to this function

first_private_ipv4(list_ips_func \\ &:inet.getif/0)

View Source
@spec first_private_ipv4((-> {:ok, [{t(), any(), any()}]})) :: t()

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
@spec is_private_ipv4(t()) :: boolean()

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
Link to this function

lower_16_bit_ip_address(ip)

View Source
@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