Inet provides access to TCP/IP protocols.
Some functions returns a hostent record.
Use this line in your module
-include_lib("kernel/include/inet.hrl").
to include the record definition.
h_addr_list
h_addrtype
inet or inet6
h_aliases
h_length
h_name
Addresses as inputs to functions can be either a string or
a tuple.
For instance, the IP address 150.236.20.73 can be passed to
gethostbyaddr/1 either as the string "150.236.20.73"
or as the tuple {150, 236, 20, 73}.
Addresses returned by any function in the inet module
will be a tuple.
Hostnames may be specified as either atoms or a strings.
Where an address family is required, valid values are
inet
(standard IPv4 addresses) or inet6 (IPv6).
Tag = atom()Returns a diagnostic error string. See the section below
for possible Tag values and the corresponding strings.
gethostbyaddr(Address) -> {ok, Hostent} | {error, Reason}
Address = address()Hostent = hostent()Returns a hostent record given an address.
gethostbyname(Name) -> {ok, Hostent} | {error, Reason}
Hostname = hostname()Hostent = hostent()Returns a hostent record given a hostname.
gethostbyname(Name, Family) -> {ok, Hostent} | {error, Reason}
Hostname = hostname()Family = family()Hostent = hostent()Returns a hostent record given a hostname, restricted to the
given address family.
gethostname() -> {ok, Name} | {error, Reason}
Hostname = hostname()Returns the local hostname. Will never fail.
sockname(Socket) -> {ok, {IP, Port}} | {error, Reason}
Socket = socket()Address = address()Port = integer()Returns the local address and port number for a socket.
peername(Socket) -> {ok, {Address, Port}} | {error, Reason}
Socket = socket()Address = address()Port = integer()Returns the address and port for the other end of a connection.
Socket = socket()Number = integer()Returns the local port number for a socket.
Socket = socket()Closes a socket of any type.
getaddr(IP,inet) -> {ok,{A1,A2,A3,A4}} | {error, Reason}
IP = {A1,A2,A3,A4} | string() | atom()A1 = A2 = A3 = A4 = integer()Reason = term()Returns the IP-address as a tuple with integers for IP which can be an
IP-address a single hostname or a fully qualified hostname.
At present only IPv4 adresses (the inet argument) is supported, but
the function is prepared to support IPv6 (inet6) in a near future.
setopts(Socket, Options) -> ok | {error, Reason}
Socket = term()Options = list()Sets one or more options for a socket. The following options are available:
{active, Boolean}
true, which is the default,
everything received from the socket will be sent as messages
to the receiving process.
If the active option is set to false (passive mode),
the process must explicitly receive incoming data by calling
gen_tcp:recv/N or gen_udp:recv/N
(depending on the type of socket).
Note: Passive mode provides flow control; the other side
will not be able send faster than the receiver can read.
Active mode provides no flow control; a fast sender could
easily overflow the receiver with incoming messages.
Use active mode only if your high-level protocol provides
its own flow control (for instance, acknowledging received
messages) or the amount of data exchanged is small.
{broadcast, Boolean}
{dontroute, true|false}
{dontroute, true} to enable/disable routing bypass for
outgoing messages.
{header, Size}
binary option
was specified when the socket was created.
If the header option is specified, the first Size number bytes of
data received from the socket will be elements of a list, and the rest of the
data will be a binary given as the tail of the same list. If for example
Size=2 the data received will match [Byte1,Byte2|Binary].
{keepalive, Boolean}
{nodelay, Boolean}
true, the TCP_NODELAY option is
turned on for the socket, which means that even small amounts of
data will be sent immediately. (TCP/IP sockets)
{packet, PacketType}
raw | 0
1 | 2 | 4
asn1 | cdr | sunrm | fcgi | tpkt | line
gen_tcp:recv/N returns
one complete packet.
The header is not stripped off.
The meanings of the packet types are as follows:
asn1 - ASN.1 BER,
sunrm - Sun's RPC encoding,
cdr - CORBA (GIOP 1.1),
fcgi - Fast CGI,
tpkt - TPKT format [RFC1006],
line - Line mode, a packet is a line
terminated with newline, lines longer than the
receive buffer are truncated.
{recbuf, Integer}
{reuseaddr, Boolean}
{sndbuf, Integer}
The possible error reasons and the corresponding diagnostic strings
returned by format_error/1 are as follows:
e2bigeacceseaddrinuseeaddrnotavaileadveafnosupporteagainealignealreadyebadeebadfebadfdebadmsgebadrebadrpcebadrqcebadsltebfontebusyechildechrngecommeconnabortedeconnrefusedeconnresetedeadlkedeadlockedestaddrreqedirtyedomedotdotedquoteduppkgeexistefaultefbigehostdownehostunreacheidrmeiniteinprogresseintreinvaleioeisconneisdireisnamel2hltel2nsyncel3hltel3rstelbinelibaccelibbadelibexecelibmaxelibscnelnrngeloopemfileemlinkemsgsizeemultihopenametoolongenavailenetenetdownenetresetenetunreachenfileenoanoenobufsenocsienodataenodevenoentenoexecenolckenolinkenomemenomsgenonetenopkgenoprotooptenospcenosrenosymenosysenotblkenotconnenotdirenotemptyenotnamenotsockenotsupenottyenotuniqenxioeopnotsuppepermepfnosupportepipeeproclimeprocunavaileprogmismatcheprogunavaileprotoeprotonosupporteprototypeerangeerefusederemchgeremdeveremoteeremoteioeremotereleaseerofserpcmismatcherremoteeshutdownesocktnosupportespipeesrchesrmntestaleesuccessetimeetimedoutetoomanyrefsetxtbsyeucleaneunatcheuserseversionewouldblockexdevexfullnxdomain