net(3erl)
Bestie, this is net(3erl) β the Erlang Module Definition β and it's literally the network interface page. Buckle up, we're doing every type and export, no cap. π
β¨
π NAME π
net β Network interface.
β¨ DESCRIPTION β¨
This module provides an API for the network interface. That's the whole assignment: it's the Erlang module that hands you the network-interface API. Slay.
π§ DATA TYPES π§
Okay, data-type time, bestie. These are the shapes you'll see. π¦
address_info()
address_info() =
#{family := socket:domain(),
socktype := socket:type(),
protocol := socket:protocol(),
address := socket:sockaddr()}
ifaddrs()
ifaddrs() =
#{name := string(),
flags := ifaddrs_flags(),
addr => socket:sockaddr(),
netmask => socket:sockaddr(),
broadaddr => socket:sockaddr(),
dstaddr => socket:sockaddr()}
This type defines all addresses (and flags) associated with the interface.
Note, bestie: not all fields of this map have to be present. Theflagsfield can be used to test for some of the fields. For examplebroadaddrwill only be present if thebroadcastflag is present inflags.
ifaddrs_flag()
ifaddrs_flag() =
up | broadcast | debug | loopback | pointopoint | notrailers |
running | noarp | promisc | master | slave | multicast |
portsel | automedia | dynamic
ifaddrs_flags()
ifaddrs_flags() = [ifaddrs_flag()]
ifaddrs_filter()
ifaddrs_filter() =
all | default | inet | inet6 | packet |
ifaddrs_filter_map() |
ifaddrs_filter_fun()
The filter options are:
all: All interfaces.default: Interfaces with address familyinetandinet6.inet|inet6|packet: Interfaces with only the specified address family.
ifaddrs_filter_map()
ifaddrs_filter_map() =
#{family := default | inet | inet6 | packet | all,
flags := any | [ifaddrs_flag()]}
The family field can only have the (above) specified values (and not all the values of socket:domain()).
The use of the flags field is that any flag provided must exist for the interface.
For example, if family is set to inet and flags to [broadcast, multicast], only interfaces with address family inet and the flags broadcast and multicast will be listed.
ifaddrs_filter_fun()
ifaddrs_filter_fun() = fun((ifaddrs()) -> boolean())
For each ifaddrs entry, return either true to keep the entry or false to discard the entry.
For example, to get an interface list which only contains non-loopback inet interfaces:
net:getifaddrs(fun(#{addr := #{family := inet},
flags := Flags}) ->
not lists:member(loopback, Flags);
(_) ->
false
end).
name_info()
name_info() = #{host := string(), service := string()}
name_info_flags()
name_info_flags() = [name_info_flag() | name_info_flag_ext()]
name_info_flag()
name_info_flag() =
namereqd | dgram | nofqdn | numerichost | numericserv
name_info_flag_ext()
name_info_flag_ext() = idn
network_interface_name()
network_interface_name() = string()
network_interface_index()
network_interface_index() = integer() >= 0
π₯ EXPORTS π₯
Here come the functions, bestie. Same order as the page, every clause intact. π
gethostname()
gethostname() -> {ok, HostName} | {error, Reason}
Types:
HostName = string()
Reason = term()
Returns the name of the current host. That's the whole function, and it ate. π
getnameinfo()
getnameinfo(SockAddr) -> {ok, Info} | {error, Reason}
getnameinfo(SockAddr, Flags) -> {ok, Info} | {error, Reason}
Types:
SockAddr = socket:sockaddr()
Flags = name_info_flags() | undefined
Info = name_info()
Reason = term()
Address-to-name translation in a protocol-independent manner.
This function is the inverse of getaddrinfo. It converts a socket address to a corresponding host and service.
getaddrinfo()
getaddrinfo(Host) -> {ok, Info} | {error, Reason}
getaddrinfo(Host, Service :: undefined) ->
{ok, Info} | {error, Reason}
getaddrinfo(Host :: undefined, Service) ->
{ok, Info} | {error, Reason}
getaddrinfo(Host, Service) -> {ok, Info} | {error, Reason}
Types:
Host = Service = string()
Info = [address_info()]
Reason = term()
Network address and service translation.
This function is the inverse of getnameinfo. It converts host and service to a corresponding socket address.
One of Host and Service may be undefined but not both.
getifaddrs()
getifaddrs() -> {ok, IfAddrs} | {error, Reason}
getifaddrs(Filter) -> {ok, IfAddrs} | {error, Reason}
getifaddrs(Namespace) -> {ok, IfAddrs} | {error, Reason}
getifaddrs(Filter, Namespace) -> {ok, IfAddrs} | {error, Reason}
Types:
Filter = ifaddrs_filter()
Namespace = file:filename_all()
IfAddrs = [ifaddrs()]
Reason = term()
Get interface addresses.
This function is used to get the machine's interface addresses, possibly filtered according to Filter.
By default, a filter with the content: #{family => default, flags => any} is used. This will return all interfaces with addresses in the inet and inet6 families.
if_name2index()
if_name2index(Name) -> {ok, Idx} | {error, Reason}
Types:
Name = network_interface_name()
Idx = network_interface_index()
Reason = term()
Mappings between network interface names and indexes.
if_index2name()
if_index2name(Idx) -> {ok, Name} | {error, Reason}
Types:
Idx = network_interface_index()
Name = network_interface_name()
Reason = term()
Mappings between network interface index and names.
if_names()
if_names() -> {ok, Names} | {error, Reason}
Types:
Names = [{Idx, If}]
Idx = network_interface_index()
If = network_interface_name()
Reason = term()
Get network interface names and indexes.
Okay, that's the whole net(3erl) page. Cute sign-off: source/version check says Ericsson AB and kernel 8.5.4.2, with net(3erl) as the manual page. Date? The footer doesn't have one, so bestie, I'm not making up a date. Mwah ππ«Ά
π¦ where this page comes from
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4 Β· Apache-2.0
- ubuntu noble: erlang-manpages 1:25.3.2.8+dfsg-1ubuntu4.8 Β· Apache-2.0
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms