Module inet

Data Types

address_family()


address_family() = inet

hostname()


hostname() = atom() | string()

ip4_address()


ip4_address() = {0..255, 0..255, 0..255, 0..255}

ip_address()


ip_address() = ip4_address()

moniker()


moniker() = ?GEN_TCP_MONIKER | ?GEN_UDP_MONIKER

port_number()


port_number() = 0..65535

socket()


socket() = {moniker(), socket_impl(), module()}

socket_impl()


socket_impl() = any()

Function Index

close/1 Close the socket.
getaddr/2 Get the IP address associated with a given name.
ntoa/1 Convert an IPv4 address to a string.
parse_address/1 Parse an IP address string to an ip4_address().
parse_ipv4_address/1 Parse an IPv4 address string to an ip4_address().
parse_ipv4strict_address/1 Parse a strict IPv4 address string to an ip4_address().
peername/1 The address and port representing the "remote" end of a connection.
port/1 Retrieve the actual port number to which the socket is bound.
sockname/1 The address and port representing the "local" end of a connection.

Function Details

close/1


close(Socket::socket()) -> ok

Socket: the socket to close

returns: ok.

Close the socket.

getaddr/2


getaddr(Name::ip_address() | hostname(), Family::address_family()) -> {ok, ip_address()} | {error, Reason::term()}

Name: the name to resolve
Family: the family to resolve it to

returns: The address or an error tuple.

Get the IP address associated with a given name.

ntoa/1


ntoa(IpAddress::ip_address()) -> string() | {error, einval}

IpAddress: an IPv4 address tuple

returns: a string representation of the IP address, or {error, einval} if the argument is not a valid IPv4 address.

Convert an IPv4 address to a string.

This function converts an ip4_address() tuple to its dotted-decimal string representation, for example {192, 168, 0, 1} becomes "192.168.0.1".

Note: Unlike Erlang/OTP, IPv6 addresses are not supported. Passing an IPv6 address tuple will return {error, einval}.

parse_address/1


parse_address(Address::string()) -> {ok, ip4_address()} | {error, einval}

Address: a string representation of an IPv4 address

returns: {ok, IPv4Address} if the string is a valid strict IPv4 address, or {error, einval} otherwise.

Parse an IP address string to an ip4_address().

This function is an alias for parse_ipv4strict_address/1.

Note: Unlike Erlang/OTP, IPv6 addresses are not supported. Only strict dotted-decimal IPv4 addresses with exactly four fields are accepted. Short form addresses such as "127.1" or "0x7f000001" are not supported. Leading zeros are not supported as well, so "127.0.0.001" is not allowed.

parse_ipv4_address/1


parse_ipv4_address(Address::string()) -> {ok, ip4_address()} | {error, einval}

Address: a string representation of an IPv4 address

returns: {ok, IPv4Address} if the string is a valid strict IPv4 address, or {error, einval} otherwise.

Parse an IPv4 address string to an ip4_address().

This function is an alias for parse_ipv4strict_address/1.

Note: Unlike Erlang/OTP, this function behaves like parse_ipv4strict_address/1 and only accepts strict dotted-decimal IPv4 addresses with exactly four fields. Short form addresses such as "127.1" or "0x7f000001" are not supported. Leading zeros are not supported as well, so "127.0.0.001" is not allowed.

parse_ipv4strict_address/1


parse_ipv4strict_address(Address::string()) -> {ok, ip4_address()} | {error, einval}

Address: a string representation of a strict IPv4 address

returns: {ok, IPv4Address} if the string is a valid strict IPv4 address, or {error, einval} otherwise.

Parse a strict IPv4 address string to an ip4_address().

Requires an IPv4 address string containing exactly four decimal fields separated by dots, where each field is in the range 0-255. For example: "192.168.0.1" or "127.0.0.1".

Short form addresses such as "127.1" or hexadecimal notation such as "0x7f000001" are not accepted.

peername/1


peername(Socket::socket()) -> {ok, {ip_address(), port_number()}} | {error, Reason::term()}

Socket: the socket

returns: The address and port of the remote end of an established connection.

The address and port representing the “remote” end of a connection. This function should be called on a running socket instance.

port/1


port(Socket::socket()) -> port_number()

Socket: the socket from which to obtain the port number

returns: the port number associated with the local socket

Retrieve the actual port number to which the socket is bound. This function is useful if the port assignment is done by the operating system.

sockname/1


sockname(Socket::socket()) -> {ok, {ip_address(), port_number()}} | {error, Reason::term()}

Socket: the socket

returns: The address and port of the local end of an established connection.

The address and port representing the “local” end of a connection. This function should be called on a running socket instance.