ex_dhcp v0.1.5 ExDhcp.Utils View Source

Provides utilities containing typespecs for data types and binary/string conversions for ip and mac addresses. For ease-of-use both within this library and when using it.

Link to this section Summary

Types

Erlang-style ip addresses.

Mac addresses in the same style as the erlang ip address.

Functions

Converts a binary stored ip address (in the dhcp packet spec) to an erlang-style ip address. (4-tuple of bytes)

Converts a binary stored mac address (in the dhcp packet spec) to an erlang-style mac address. (6-tuple of bytes)

Creates a subnet mask from a cidr value.

Converts an erlang-style ip address (4-tuple of bytes) to a binary stored ip address (in the dhcp packet spec)

Represents an erlang-style ip4 value as a string, without going through a list intermediate.

Converts an erlang-style mac address (6-tuple of bytes) to a binary stored mac address (in the dhcp packet spec).

Converts a mac address 6-byte tuple to a string.

Converts a mac address string into a raw binary value.

Link to this section Types

Erlang-style ip addresses.

Link to this type

mac() View Source
mac() :: {byte(), byte(), byte(), byte(), byte(), byte()}

Mac addresses in the same style as the erlang ip address.

Link to this section Functions

Link to this function

bin2ip(mac_addr) View Source
bin2ip(<<_::32>>) :: ip4()

Converts a binary stored ip address (in the dhcp packet spec) to an erlang-style ip address. (4-tuple of bytes)

Converts a binary stored mac address (in the dhcp packet spec) to an erlang-style mac address. (6-tuple of bytes)

Link to this function

cidr2mask(cidr_val) View Source
cidr2mask(cidr :: 0..32) :: ip4()

Creates a subnet mask from a cidr value.

iex> ExDhcp.Utils.cidr2mask(24)
{255, 255, 255, 0}
Link to this function

ip2bin(ip_addr) View Source
ip2bin(ip4()) :: <<_::32>>

Converts an erlang-style ip address (4-tuple of bytes) to a binary stored ip address (in the dhcp packet spec)

Link to this function

ip2str(ip_addr) View Source
ip2str(ip4()) :: binary()

Represents an erlang-style ip4 value as a string, without going through a list intermediate.

Converts an erlang-style mac address (6-tuple of bytes) to a binary stored mac address (in the dhcp packet spec).

Converts a mac address 6-byte tuple to a string.

iex> ExDhcp.Utils.mac2str({1, 2, 3, 16, 255, 254})
"01:02:03:10:FF:FE"

Converts a mac address string into a raw binary value.

iex> ExDhcp.Utils.str2mac("01:02:03:10:FF:FE")
{1, 2, 3, 16, 255, 254}