Kernel

Reference Manual

Version 6.5

Table of Contents

net

Module

net

Module Summary

Network interface.

Since

Module net was introduced in OTP 22.0.

Description

This module provides an API for the network interface.

Note

There is currently no support for Windows.

Data Types

address_info() =
    #{family := socket:domain(),
      socktype := socket:type(),
      protocol := socket:protocol(),
      address := socket:sockaddr()}

name_info() = #{host := string(), service := string()}
name_info_flag() =
    namereqd | dgram | nofqdn | numerichost | nomericserv

name_info_flag_ext() =
    idn | idna_allow_unassigned | idna_use_std3_ascii_rules

network_interface_index() = integer() >= 0

Exports

gethostname() -> {ok, HostName} | {error, Reason}

Types

HostName = string()
Reason = term()

Returns the name of the current host.

getnameinfo(SockAddr) -> {ok, Info} | {error, Reason}
OTP 22.0
getnameinfo(SockAddr, Flags) -> {ok, Info} | {error, Reason}
OTP 22.0

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.

getaddrinfo(Host) -> {ok, Info} | {error, Reason}
OTP 22.0
getaddrinfo(Host, Service :: undefined) ->
               {ok, Info} | {error, Reason}
OTP 22.0
getaddrinfo(Host :: undefined, Service) ->
               {ok, Info} | {error, Reason}
OTP 22.0
getaddrinfo(Host, Service) -> {ok, Info} | {error, Reason}
OTP 22.0

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.

if_name2index(Name) -> {ok, Idx} | {error, Reason}
OTP 22.0

Types

Reason = term()

Mappings between network interface names and indexes.

if_index2name(Idx) -> {ok, Name} | {error, Reason}
OTP 22.0

Types

Reason = term()

Mappings between network interface index and names.

if_names() -> Names | {error, Reason}
OTP 22.0

Types

Names = [{Idx, If}]
Reason = term()

Get network interface names and indexes.