net

net

net
Network interface.
Module net was introduced in OTP 22.0.

This module provides an API for the network interface.

Note

There is currently no support for Windows.

Note

The content of this file is only valid if the system has been built with 'socket' (esock) support, which is the default.

This type defines all addresses (and flags) associated with the interface.

Not all fields of this map has to be present. The flags field can be used to test for some of the fields. For example broadaddr will only be present if the broadcast flag is present in flags.

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.

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).

Types

HostName = string()
Reason = term()

Returns the name of the current host.

Types

Flags = name_info_flags() | undefined
Reason = term()

Address-to-name translation in a protocol-independant manner.

This function is the inverse of getaddrinfo. It converts a socket address to a corresponding host and service.

Types

Host = Service = string()
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 the Host and Service may be undefined but not both.

Types

IfAddrs = [ifaddrs()]
Reason = term()

Get interface addresses.

This function is used to get the machines 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.