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
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
ip4()
View Source
ip4() :: :inet.ip4_address()
ip4() :: :inet.ip4_address()
Erlang-style ip addresses.
mac() View Source
Mac addresses in the same style as the erlang ip address.
Link to this section Functions
bin2ip(mac_addr)
View Source
bin2ip(<<_::32>>) :: ip4()
bin2ip(<<_::32>>) :: ip4()
Converts a binary stored ip address (in the dhcp packet spec) to an erlang-style ip address. (4-tuple of bytes)
bin2mac(mac_addr) View Source
Converts a binary stored mac address (in the dhcp packet spec) to an erlang-style mac address. (6-tuple of bytes)
cidr2mask(cidr_val)
View Source
cidr2mask(cidr :: 0..32) :: ip4()
cidr2mask(cidr :: 0..32) :: ip4()
Creates a subnet mask from a cidr value.
iex> ExDhcp.Utils.cidr2mask(24)
{255, 255, 255, 0}
ip2bin(ip_addr)
View Source
ip2bin(ip4()) :: <<_::32>>
ip2bin(ip4()) :: <<_::32>>
Converts an erlang-style ip address (4-tuple of bytes) to a binary stored ip address (in the dhcp packet spec)
ip2str(ip_addr) View Source
Represents an erlang-style ip4 value as a string, without going through a list intermediate.
mac2bin(mac_addr) View Source
Converts an erlang-style mac address (6-tuple of bytes) to a binary stored mac address (in the dhcp packet spec).
mac2str(mac_addr) View Source
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"
str2mac(mac_addr) View Source
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}