From e5875001247e6a6ac4f474157a51a8c54f94ae49 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Thu, 14 Mar 2013 16:01:25 +0100 Subject: Convert XML files to UTF-8 --- lib/kernel/doc/src/inet.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index 541500a300..f99aef57b7 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -1,4 +1,4 @@ - + -- cgit v1.2.3 From af112cb10613d422080785621a274a18d96567c0 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Fri, 19 Jul 2013 15:18:42 +0200 Subject: Document socket option 'netns' --- lib/kernel/doc/src/inet.xml | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index 7cd98914d1..650ab41c3e 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -715,6 +715,59 @@ fe80::204:acff:fe17:bf38

Received Packet is delivered as defined by Mode.

+ {netns, Namespace :: file:filename_all()} + +

Set a network namespace for the socket. The Namespace + parameter is a filename defining the namespace for example + "/var/run/netns/example" typically created by the command + ip netns add example. This option must be used in a + function call that creates a socket i.e + + gen_tcp:connect/3,4, + + gen_tcp:listen/2, + + gen_udp:open/1,2 or + + gen_sctp:open/0-2. +

+

This option uses the Linux specific syscall + setns() such as in Linux kernel 3.0 or later + and therefore only exists when the runtime system + has been compiled for such an operating system. +

+

+ The virtual machine also needs elevated privileges either + running as superuser or (for Linux) having the capability + CAP_SYS_ADMIN according to the documentation for setns(2). + However, during testing also CAP_SYS_PTRACE + and CAP_DAC_READ_SEARCH has proven to be necessary. + Example: +setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp + + Note also that the filesystem containing the virtual machine + executable (beam.smp in the example above) has to be local, + mounted without the nosetuid flag, + support extended attributes and that + the kernel has to support file capabilities. + All this runs out of the box on at least Ubuntu 12.04 LTS, + except that SCTP sockets appears to not support + network namespaces. +

+

The Namespace is a file name and is encoded + and decoded as discussed in + file + except that the emulator flag +fnu is ignored and + getopts/2 + for this option will return a binary for the filename + if the stored filename can not be decoded, + which should only happen if you set the option using a binary + that can not be decoded with the emulator's filename encoding: + + file:native_name_encoding/0. +

+
+ list

Received Packet is delivered as a list.

-- cgit v1.2.3 From d794ba8845619322639f24602624b9acd71efc98 Mon Sep 17 00:00:00 2001 From: Fredrik Gustafsson Date: Tue, 30 Jul 2013 15:37:34 +0200 Subject: kernel: clarified inet:parse_address/1 referrering to old code --- lib/kernel/doc/src/inet.xml | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index 7cd98914d1..f33ea3c57d 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -76,11 +76,11 @@ FFFF::192.168.42.2 {16#3ffe,16#b80,16#1f8d,16#2,16#204,16#acff,16#fe17,16#bf38} fe80::204:acff:fe17:bf38 {16#fe80,0,0,0,0,16#204,16#acff,16#fe17,16#bf38} -

A function that may be useful is inet_parse:address/1:

+

A function that may be useful is parse_address/1:

-1> inet_parse:address("192.168.42.2").
+1> inet:parse_address("192.168.42.2").
 {ok,{192,168,42,2}}
-2> inet_parse:address("FFFF::192.168.42.2").
+2> inet:parse_address("FFFF::192.168.42.2").
 {ok,{65535,0,0,0,0,0,49320,10754}}
-- cgit v1.2.3 From e547c997a4e516d3474e577bd4747e249303a7c7 Mon Sep 17 00:00:00 2001 From: Fredrik Gustafsson Date: Tue, 30 Jul 2013 16:06:40 +0200 Subject: kernel: added ntoa documentation and exported it in inet.erl --- lib/kernel/doc/src/inet.xml | 7 +++++++ 1 file changed, 7 insertions(+) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index f33ea3c57d..254dfbf034 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -374,6 +374,13 @@ fe80::204:acff:fe17:bf38 + + + Convert IPv6 / IPV4 adress to ascii + +

Parses an ip_address() and returns an IPv4 or IPv6 address string.

+
+
Parse an IPv4 address -- cgit v1.2.3 From 7fbf2c26ac063988818230a0e18a9df48c2fbf2d Mon Sep 17 00:00:00 2001 From: Steve Vinoski Date: Tue, 27 Aug 2013 11:42:00 -0400 Subject: add {active,N} socket option for TCP, UDP, and SCTP Add the {active,N} socket option, where N is an integer in the range -32768..32767, to allow a caller to specify the number of data messages to be delivered to the controlling process. Once the socket's delivered message count either reaches 0 or is explicitly set to 0 with inet:setopts/2 or by including {active,0} as an option when the socket is created, the socket transitions to passive ({active, false}) mode and the socket's controlling process receives a message to inform it of the transition. TCP sockets receive {tcp_passive,Socket}, UDP sockets receive {udp_passive,Socket} and SCTP sockets receive {sctp_passive,Socket}. The socket's delivered message counter defaults to 0, but it can be set using {active,N} via any gen_tcp, gen_udp, or gen_sctp function that takes socket options as arguments, or via inet:setopts/2. New N values are added to the socket's current counter value, and negative numbers can be used to reduce the counter value. Specifying a number that would cause the socket's counter value to go above 32767 causes an einval error. If a negative number is specified such that the counter value would become negative, the socket's counter value is set to 0 and the socket transitions to passive mode. If the counter value is already 0 and inet:setopts(Socket, [{active,0}]) is specified, the counter value remains at 0 but the appropriate passive mode transition message is generated for the socket. This commit contains a modified preloaded prim_inet.beam due to changes in prim_inet.erl. Add tests for {active,N} mode for TCP, UDP, and SCTP sockets. Add documentation for {active,N} mode for inet, gen_tcp, gen_udp, and gen_sctp. --- lib/kernel/doc/src/inet.xml | 51 +++++++++++++++++++++++++++++++-------------- 1 file changed, 35 insertions(+), 16 deletions(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index e1b0b34888..fb8bf32978 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -456,47 +456,66 @@ fe80::204:acff:fe17:bf38

Sets one or more options for a socket. The following options are available:

- {active, true | false | once} + {active, true | false | once | N}

If the value is true, which is the default, everything received from the socket will be sent as messages to the receiving process. If the value is false (passive mode), the process must explicitly - receive incoming data by calling gen_tcp:recv/2,3 - or gen_udp:recv/2,3 (depending on the type of - socket).

+ receive incoming data by calling + gen_tcp:recv/2,3, + gen_udp:recv/2,3 + or gen_sctp:recv/1,2 + (depending on the type of socket).

If the value is once ({active, once}), one data message from the socket will be sent to the process. To receive one more message, setopts/2 must be called again with the {active, once} option.

-

When using {active, once}, the socket changes - behaviour automatically when data is received. This can - sometimes be confusing in combination with connection - oriented sockets (i.e. gen_tcp) as a socket with - {active, false} behaviour reports closing +

If the value is an integer N in the range -32768 to 32767 + (inclusive), the value is added to the socket's count of data + messages sent to the controlling process. A socket's default + message count is 0. If a negative value is specified and its + magnitude is equal to or greater than the socket's current + message count, the socket's message count is set to 0. Once + the socket's message count reaches 0, either due to sending + received data messages to the process or by being explicitly set, + the process is then notified by a special message, specific to + the type of socket, that the socket has entered passive + mode. Once the socket enters passive mode, to receive more + messages setopts/2 must be called again to set the + socket back into an active mode.

+

When using {active, once} or {active, N}, the + socket changes behaviour automatically when data is received. + This can sometimes be confusing in combination with + connection-oriented sockets (i.e. gen_tcp) as a socket + with {active, false} behaviour reports closing differently than a socket with {active, true} behaviour. To make programming easier, a socket where the peer closed and this was detected while in {active, false} mode, will still generate the message - {tcp_closed,Socket} when set to {active, once} or {active, true} mode. It is therefore + {tcp_closed,Socket} when set to {active, once}, + {active, true} or {active, N} mode. It is therefore safe to assume that the message {tcp_closed,Socket}, possibly followed by socket port termination (depending on the exit_on_close option) will eventually appear when a socket changes back and forth between {active, true} and - {active, false} mode. However, + {active, false} mode. However, when peer closing is detected is all up to the underlying TCP/IP stack and protocol.

-

Note that {active,true} mode provides no flow +

Note that {active, true} mode provides no flow control; a fast sender could easily overflow the - receiver with incoming messages. Use active mode only if + receiver with incoming messages. The same is true of + {active, N} mode while the message count is greater + than zero. 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. {active,false} - mode or use of the {active, once} mode provides - flow control; the other side will not be able send + amount of data exchanged is small. {active, false} + mode, use of the {active, once} mode or {active, N} + mode with values of N appropriate for the application + provides flow control; the other side will not be able send faster than the receiver can read.

-- cgit v1.2.3 From b4d7911ac364eb913d89ff459a8354a1b3983416 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Mon, 18 Nov 2013 15:55:32 +0100 Subject: Document --- lib/kernel/doc/src/inet.xml | 76 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index fd62f778a2..c09cb6a1ef 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -434,6 +434,46 @@ fe80::204:acff:fe17:bf38 connection.

+ + + + Return all address/port numbers for the other end of a connection + + +

+ The same as + + peernames(Socket, 0) + . + Note that this function's behaviour for an SCTP + one-to-many style socket is not defined by the SCTP Socket API. +

+
+
+ + + + Return all address/port numbers for the other end of a connection + + +

+ Returns a list of all address/port number pairs for the other end + of a socket's association Assoc. +

+

+ This function can return multiple addresses for multihomed + sockets such as SCTP sockets. For other sockets it does the + same as peername/1. +

+

+ Note that the Assoc parameter + is by the SCTP Socket API defined to be ignored for + one-to-one style sockets. What the special value 0 + means hence its behaviour for one-to-many style sockets + is unfortunately not defined. +

+
+
Return the local port number for a socket @@ -448,6 +488,42 @@ fe80::204:acff:fe17:bf38

Returns the local address and port number for a socket.

+ + + Return all local address/port numbers for a socket + +

+ The same as + + socknames(Socket, 0) + . +

+
+
+ + + Return all local address/port numbers for a socket + +

+ Returns a list of all local address/port number pairs for a socket + for the given association Assoc. +

+

+ This function can return multiple addresses for multihomed + sockets such as SCTP sockets. For other sockets it does the + same as sockname/1. +

+

+ Note that the Assoc parameter + is by the SCTP Socket API defined to be ignored for + one-to-one style sockets. For one-to-many style sockets + the special value 0 is defined to mean that + the returned addresses shall be without regard to any + particular association. How different SCTP implementations + interprets this varies somewhat. +

+
+
Set one or more options for a socket -- cgit v1.2.3 From b9278a19e1abdb80d93833773f4b9c431958bdcb Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Mon, 25 Nov 2013 10:13:29 +0100 Subject: Improve documentation --- lib/kernel/doc/src/inet.xml | 60 +++++++++++++++++++++++++++------------------ 1 file changed, 36 insertions(+), 24 deletions(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index c09cb6a1ef..bc4c68230e 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -430,8 +430,16 @@ fe80::204:acff:fe17:bf38 Return the address and port for the other end of a connection -

Returns the address and port for the other end of a - connection.

+

+ Returns the address and port for the other end of a + connection. +

+

+ Note that for SCTP sockets this function only returns + one of the socket's peer addresses. The function + peernames/1,2 + returns all. +

@@ -441,12 +449,11 @@ fe80::204:acff:fe17:bf38

- The same as - - peernames(Socket, 0) - . + Equivalent to + peernames(Socket, 0). Note that this function's behaviour for an SCTP - one-to-many style socket is not defined by the SCTP Socket API. + one-to-many style socket is not defined by the + SCTP Sockets API Extensions.

@@ -462,12 +469,13 @@ fe80::204:acff:fe17:bf38

This function can return multiple addresses for multihomed - sockets such as SCTP sockets. For other sockets it does the - same as peername/1. + sockets such as SCTP sockets. For other sockets it + returns a one element list.

- Note that the Assoc parameter - is by the SCTP Socket API defined to be ignored for + Note that the Assoc parameter is by the + SCTP Sockets API Extensions + defined to be ignored for one-to-one style sockets. What the special value 0 means hence its behaviour for one-to-many style sockets is unfortunately not defined. @@ -486,6 +494,12 @@ fe80::204:acff:fe17:bf38 Return the local address and port number for a socket

Returns the local address and port number for a socket.

+

+ Note that for SCTP sockets this function only returns + one of the socket addresses. The function + socknames/1,2 + returns all. +

@@ -493,10 +507,8 @@ fe80::204:acff:fe17:bf38 Return all local address/port numbers for a socket

- The same as - - socknames(Socket, 0) - . + Equivalent to + socknames(Socket, 0).

@@ -510,17 +522,17 @@ fe80::204:acff:fe17:bf38

This function can return multiple addresses for multihomed - sockets such as SCTP sockets. For other sockets it does the - same as sockname/1. + sockets such as SCTP sockets. For other sockets it + returns a one element list.

- Note that the Assoc parameter - is by the SCTP Socket API defined to be ignored for - one-to-one style sockets. For one-to-many style sockets - the special value 0 is defined to mean that - the returned addresses shall be without regard to any - particular association. How different SCTP implementations - interprets this varies somewhat. + Note that the Assoc parameter is by the + SCTP Sockets API Extensions + defined to be ignored for one-to-one style sockets. + For one-to-many style sockets the special value 0 + is defined to mean that the returned addresses shall be + without regard to any particular association. + How different SCTP implementations interprets this varies somewhat.

-- cgit v1.2.3 From bef120698af5377b258446077a3d852484f79397 Mon Sep 17 00:00:00 2001 From: Danil Zagoskin Date: Sat, 10 May 2014 13:24:11 +0400 Subject: inet: fix typo in inet:getstat/2 doc The word 'received' in 'send_dvi' option description seems to be copy-pasted and not removed --- lib/kernel/doc/src/inet.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index 4a48a5c3d8..50e1cc290c 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -361,7 +361,7 @@ fe80::204:acff:fe17:bf38
send_dvi -

Average packet size deviation in bytes received sent from the socket.

+

Average packet size deviation in bytes sent from the socket.

send_max -- cgit v1.2.3 From 77f71fc05cc4eb378de0a16df6390b3781d18d36 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Magnus=20Lid=C3=A9n?= Date: Thu, 6 Nov 2014 10:46:20 +0100 Subject: Update documentation for buffer options --- lib/kernel/doc/src/inet.xml | 61 +++++++++++++++++++++++++++------------------ 1 file changed, 37 insertions(+), 24 deletions(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index 50e1cc290c..8dd311e5cd 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -138,7 +138,7 @@ fe80::204:acff:fe17:bf38 Return a list of IP configuration parameters -

Returns the state of the Inet configuration database in +

Returns the state of the Inet configuration database in form of a list of recorded configuration parameters. (See the ERTS User's Guide, Inet configuration, for more information). Only parameters with other than default values are returned.

@@ -258,8 +258,8 @@ fe80::204:acff:fe17:bf38 -

Gets one or more options for a socket. - See setopts/2 +

Gets one or more options for a socket. + See setopts/2 for a list of available options.

The number of elements in the returned OptionValues list does not necessarily correspond to the number of options @@ -278,14 +278,14 @@ fe80::204:acff:fe17:bf38 by the protocol level, the option number and either a binary or the size, in bytes, of the buffer in which the option value is to be stored. A binary - should be used when the underlying getsockopt requires + should be used when the underlying getsockopt requires input in the argument field, in which case the size of the binary should correspond to the required buffer size of the return value. The supplied values in a RawOptReq correspond to the second, third and fourth/fifth parameters to the getsockopt call in the C socket API. The value stored - in the buffer is returned as a binary ValueBin + in the buffer is returned as a binary ValueBin where all values are coded in the native endianess.

Asking for and inspecting raw socket options require low level information about the current operating system and TCP @@ -306,7 +306,7 @@ fe80::204:acff:fe17:bf38 value to be a 32 bit integer. We could use the following code to retrieve the value:

+ get_tcpi_sacked(Sock) -> {ok,[{raw,_,_,Info}]} = inet:getopts(Sock,[{raw,6,11,92}]), <<_:28/binary,TcpiSacked:32/native,_/binary>> = Info, TcpiSacked.]]> @@ -408,7 +408,7 @@ fe80::204:acff:fe17:bf38 Parse an IPv6 address strict. -

Parses an IPv6 address string and returns an ip6_address(). +

Parses an IPv6 address string and returns an ip6_address(). Does not accept IPv4 adresses.

@@ -613,15 +613,20 @@ fe80::204:acff:fe17:bf38
- {buffer, Size} + {buffer, Size} -

Determines the size of the user-level software buffer used by - the driver. Not to be confused with sndbuf - and recbuf options which correspond to - the kernel socket buffers. It is recommended - to have val(buffer) >= max(val(sndbuf),val(recbuf)). - In fact, the val(buffer) is automatically set to - the above maximum when sndbuf or recbuf values are set.

+

The size of the user-level software buffer used by + the driver. Not to be confused with sndbuf + and recbuf options which correspond to + the kernel socket buffers. It is recommended + to have val(buffer) >= max(val(sndbuf),val(recbuf)) to + avoid performance issues due to unnecessary copying. + In fact, the val(buffer) is automatically set to + the above maximum when sndbuf or recbuf values are set. + However, since the actual sizes set for sndbuf and recbuf + usually becomes larger, you are encouraged to use + inet:getopts/2 + to analyze the behavior of your operating system.

{delay_send, Boolean} @@ -998,8 +1003,12 @@ setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp {recbuf, Size} -

Gives the size of the receive buffer to use for - the socket.

+

The minimum size of the receive buffer to use for + the socket. You are encouraged to use + inet:getopts/2, + to retrieve the actual size set by your operating system. + +

{reuseaddr, Boolean} @@ -1030,20 +1039,24 @@ setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp {sndbuf, Size} -

Gives the size of the send buffer to use for the socket.

+

The minimum size of the send buffer to use for the socket. + You are encouraged to use + inet:getopts/2, + to retrieve the actual size set by your operating system. +

{priority, Integer} -

Sets the SO_PRIORITY socket level option on platforms where - this is implemented. The behaviour and allowed range varies on - different systems. The option is ignored on platforms where the +

Sets the SO_PRIORITY socket level option on platforms where + this is implemented. The behaviour and allowed range varies on + different systems. The option is ignored on platforms where the option is not implemented. Use with caution.

{tos, Integer} -

Sets IP_TOS IP level options on platforms where this is - implemented. The behaviour and allowed range varies on different - systems. The option is ignored on platforms where the option is +

Sets IP_TOS IP level options on platforms where this is + implemented. The behaviour and allowed range varies on different + systems. The option is ignored on platforms where the option is not implemented. Use with caution.

-- cgit v1.2.3 From d6628cffb5ce15237fd7cec774e1b69f526ece09 Mon Sep 17 00:00:00 2001 From: Daniel Kempkens Date: Thu, 19 Feb 2015 14:18:58 +0100 Subject: Fix typos ("received to the socket") --- lib/kernel/doc/src/inet.xml | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index 8dd311e5cd..77a8caaaf6 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -332,23 +332,23 @@ fe80::204:acff:fe17:bf38 recv_avg -

Average size of packets in bytes received to the socket.

+

Average size of packets in bytes received by the socket.

recv_cnt -

Number of packets received to the socket.

+

Number of packets received by the socket.

recv_dvi -

Average packet size deviation in bytes received to the socket.

+

Average packet size deviation in bytes received by the socket.

recv_max -

The size of the largest packet in bytes received to the socket.

+

The size of the largest packet in bytes received by the socket.

recv_oct -

Number of bytes received to the socket.

+

Number of bytes received by the socket.

send_avg -- cgit v1.2.3 From 4f63e427f1345b40b484ef16f6ff5e922bf14dac Mon Sep 17 00:00:00 2001 From: Rory Byrne Date: Mon, 20 Apr 2015 10:57:53 +0100 Subject: Add 'show_econnreset' TCP socket option An ECONNRESET is a socket error which tells us that a TCP peer has sent an RST. The RST indicates that they have aborted the connection and that the payload we have received should not be considered complete. Up until now, the implementation of TCP in inet_drv.c has hidden the receipt of the RST from the user, treating it as though it was just a FIN terminating the read side of the socket. There are many cases where user code needs to be able to distinguish between a socket that was closed normally and one that was aborted. Setting the option {show_econnreset, true} enables the user to receive ECONNRESET errors on both active and passive sockets. A connected socket returned from gen_tcp:accept/1 will inherit the show_econnreset setting of the listening socket. By default this option is set to {show_econnreset, false}. Note that this patch only enables the reporting of ECONNRESET when the socket is being read from. It does not report ECONNRESET (or EPIPE) when the user tries to write to a connection when an RST has already been received. Currently the TCP implementation in inet_drv.c hides all such send errors from the user in favour of returning {error, close}. A separate patch will be needed to enable the reporting of such errors. --- lib/kernel/doc/src/inet.xml | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index 77a8caaaf6..a364f9e0c9 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -1037,6 +1037,33 @@ setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp
+ {show_econnreset, Boolean}(TCP/IP sockets) + +

When this option is set to false, as it is by + default, an RST that is received from the TCP peer is treated + as a normal close (as though a FIN was sent). A caller + to gen_tcp:recv/2 + will get {error, closed}. In active + mode the controlling process will receive a + {tcp_close, Socket} message, indicating that the + peer has closed the connection.

+

Setting this option to true will allow you to + distinguish between a connection that was closed normally, + and one which was aborted (intentionally or unintentionally) + by the TCP peer. A call to + gen_tcp:recv/2 + will return {error, econnreset}. In + active mode, the controlling process will receive a + {tcp_error, Socket, econnreset} message + before the usual {tcp_closed, Socket}, as is + the case for any other socket error.

+

A connected socket returned from + gen_tcp:accept/1 + will inherit the show_econnreset setting from the + listening socket.

+ +
+ {sndbuf, Size}

The minimum size of the send buffer to use for the socket. -- cgit v1.2.3 From 0098eed847516cc6760d961421c83527816e35ae Mon Sep 17 00:00:00 2001 From: Rory Byrne Date: Sat, 2 May 2015 20:34:24 +0100 Subject: Apply 'show_econnreset' socket option to send errors as well Up till now all send errors have been translated into a generic {error, closed}. This patch allows {error, econnreset} to be returned on send errors when it is detected that the TCP peer has sent an RST. --- lib/kernel/doc/src/inet.xml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index a364f9e0c9..4dd9e0e221 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -1056,7 +1056,10 @@ setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp active mode, the controlling process will receive a {tcp_error, Socket, econnreset} message before the usual {tcp_closed, Socket}, as is - the case for any other socket error.

+ the case for any other socket error. Calls to + gen_tcp:send/2 + will also return {error, econnreset} when it + is detected that a TCP peer has sent an RST.

A connected socket returned from gen_tcp:accept/1 will inherit the show_econnreset setting from the -- cgit v1.2.3 From 738c34d4bb8f1a3811acd00af8c6c12107f8315b Mon Sep 17 00:00:00 2001 From: Bruce Yinhe Date: Thu, 18 Jun 2015 11:31:02 +0200 Subject: Change license text to APLv2 --- lib/kernel/doc/src/inet.xml | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index 4dd9e0e221..e5d7ce048a 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -8,16 +8,17 @@ Ericsson AB. All Rights Reserved. - The contents of this file are subject to the Erlang Public License, - Version 1.1, (the "License"); you may not use this file except in - compliance with the License. You should have received a copy of the - Erlang Public License along with this software. If not, it can be - retrieved online at http://www.erlang.org/. + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 - Software distributed under the License is distributed on an "AS IS" - basis, WITHOUT WARRANTY OF ANY KIND, either express or implied. See - the License for the specific language governing rights and limitations - under the License. + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. -- cgit v1.2.3 From afac3c7136c48d8630bd400c5454e146915e634f Mon Sep 17 00:00:00 2001 From: Serge Aleynikov Date: Mon, 26 Oct 2015 14:46:54 +0100 Subject: erts: Add {line_delimiter, byte()} option to inet:setopts/2 A new {line_delimiter, byte()} option allows line-oriented TCP-based protocols to use a custom line delimiting character. It is to be used in conjunction with {packet, line}. This option also works with erlang:decode_packet/3 when its first argument is 'line'. --- lib/kernel/doc/src/inet.xml | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index e5d7ce048a..e6d418dc58 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -981,6 +981,11 @@ setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp indicated length are accepted and not considered invalid due to internal buffer limitations.

+ {line_delimiter, Char}(TCP/IP sockets) + +

Sets the line delimiting character for line oriented protocols + (line). Default value is $\n.

+
{priority, Priority}

Set the protocol-defined priority for all packets to be sent -- cgit v1.2.3 From 02aca536aec93edd799d67615e47bdb7b5babf4a Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Fri, 9 Oct 2015 13:02:25 +0200 Subject: [kernel] Correct documentation Fix mistakes found by 'xmllint'. --- lib/kernel/doc/src/inet.xml | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index e6d418dc58..088d78c1d6 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -4,7 +4,7 @@

- 19972013 + 19972015 Ericsson AB. All Rights Reserved. @@ -117,8 +117,9 @@ fe80::204:acff:fe17:bf38 - socket() -

See gen_tcp(3) + socket() +

+ See gen_tcp(3) and gen_udp(3).

@@ -222,7 +223,7 @@ fe80::204:acff:fe17:bf38

Do not rely too much on the order of Flag atoms or - Ifopt tuples. There are some rules, though: + Ifopt tuples. There are some rules, though:

Immediately after {addr,_} follows {netmask,_} @@ -238,7 +239,6 @@ fe80::204:acff:fe17:bf38 tuple concerns that address. -

The {hwaddr,_} tuple is not returned on Solaris since the hardware address historically belongs to the link layer and only @@ -379,14 +379,14 @@ fe80::204:acff:fe17:bf38 Convert IPv6 / IPV4 adress to ascii -

Parses an ip_address() and returns an IPv4 or IPv6 address string.

+

Parses an ip_address() and returns an IPv4 or IPv6 address string.

Parse an IPv4 address -

Parses an IPv4 address string and returns an ip4_address(). +

Parses an IPv4 address string and returns an ip4_address(). Accepts a shortened IPv4 shortened address string.

@@ -394,14 +394,14 @@ fe80::204:acff:fe17:bf38 Parse an IPv4 address strict. -

Parses an IPv4 address string containing four fields, i.e not shortened, and returns an ip4_address().

+

Parses an IPv4 address string containing four fields, i.e not shortened, and returns an ip4_address().

Parse an IPv6 address -

Parses an IPv6 address string and returns an ip6_address(). +

Parses an IPv6 address string and returns an ip6_address(). If an IPv4 address string is passed, an IPv4-mapped IPv6 address is returned.

@@ -409,22 +409,22 @@ fe80::204:acff:fe17:bf38 Parse an IPv6 address strict. -

Parses an IPv6 address string and returns an ip6_address(). - Does not accept IPv4 adresses.

+

Parses an IPv6 address string and returns an ip6_address(). + Does not accept IPv4 adresses.

Parse an IPv4 or IPv6 address. -

Parses an IPv4 or IPv6 address string and returns an ip4_address() or ip6_address(). Accepts a shortened IPv4 address string.

+

Parses an IPv4 or IPv6 address string and returns an ip4_address() or ip6_address(). Accepts a shortened IPv4 address string.

Parse an IPv4 or IPv6 address strict. -

Parses an IPv4 or IPv6 address string and returns an ip4_address() or ip6_address(). Does not accept a shortened IPv4 address string.

+

Parses an IPv4 or IPv6 address string and returns an ip4_address() or ip6_address(). Does not accept a shortened IPv4 address string.

@@ -862,10 +862,10 @@ fe80::204:acff:fe17:bf38 CAP_SYS_ADMIN according to the documentation for setns(2). However, during testing also CAP_SYS_PTRACE and CAP_DAC_READ_SEARCH has proven to be necessary. - Example: + Example:

setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp - Note also that the filesystem containing the virtual machine +

Note also that the filesystem containing the virtual machine executable (beam.smp in the example above) has to be local, mounted without the nosetuid flag, support extended attributes and that -- cgit v1.2.3 From 3d70cee4034e4da37d125679345aa2a10c58cb34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Bj=C3=B6rn=20Gustavsson?= Date: Tue, 14 Apr 2015 23:21:36 +0200 Subject: Update Kernel documentation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Language cleaned up by technical writers from Combitech. Proofreading and corrections by Björn Gustavsson and Hans Bolinder. --- lib/kernel/doc/src/inet.xml | 1659 +++++++++++++++++++++---------------------- 1 file changed, 819 insertions(+), 840 deletions(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index 088d78c1d6..cfff393b8c 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -29,43 +29,47 @@ A

inet - Access to TCP/IP Protocols + Access to TCP/IP protocols. -

Provides access to TCP/IP protocols.

-

See also ERTS User's Guide, Inet configuration for more - information on how to configure an Erlang runtime system for IP - communication.

-

Two Kernel configuration parameters affect the behaviour of all - sockets opened on an Erlang node: - inet_default_connect_options can contain a list of default - options used for all sockets returned when doing connect, - and inet_default_listen_options can contain a list of - default options used when issuing a listen call. When - accept is issued, the values of the listensocket options - are inherited, why no such application variable is needed for +

This module provides access to TCP/IP protocols.

+

See also + ERTS User's Guide: + Inet Configuration for more information about how to + configure an Erlang runtime system for IP communication.

+

The following two Kernel configuration parameters affect the + behavior of all sockets opened on an Erlang node:

+ +

inet_default_connect_options can contain a list of + default options used for all sockets returned when doing + connect.

+

inet_default_listen_options can contain a list of + default options used when issuing a listen call.

+
+

When accept is issued, the values of the listening socket options + are inherited. No such application variable is therefore needed for accept.

-

Using the Kernel configuration parameters mentioned above, one - can set default options for all TCP sockets on a node. This should - be used with care, but options like {delay_send,true} - might be specified in this way. An example of starting an Erlang - node with all sockets using delayed send could look like this:

+

Using the Kernel configuration parameters above, one + can set default options for all TCP sockets on a node, but use this + with care. Options such as {delay_send,true} can be + specified in this way. The following is an example of starting an Erlang + node with all sockets using delayed send:

 $ erl -sname test -kernel \
 inet_default_connect_options '[{delay_send,true}]' \
 inet_default_listen_options '[{delay_send,true}]'
-

Note that the default option {active, true} currently +

Notice that default option {active, true} cannot be changed, for internal reasons.

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

-

IPv4 address examples:

+ tuple. For example, the IP address 150.236.20.73 can be passed to + gethostbyaddr/1, either as string "150.236.20.73" + or as tuple {150, 236, 20, 73}.

+

IPv4 address examples:

Address ip_address() ------- ------------ 127.0.0.1 {127,0,0,1} 192.168.42.2 {192,168,42,2} -

IPv6 address examples:

+

IPv6 address examples:

Address ip_address() ------- ------------ @@ -77,7 +81,9 @@ FFFF::192.168.42.2 {16#3ffe,16#b80,16#1f8d,16#2,16#204,16#acff,16#fe17,16#bf38} fe80::204:acff:fe17:bf38 {16#fe80,0,0,0,0,16#204,16#acff,16#fe17,16#bf38} -

A function that may be useful is parse_address/1:

+

Function + parse_address/1 + can be useful:

 1> inet:parse_address("192.168.42.2").
 {ok,{192,168,42,2}}
@@ -89,9 +95,12 @@ fe80::204:acff:fe17:bf38
     
       
       
-        

The record is defined in the Kernel include file "inet.hrl". - Add the following directive to the module:

--include_lib("kernel/include/inet.hrl").
+

The record is defined in the Kernel include file + "inet.hrl".

+

Add the following directive to the module:

+ +-include_lib("kernel/include/inet.hrl"). +
@@ -110,17 +119,20 @@ fe80::204:acff:fe17:bf38 -

An atom which is named from the Posix error codes - used in Unix, and in the runtime libraries of most - C compilers. See + +

An atom that is named from the POSIX error codes used in Unix, + and in the runtime libraries of most C compilers. See section POSIX Error Codes.

socket() -

- See gen_tcp(3) - and gen_udp(3).

+ +

See + gen_tcp:type-socket + and + gen_udp:type-socket. +

@@ -131,443 +143,415 @@ fe80::204:acff:fe17:bf38 - Close a socket of any type + Close a socket of any type.

Closes a socket of any type.

+ - - Return a list of IP configuration parameters + + Return a descriptive string for an error reason. -

Returns the state of the Inet configuration database in - form of a list of recorded configuration parameters. (See the - ERTS User's Guide, Inet configuration, for more information). - Only parameters with other than default values are returned.

+

Returns a diagnostic error string. For possible POSIX values and + corresponding strings, see section + POSIX Error Codes.

+ - - Return a descriptive string for an error reason + + Return a list of IP configuration parameters. -

Returns a diagnostic error string. See the section below - for possible Posix values and the corresponding - strings.

+

Returns the state of the Inet configuration database in + form of a list of recorded configuration parameters. For more + information, see ERTS User's Guide: + Inet Configuration. + Only parameters with other than default values are returned.

+ - Return the IP-address for a host + Return the IP address for a host. -

Returns the IP-address for Host as a tuple of - integers. Host can be an IP-address, a single hostname - or a fully qualified hostname.

+

Returns the IP address for Host as a tuple of + integers. Host can be an IP address, a single + hostname, or a fully qualified hostname.

+ - Return the IP-addresses for a host + Return the IP addresses for a host. -

Returns a list of all IP-addresses for Host. - Host can be an IP-address, a single hostname or a fully - qualified hostname.

+

Returns a list of all IP addresses for Host. + Host can be an IP address, a single hostname, or + a fully qualified hostname.

+ - Return a hostent record for the host with the given address + Return a hostent record for the host with the specified + address. -

Returns a hostent record given an address.

-
+

Returns a hostent record for the host with the specified + address.

+ - Return a hostent record for the host with the given name + Return a hostent record for the host with the specified name. + -

Returns a hostent record given a hostname.

+

Returns a hostent record for the host with the specified + hostname.

+ - Return a hostent record for the host with the given name + Return a hostent record for the host with the specified name. + -

Returns a hostent record given a hostname, restricted - to the given address family.

+

Returns a hostent record for the host with the specified + name, restricted to the specified address family.

+ - Return the local hostname + Return the local hostname. -

Returns the local hostname. Will never fail.

+

Returns the local hostname. Never fails.

- Return a list of interfaces and their addresses - -

- Returns a list of 2-tuples containing interface names and the - interface's addresses. Ifname is a Unicode string. - Hwaddr is hardware dependent, e.g on Ethernet interfaces - it is the 6-byte Ethernet address (MAC address (EUI-48 address)). -

-

- The {addr,Addr}, {netmask,_} and {broadaddr,_} - tuples are repeated in the result list iff the interface has multiple - addresses. If you come across an interface that has - multiple {flag,_} or {hwaddr,_} tuples you have - a really strange interface or possibly a bug in this function. - The {flag,_} tuple is mandatory, all other optional. -

-

- Do not rely too much on the order of Flag atoms or - Ifopt tuples. There are some rules, though:

- - - Immediately after {addr,_} follows {netmask,_} - - - Immediately thereafter follows {broadaddr,_} if - the broadcast flag is not set and the - pointtopoint flag is set. - - - Any {netmask,_}, {broadaddr,_} or - {dstaddr,_} tuples that follow an {addr,_} - tuple concerns that address. - - -

- The {hwaddr,_} tuple is not returned on Solaris since the - hardware address historically belongs to the link layer and only - the superuser can read such addresses. -

-

- On Windows, the data is fetched from quite different OS API - functions, so the Netmask and Broadaddr - values may be calculated, just as some Flag values. - You have been warned. Report flagrant bugs. -

-
+ Return a list of interfaces and their addresses. + +

Returns a list of 2-tuples containing interface names and the + interface addresses. Ifname is a Unicode string. + Hwaddr is hardware dependent, for example, on + Ethernet interfaces + it is the 6-byte Ethernet address (MAC address (EUI-48 address)).

+

The tuples {addr,Addr}, {netmask,_}, and + {broadaddr,_} are repeated in the result list if the interface + has multiple addresses. If you come across an interface with + multiple {flag,_} or {hwaddr,_} tuples, you have + a strange interface or possibly a bug in this function. The tuple + {flag,_} is mandatory, all others are optional.

+

Do not rely too much on the order of Flag atoms + or Ifopt tuples. There are however some rules:

+ +

Immediately after + {addr,_} follows {netmask,_}.

+

Immediately thereafter follows {broadaddr,_} if flag + broadcast is not set and flag + pointtopoint is set.

+

Any {netmask,_}, {broadaddr,_}, or + {dstaddr,_} tuples that follow an {addr,_} + tuple concerns that address.

+
+

The tuple {hwaddr,_} is not returned on Solaris, as the + hardware address historically belongs to the link layer and only + the superuser can read such addresses.

+ +

On Windows, the data is fetched from different OS API functions, + so the Netmask and Broadaddr + values can be calculated, just as some Flag + values. Report flagrant bugs.

+
+
- Get one or more options for a socket + Get one or more options for a socket. -

Gets one or more options for a socket. - See setopts/2 - for a list of available options.

-

The number of elements in the returned OptionValues +

Gets one or more options for a socket. For a list of available + options, see + setopts/2.

+

The number of elements in the returned + OptionValues list does not necessarily correspond to the number of options asked for. If the operating system fails to support an option, - it is simply left out in the returned list. An error tuple is only - returned when getting options for the socket is impossible - (i.e. the socket is closed or the buffer size in a raw request + it is left out in the returned list. An error tuple is returned + only when getting options for the socket is impossible (that is, + the socket is closed or the buffer size in a raw request is too large). This behavior is kept for backward compatibility reasons.

-

A raw option request RawOptReq = {raw, Protocol, OptionNum, ValueSpec} can be used to get information about +

A raw option request + RawOptReq = {raw, Protocol, OptionNum, ValueSpec} + can be used to get information about socket options not (explicitly) supported by the emulator. The - use of raw socket options makes the code non portable, but + use of raw socket options makes the code non-portable, but allows the Erlang programmer to take advantage of unusual features present on the current platform.

-

The RawOptReq consists of the tag raw followed - by the protocol level, the option number and either a binary +

RawOptReq consists of tag raw followed + by the protocol level, the option number, and either a binary or the size, in bytes, of the - buffer in which the option value is to be stored. A binary - should be used when the underlying getsockopt requires - input - in the argument field, in which case the size of the binary - should correspond to the required buffer + buffer in which the option value is to be stored. A binary is to be + used when the underlying getsockopt requires input + in the argument field. In this case, the binary size + is to correspond to the required buffer size of the return value. The supplied values in a RawOptReq - correspond to the second, third and fourth/fifth parameters to the + correspond to the second, third, and fourth/fifth parameters to the getsockopt call in the C socket API. The value stored - in the buffer is returned as a binary ValueBin + in the buffer is returned as a binary ValueBin, where all values are coded in the native endianess.

-

Asking for and inspecting raw socket options require low - level information about the current operating system and TCP - stack.

-

As an example, consider a Linux machine where the - TCP_INFO option could be used to collect TCP statistics - for a socket. Lets say we're interested in the - tcpi_sacked field of the struct tcp_info - filled in when asking for TCP_INFO. To - be able to access this information, we need to know both the - numeric value of the protocol level IPPROTO_TCP, the - numeric value of the option TCP_INFO, the size of the - struct tcp_info and the size and offset of - the specific field. By inspecting the headers or writing a small C - program, we found IPPROTO_TCP to be 6, - TCP_INFO to be 11, the structure size to be 92 (bytes), - the offset of tcpi_sacked to be 28 bytes and the actual - value to be a 32 bit integer. We could use the following - code to retrieve the value:

+

Asking for and inspecting raw socket options require low-level + information about the current operating system and TCP stack.

+

Example:

+

Consider a Linux machine where option + TCP_INFO can be used to collect TCP statistics + for a socket. Assume you are interested in field + tcpi_sacked of struct tcp_info + filled in when asking for TCP_INFO. To be able to access + this information, you need to know the following:

+ + The numeric value of protocol level IPPROTO_TCP + The numeric value of option TCP_INFO + The size of struct tcp_info + The size and offset of the specific field + +

By inspecting the headers or writing a small C program, it is found + that IPPROTO_TCP is 6, TCP_INFO is 11, the structure + size is 92 (bytes), the offset of tcpi_sacked is 28 bytes, + and the value is a 32-bit integer. The following code can be used + to retrieve the value:

- {ok,[{raw,_,_,Info}]} = inet:getopts(Sock,[{raw,6,11,92}]), - <<_:28/binary,TcpiSacked:32/native,_/binary>> = Info, - TcpiSacked.]]> -

Preferably, you would check the machine type, the OS - and the kernel version prior to executing anything similar to the - code above.

+get_tcpi_sacked(Sock) -> + {ok,[{raw,_,_,Info}]} = inet:getopts(Sock,[{raw,6,11,92}]), + <<_:28/binary,TcpiSacked:32/native,_/binary>> = Info, + TcpiSacked.]]>
+

Preferably, you would check the machine type, the operating system, + and the Kernel version before executing anything similar to + this code.

- Get one or more statistic options for a socket + Get one or more statistic options for a socket.

Gets one or more statistic options for a socket.

- -

getstat(Socket) is equivalent to - getstat(Socket, [recv_avg, recv_cnt, recv_dvi, - recv_max, recv_oct, send_avg, send_cnt, send_dvi, send_max, - send_oct]).

-

The following options are available:

+

getstat(Socket) is equivalent to + getstat(Socket, [recv_avg, recv_cnt, recv_dvi, + recv_max, recv_oct, send_avg, send_cnt, send_dvi, send_max, + send_oct]).

+

The following options are available:

- recv_avg - -

Average size of packets in bytes received by the socket.

-
- recv_cnt - + recv_avg + +

Average size of packets, in bytes, received by the socket.

+
+ recv_cnt +

Number of packets received by the socket.

-
- recv_dvi - -

Average packet size deviation in bytes received by the socket.

-
- recv_max - -

The size of the largest packet in bytes received by the socket.

-
- recv_oct - + + recv_dvi + +

Average packet size deviation, in bytes, received by the socket.

+
+ recv_max + +

Size of the largest packet, in bytes, received by the socket.

+
+ recv_oct +

Number of bytes received by the socket.

-
- - send_avg - -

Average size of packets in bytes sent from the socket.

-
- send_cnt - + + send_avg + +

Average size of packets, in bytes, sent from the socket.

+
+ send_cnt +

Number of packets sent from the socket.

-
- send_dvi - -

Average packet size deviation in bytes sent from the socket.

-
- send_max - -

The size of the largest packet in bytes sent from the socket.

-
- send_oct - + + send_dvi + +

Average packet size deviation, in bytes, sent from the socket.

+
+ send_max + +

Size of the largest packet, in bytes, sent from the socket.

+
+ send_oct +

Number of bytes sent from the socket.

-
+
+ - Convert IPv6 / IPV4 adress to ascii + Convert IPv6/IPV4 address to ASCII. + +

Parses an + ip_address() + and returns an IPv4 or IPv6 address string.

+
+
+ + + + Parse an IPv4 or IPv6 address. -

Parses an ip_address() and returns an IPv4 or IPv6 address string.

+

Parses an IPv4 or IPv6 address string and returns an + ip4_address() or + ip6_address(). + Accepts a shortened IPv4 address string.

+ - Parse an IPv4 address + Parse an IPv4 address. -

Parses an IPv4 address string and returns an ip4_address(). - Accepts a shortened IPv4 shortened address string.

+

Parses an IPv4 address string and returns an + ip4_address(). + Accepts a shortened IPv4 address string.

+ Parse an IPv4 address strict. -

Parses an IPv4 address string containing four fields, i.e not shortened, and returns an ip4_address().

+

Parses an IPv4 address string containing four fields, that is, + not shortened, and returns an + ip4_address(). +

+ - Parse an IPv6 address + Parse an IPv6 address. -

Parses an IPv6 address string and returns an ip6_address(). - If an IPv4 address string is passed, an IPv4-mapped IPv6 address is returned.

+

Parses an IPv6 address string and returns an + ip6_address(). + If an IPv4 address string is specified, an IPv4-mapped IPv6 address + is returned.

+ Parse an IPv6 address strict. -

Parses an IPv6 address string and returns an ip6_address(). - Does not accept IPv4 adresses.

-
-
- - - Parse an IPv4 or IPv6 address. - -

Parses an IPv4 or IPv6 address string and returns an ip4_address() or ip6_address(). Accepts a shortened IPv4 address string.

+

Parses an IPv6 address string and returns an + ip6_address(). + Does not accept IPv4 addresses.

+ Parse an IPv4 or IPv6 address strict. -

Parses an IPv4 or IPv6 address string and returns an ip4_address() or ip6_address(). Does not accept a shortened IPv4 address string.

+

Parses an IPv4 or IPv6 address string and returns an + ip4_address() or + ip6_address(). + Does not accept a shortened IPv4 address string.

+ - Return the address and port for the other end of a connection + Return the address and port for the other end of a connection. + -

- Returns the address and port for the other end of a - connection. -

-

- Note that for SCTP sockets this function only returns - one of the socket's peer addresses. The function - peernames/1,2 - returns all. -

+

Returns the address and port for the other end of a connection.

+

Notice that for SCTP sockets, this function returns only + one of the peer addresses of the socket. Function + peernames/1,2 + returns all.

+ - - Return all address/port numbers for the other end of a connection - + Return all address/port numbers for the other end of a + connection. -

- Equivalent to +

Equivalent to peernames(Socket, 0). - Note that this function's behaviour for an SCTP +

+

Notice that the behavior of this function for an SCTP one-to-many style socket is not defined by the - SCTP Sockets API Extensions. -

+ SCTP Sockets API Extensions.

+ - - Return all address/port numbers for the other end of a connection - + Return all address/port numbers for the other end of a + connection. -

- Returns a list of all address/port number pairs for the other end - of a socket's association Assoc. -

-

- This function can return multiple addresses for multihomed - sockets such as SCTP sockets. For other sockets it - returns a one element list. -

-

- Note that the Assoc parameter is by the +

Returns a list of all address/port number pairs for the other end + of an association Assoc of a socket.

+

This function can return multiple addresses for multihomed + sockets, such as SCTP sockets. For other sockets it + returns a one-element list.

+

Notice that parameter Assoc is by the SCTP Sockets API Extensions defined to be ignored for - one-to-one style sockets. What the special value 0 - means hence its behaviour for one-to-many style sockets - is unfortunately not defined. -

+ one-to-one style sockets. What the special value 0 + means, hence its behavior for one-to-many style sockets, + is unfortunately undefined.

+ - Return the local port number for a socket + Return the local port number for a socket.

Returns the local port number for a socket.

- - - Return the local address and port number for a socket - -

Returns the local address and port number for a socket.

-

- Note that for SCTP sockets this function only returns - one of the socket addresses. The function - socknames/1,2 - returns all. -

-
-
- - - Return all local address/port numbers for a socket - -

- Equivalent to - socknames(Socket, 0). -

-
-
- - - Return all local address/port numbers for a socket - -

- Returns a list of all local address/port number pairs for a socket - for the given association Assoc. -

-

- This function can return multiple addresses for multihomed - sockets such as SCTP sockets. For other sockets it - returns a one element list. -

-

- Note that the Assoc parameter is by the - SCTP Sockets API Extensions - defined to be ignored for one-to-one style sockets. - For one-to-many style sockets the special value 0 - is defined to mean that the returned addresses shall be - without regard to any particular association. - How different SCTP implementations interprets this varies somewhat. -

-
-
+ - Set one or more options for a socket + Set one or more options for a socket. -

Sets one or more options for a socket. The following options - are available:

+

Sets one or more options for a socket.

+

The following options are available:

{active, true | false | once | N}

If the value is true, which is the default, - everything received from the socket will be sent as - messages to the receiving process. If the value is - false (passive mode), the process must explicitly - receive incoming data by calling + everything received from the socket is sent as + messages to the receiving process.

+

If the value is false (passive mode), the process must + explicitly receive incoming data by calling gen_tcp:recv/2,3, - gen_udp:recv/2,3 + gen_udp:recv/2,3, or gen_sctp:recv/1,2 (depending on the type of socket).

If the value is once ({active, once}), - one data message from the socket will be sent - to the process. To receive one more message, - setopts/2 must be called again with the - {active, once} option.

+ one data message from the socket is sent + to the process. To receive one more message, + setopts/2 must be called again with option + {active, once}.

If the value is an integer N in the range -32768 to 32767 (inclusive), the value is added to the socket's count of data messages sent to the controlling process. A socket's default - message count is 0. If a negative value is specified and its - magnitude is equal to or greater than the socket's current - message count, the socket's message count is set to 0. Once - the socket's message count reaches 0, either due to sending + message count is 0. If a negative value is specified, and + its magnitude is equal to or greater than the socket's current + message count, the socket's message count is set to 0. + Once the socket's message count reaches 0, either because + of sending received data messages to the process or by being explicitly set, the process is then notified by a special message, specific to the type of socket, that the socket has entered passive @@ -575,339 +559,298 @@ fe80::204:acff:fe17:bf38 messages setopts/2 must be called again to set the socket back into an active mode.

When using {active, once} or {active, N}, the - socket changes behaviour automatically when data is received. - This can sometimes be confusing in combination with - connection-oriented sockets (i.e. gen_tcp) as a socket - with {active, false} behaviour reports closing + socket changes behavior automatically when data is received. + This can be confusing in combination with connection-oriented + sockets (that is, gen_tcp), as a socket + with {active, false} behavior reports closing differently than a socket with {active, true} - behaviour. To make programming easier, a socket where - the peer closed and this was detected while in - {active, false} mode, will still generate the - message + behavior. To simplify programming, a socket where + the peer closed, and this is detected while in + {active, false} mode, still generates message {tcp_closed,Socket} when set to {active, once}, - {active, true} or {active, N} mode. It is therefore - safe to assume that the message - {tcp_closed,Socket}, possibly followed by socket - port termination (depending on the exit_on_close - option) will eventually appear when a socket changes + {active, true}, or {active, N} mode. + It is therefore safe to assume that message + {tcp_closed,Socket}, possibly followed by socket port + termination (depending on option exit_on_close) + eventually appears when a socket changes back and forth between {active, true} and {active, false} mode. However, - when peer closing is detected is all up to the + when peer closing is detected it is all up to the underlying TCP/IP stack and protocol.

-

Note that {active, true} mode provides no flow - control; a fast sender could easily overflow the - receiver with incoming messages. The same is true of - {active, N} mode while the message count is greater - than zero. Use active mode only if +

Notice that {active, true} mode provides no flow + control; a fast sender can easily overflow the + receiver with incoming messages. The same is true for + {active, N} mode, while the message count is greater + than zero.

+

Use active mode only if your high-level protocol provides its own flow control - (for instance, acknowledging received messages) or the + (for example, acknowledging received messages) or the amount of data exchanged is small. {active, false} - mode, use of the {active, once} mode or {active, N} + mode, use of the {active, once} mode, or {active, N} mode with values of N appropriate for the application - provides flow control; the other side will not be able send + provides flow control. The other side cannot send faster than the receiver can read.

- - {broadcast, Boolean}(UDP sockets) + {broadcast, Boolean} (UDP sockets) -

Enable/disable permission to send broadcasts.

- +

Enables/disables permission to send broadcasts.

+ +
+ {buffer, Size} + +

The size of the user-level software buffer used by + the driver. Not to be confused with options sndbuf + and recbuf, which correspond to the + Kernel socket buffers. It is recommended + to have val(buffer) >= max(val(sndbuf),val(recbuf)) to + avoid performance issues because of unnecessary copying. + val(buffer) is automatically set to the above + maximum when values sndbuf or recbuf are set. + However, as the sizes set for sndbuf and recbuf + usually become larger, you are encouraged to use + getopts/2 + to analyze the behavior of your operating system.

- - {buffer, Size} - -

The size of the user-level software buffer used by - the driver. Not to be confused with sndbuf - and recbuf options which correspond to - the kernel socket buffers. It is recommended - to have val(buffer) >= max(val(sndbuf),val(recbuf)) to - avoid performance issues due to unnecessary copying. - In fact, the val(buffer) is automatically set to - the above maximum when sndbuf or recbuf values are set. - However, since the actual sizes set for sndbuf and recbuf - usually becomes larger, you are encouraged to use - inet:getopts/2 - to analyze the behavior of your operating system.

-
- {delay_send, Boolean}

Normally, when an Erlang process sends to a socket, - the driver will try to immediately send the data. If that - fails, the driver will use any means available to queue + the driver tries to send the data immediately. If that + fails, the driver uses any means available to queue up the message to be sent whenever the operating system says it can handle it. Setting {delay_send, true} - will make all messages queue up. This makes - the messages actually sent onto the network be larger but - fewer. The option actually affects the scheduling of send + makes all messages queue up. The messages sent + to the network are then larger but fewer. + The option affects the scheduling of send requests versus Erlang processes instead of changing any - real property of the socket. Needless to say it is an - implementation specific option. Default is false.

+ real property of the socket. The option is + implementation-specific. Defaults to false.

+
+ {deliver, port | term} + +

When {active, true}, data is delivered on the form + port : {S, {data, [H1,..Hsz | Data]}} or + term : {tcp, S, [H1..Hsz | Data]}.

- - {deliver, port | term} -

When {active, true} delivers data on the forms - port : {S, {data, [H1,..Hsz | Data]}} or - term : {tcp, S, [H1..Hsz | Data]}. -

-
- {dontroute, Boolean} -

Enable/disable routing bypass for outgoing messages.

+

Enables/disables routing bypass for outgoing messages.

- {exit_on_close, Boolean} -

By default this option is set to true.

+

This option is set to true by default.

The only reason to set it to false is if you want - to continue sending data to the socket after a close has - been detected, for instance if the peer has used - gen_tcp:shutdown/2 - to shutdown the write side.

+ to continue sending data to the socket after a close is + detected, for example, if the peer uses + gen_tcp:shutdown/2 + to shut down the write side.

- {header, Size} -

This option is only meaningful if the binary - option was specified when the socket was created. If - the header option is specified, the first +

This option is only meaningful if option binary + was specified when the socket was created. If option + header 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 + are elements of a list, and the remaining data is + a binary specified as the tail of the same list. For example, + if Size == 2, the data received matches [Byte1,Byte2|Binary].

- {high_msgq_watermark, Size} -

The socket message queue will be set into a busy - state when the amount of data queued on the message - queue reaches this limit. Note that this limit only - concerns data that have not yet reached the ERTS internal - socket implementation. Default value used is 8 kB.

-

Senders of data to the socket will be suspended if - either the socket message queue is busy, or the socket - itself is busy.

-

For more information see the low_msgq_watermark, - high_watermark, and low_watermark options.

-

Note that distribution sockets will disable the use of - high_msgq_watermark and low_msgq_watermark, - and will instead use the - distribution - buffer busy limit which is a similar feature.

+

The socket message queue is set to a busy + state when the amount of data on the message + queue reaches this limit. Notice that this limit only + concerns data that has not yet reached the ERTS internal + socket implementation. Defaults to 8 kB.

+

Senders of data to the socket are suspended if + either the socket message queue is busy or the socket + itself is busy.

+

For more information, see options low_msgq_watermark, + high_watermark, and low_watermark.

+

Notice that distribution sockets disable the use of + high_msgq_watermark and low_msgq_watermark. + Instead use the + distribution buffer busy limit, + which is a similar feature.

- {high_watermark, Size} (TCP/IP sockets) -

The socket will be set into a busy state when the amount - of data queued internally by the ERTS socket implementation - reaches this limit. Default value used is 8 kB.

-

Senders of data to the socket will be suspended if - either the socket message queue is busy, or the socket - itself is busy.

-

For more information see the low_watermark, - high_msgq_watermark, and low_msqg_watermark - options.

+

The socket is set to a busy state when the amount + of data queued internally by the ERTS socket implementation + reaches this limit. Defaults to 8 kB.

+

Senders of data to the socket are suspended if + either the socket message queue is busy or the socket + itself is busy.

+

For more information, see options low_watermark, + high_msgq_watermark, and low_msqg_watermark.

- {ipv6_v6only, Boolean} -

- Restricts the socket to only use IPv6, prohibiting any +

Restricts the socket to use only IPv6, prohibiting any IPv4 connections. This is only applicable for - IPv6 sockets (option inet6). -

-

- On most platforms this option has to be set on the socket - before associating it to an address. Therefore it is only - reasonable to give it when creating the socket and not - to use it when calling the function - (setopts/2) - containing this description. -

-

- The behaviour of a socket with this socket option set to - true is becoming the only portable one. The original + IPv6 sockets (option inet6).

+

On most platforms this option must be set on the socket + before associating it to an address. It is therefore only + reasonable to specify it when creating the socket and not + to use it when calling function + (setopts/2) + containing this description.

+

The behavior of a socket with this option set to + true is the only portable one. The original idea when IPv6 was new of using IPv6 for all traffic is now not recommended by FreeBSD (you can use {ipv6_v6only,false} to override the recommended system default value), - forbidden by OpenBSD (the supported GENERIC kernel) - and impossible on Windows (that has separate + forbidden by OpenBSD (the supported GENERIC kernel), + and impossible on Windows (which has separate IPv4 and IPv6 protocol stacks). Most Linux distros still have a system default value of false. - This policy shift among operating systems towards - separating IPv6 from IPv4 traffic has evolved since + This policy shift among operating systems to + separate IPv6 from IPv4 traffic has evolved, as it gradually proved hard and complicated to get - a dual stack implementation correct and secure. -

-

- On some platforms the only allowed value for this option - is true, e.g. OpenBSD and Windows. Trying to set - this option to false when creating the socket - will in this case fail. -

-

- Setting this option on platforms where it does not exist - is ignored and getting this option with - getopts/2 - returns no value i.e the returned list will not contain an - {ipv6_v6only,_} tuple. On Windows the option acually - does not exist, but it is emulated as being a - read-only option with the value true. -

-

- So it boils down to that setting this option to true - when creating a socket will never fail except possibly - (at the time of this writing) on a platform where you + a dual stack implementation correct and secure.

+

On some platforms, the only allowed value for this option + is true, for example, OpenBSD and Windows. Trying to set + this option to false, when creating the socket, fails + in this case.

+

Setting this option on platforms where it does not exist + is ignored. Getting this option with + getopts/2 + returns no value, that is, the returned list does not contain an + {ipv6_v6only,_} tuple. On Windows, the option + does not exist, but it is emulated as a + read-only option with value true.

+

Therefore, setting this option to true + when creating a socket never fails, except possibly on a + platform where you have customized the kernel to only allow false, - which might be doable (but weird) on e.g. OpenBSD. -

-

- If you read back the option value using - getopts/2 - and get no value the option does not exist in the host OS - and all bets are off regarding the behaviour of both - an IPv6 and an IPv4 socket listening on the same port - as well as for an IPv6 socket getting IPv4 traffic. -

+ which can be doable (but awkward) on, for example, OpenBSD.

+

If you read back the option value using + getopts/2 + and get no value, the option does not exist in the host + operating system. The behavior of both an IPv6 and an IPv4 + socket listening on the same port, and for an IPv6 socket + getting IPv4 traffic is then no longer predictable.

- {keepalive, Boolean}(TCP/IP sockets)

Enables/disables periodic transmission on a connected - socket, when no other data is being exchanged. If + socket when no other data is exchanged. If the other end does not respond, the connection is - considered broken and an error message will be sent to - the controlling process. Default disabled.

- + considered broken and an error message is sent to + the controlling process. Defaults to disabled.

+ +
+ {linger, {true|false, Seconds}} + +

Determines the time-out, in seconds, for flushing unsent data + in the close/1 socket call. If the first component of + the value tuple is false, the second is ignored. This + means that close/1 returns immediately, not waiting + for data to be flushed. Otherwise, the second component is + the flushing time-out, in seconds.

- - {linger, {true|false, Seconds}} - -

Determines the timeout in seconds for flushing unsent data in the - close/1 socket call. If the 1st component of the value - tuple is false, the 2nd one is ignored, which means that - close/1 returns immediately not waiting - for data to be flushed. Otherwise, the 2nd component is - the flushing time-out in seconds.

-
- {low_msgq_watermark, Size}

If the socket message queue is in a busy state, the - socket message queue will be set in a not busy state when - the amount of data queued in the message queue falls - below this limit. Note that this limit only concerns data - that have not yet reached the ERTS internal socket - implementation. Default value used is 4 kB.

-

Senders that have been suspended due to either a - busy message queue or a busy socket, will be resumed - when neither the socket message queue, nor the socket - are busy.

-

For more information see the high_msgq_watermark, - high_watermark, and low_watermark options.

-

Note that distribution sockets will disable the use of - high_msgq_watermark and low_msgq_watermark, - and will instead use the - distribution - buffer busy limit which is a similar feature.

+ socket message queue is set in a not busy state when + the amount of data queued in the message queue falls + below this limit. Notice that this limit only concerns data + that has not yet reached the ERTS internal socket + implementation. Defaults to 4 kB.

+

Senders that are suspended because of either a + busy message queue or a busy socket are resumed + when the socket message queue and the socket + are not busy.

+

For more information, see options high_msgq_watermark, + high_watermark, and low_watermark.

+

Notice that distribution sockets disable the use of + high_msgq_watermark and low_msgq_watermark. + Instead they use the + distribution + buffer busy limit, which is a similar feature.

- {low_watermark, Size} (TCP/IP sockets) -

If the socket is in a busy state, the socket will - be set in a not busy state when the amount of data - queued internally by the ERTS socket implementation - falls below this limit. Default value used is 4 kB.

-

Senders that have been suspended due to either a - busy message queue or a busy socket, will be resumed - when neither the socket message queue, nor the socket - are busy.

-

For more information see the high_watermark, - high_msgq_watermark, and low_msgq_watermark - options.

+

If the socket is in a busy state, the socket is + set in a not busy state when the amount of data + queued internally by the ERTS socket implementation + falls below this limit. Defaults to 4 kB.

+

Senders that are suspended because of a + busy message queue or a busy socket are resumed + when the socket message queue and the socket are not busy.

+

For more information, see options high_watermark, + high_msgq_watermark, and low_msgq_watermark.

- - {mode, Mode :: binary | list} + {mode, Mode :: binary | list} -

Received Packet is delivered as defined by Mode.

-
- +

Received Packet is delivered as defined by Mode. +

+ {netns, Namespace :: file:filename_all()} -

Set a network namespace for the socket. The Namespace - parameter is a filename defining the namespace for example - "/var/run/netns/example" typically created by the command - ip netns add example. This option must be used in a - function call that creates a socket i.e - - gen_tcp:connect/3,4, - - gen_tcp:listen/2, - - gen_udp:open/1,2 or - - gen_sctp:open/0-2. -

-

This option uses the Linux specific syscall - setns() such as in Linux kernel 3.0 or later - and therefore only exists when the runtime system - has been compiled for such an operating system. -

-

- The virtual machine also needs elevated privileges either - running as superuser or (for Linux) having the capability - CAP_SYS_ADMIN according to the documentation for setns(2). - However, during testing also CAP_SYS_PTRACE - and CAP_DAC_READ_SEARCH has proven to be necessary. - Example:

-setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp - -

Note also that the filesystem containing the virtual machine - executable (beam.smp in the example above) has to be local, - mounted without the nosetuid flag, - support extended attributes and that - the kernel has to support file capabilities. - All this runs out of the box on at least Ubuntu 12.04 LTS, - except that SCTP sockets appears to not support - network namespaces. -

-

The Namespace is a file name and is encoded - and decoded as discussed in - file - except that the emulator flag +fnu is ignored and - getopts/2 - for this option will return a binary for the filename - if the stored filename can not be decoded, - which should only happen if you set the option using a binary - that can not be decoded with the emulator's filename encoding: - - file:native_name_encoding/0. -

-
- - list +

Sets a network namespace for the socket. Parameter + Namespace is a filename defining the namespace, for + example, "/var/run/netns/example", typically created by + command ip netns add example. This option must be used in + a function call that creates a socket, that is, + gen_tcp:connect/3,4, + gen_tcp:listen/2, + gen_udp:open/1,2, or + gen_sctp:open/0,1,2.

+

This option uses the Linux-specific syscall + setns(), such as in Linux kernel 3.0 or later, + and therefore only exists when the runtime system + is compiled for such an operating system.

+

The virtual machine also needs elevated privileges, either + running as superuser or (for Linux) having capability + CAP_SYS_ADMIN according to the documentation for + setns(2). + However, during testing also CAP_SYS_PTRACE + and CAP_DAC_READ_SEARCH have proven to be necessary.

+

Example:

+ +setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp +

Notice that the filesystem containing the virtual machine + executable (beam.smp in the example) must be local, + mounted without flag nosetuid, + support extended attributes, and + the kernel must support file capabilities. + All this runs out of the box on at least Ubuntu 12.04 LTS, + except that SCTP sockets appear to not support + network namespaces.

+

Namespace is a filename and is encoded + and decoded as discussed in module + file, with the + following exceptions:

+ +

Emulator flag +fnu is ignored.

+

getopts/2 + for this option returns a binary for the filename if the stored + filename cannot be decoded. This is only to occur if you set the + option using a binary that cannot be decoded with the emulator's + filename encoding: + file:native_name_encoding/0.

+
+ + list -

Received Packet is delivered as a list.

-
- - binary +

Received Packet is delivered as a list.

+ + binary -

Received Packet is delivered as a binary.

-
- +

Received Packet is delivered as a binary.

+ {nodelay, Boolean}(TCP/IP sockets) -

If Boolean == true, the TCP_NODELAY option - is turned on for the socket, which means that even small - amounts of data will be sent immediately.

+

If Boolean == true, option TCP_NODELAY + is turned on for the socket, which means that also small + amounts of data are sent immediately.

{packet, PacketType}(TCP/IP sockets)

Defines the type of packets to use for a socket. - The following values are valid:

+ Possible values:

raw | 0 @@ -917,104 +860,99 @@ setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp

Packets consist of a header specifying the number of bytes in the packet, followed by that number of bytes. - The length of header can be one, two, or four bytes; + The header length can be one, two, or four bytes, and containing an unsigned integer in big-endian byte order. - Each send operation will generate the header, and the header - will be stripped off on each receive operation.

-

In current implementation the 4-byte header is limited to 2Gb.

+ Each send operation generates the header, and the header + is stripped off on each receive operation.

+

The 4-byte header is limited to 2Gb.

asn1 | cdr | sunrm | fcgi | tpkt | line

These packet types only have effect on receiving. When sending a packet, it is the responsibility of the application to supply a correct header. On - receiving, however, there will be one message sent to + receiving, however, one message is sent to the controlling process for each complete packet received, and, similarly, each call to gen_tcp:recv/2,3 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.

-
+

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 + +
http | http_bin

The Hypertext Transfer Protocol. The packets are returned with the format according to HttpPacket - described in - erlang:decode_packet/3. A socket in passive - mode will return {ok, HttpPacket} from gen_tcp:recv - while an active socket will send messages like {http, - Socket, HttpPacket}.

+ described in + + erlang:decode_packet/3 in ERTS. + A socket in passive + mode returns {ok, HttpPacket} from gen_tcp:recv + while an active socket sends messages like + {http, Socket, HttpPacket}.

httph | httph_bin -

These two types are often not needed as the socket will - automatically switch from http/http_bin to +

These two types are often not needed, as the socket + automatically switches from http/http_bin to httph/httph_bin internally after the first line - has been read. There might be occasions however when they are + is read. However, there can be occasions when they are useful, such as parsing trailers from chunked encoding.

{packet_size, Integer}(TCP/IP sockets) -

Sets the max allowed length of the packet body. If +

Sets the maximum allowed length of the packet body. If the packet header indicates that the length of the packet - is longer than the max allowed length, the packet is - considered invalid. The same happens if the packet header - is too big for the socket receive buffer.

-

For line oriented protocols (line,http*), - option packet_size also guarantees that lines up to the - indicated length are accepted and not considered invalid due - to internal buffer limitations.

+ is longer than the maximum allowed length, the packet is + considered invalid. The same occurs if the packet header + is too large for the socket receive buffer.

+

For line-oriented protocols (line, http*), + option packet_size also guarantees that lines up to the + indicated length are accepted and not considered invalid + because of internal buffer limitations.

{line_delimiter, Char}(TCP/IP sockets) -

Sets the line delimiting character for line oriented protocols - (line). Default value is $\n.

+

Sets the line delimiting character for line-oriented protocols + (line). Defaults to $\n.

+
+ {priority, Priority} + +

Sets the protocol-defined priority for all packets to be sent + on this socket.

+
+ {raw, Protocol, OptionNum, ValueBin} + +

See below.

- - {priority, Priority} -

Set the protocol-defined priority for all packets to be sent - on this socket.

-
- - {raw, Protocol, OptionNum, ValueBin} -

See below.

-
- {read_packets, Integer}(UDP sockets) -

Sets the max number of UDP packets to read without +

Sets the maximum number of UDP packets to read without intervention from the socket when data is available. When this many packets have been read and delivered to the destination process, new packets are not read until a new notification of available data has arrived. - The default is 5, and if this parameter is set too - high the system can become unresponsive due to + Defaults to 5. If this parameter is set too + high, the system can become unresponsive because of UDP packet flooding.

{recbuf, Size}

The minimum size of the receive buffer to use for the socket. You are encouraged to use - inet:getopts/2, - to retrieve the actual size set by your operating system. - -

+ getopts/2 + to retrieve the size set by your operating system.

{reuseaddr, Boolean} @@ -1023,118 +961,160 @@ setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp {send_timeout, Integer} -

Only allowed for connection oriented sockets.

+

Only allowed for connection-oriented sockets.

Specifies a longest time to wait for a send operation to be accepted by the underlying TCP stack. When the limit is - exceeded, the send operation will return - {error,timeout}. How much of a packet that actually - got sent is unknown, why the socket should be closed - whenever a timeout has occurred (see send_timeout_close). - Default is infinity.

+ exceeded, the send operation returns + {error,timeout}. How much of a packet that + got sent is unknown; the socket is therefore to be closed + whenever a time-out has occurred (see send_timeout_close + below). Defaults to infinity.

{send_timeout_close, Boolean} -

Only allowed for connection oriented sockets.

+

Only allowed for connection-oriented sockets.

Used together with send_timeout to specify whether - the socket will be automatically closed when the send operation + the socket is to be automatically closed when the send operation returns {error,timeout}. The recommended setting is - true which will automatically close the socket. - Default is false due to backward compatibility.

- + true, which automatically closes the socket. + Defaults to false because of backward compatibility.

+
- {show_econnreset, Boolean}(TCP/IP sockets) -

When this option is set to false, as it is by - default, an RST that is received from the TCP peer is treated - as a normal close (as though a FIN was sent). A caller - to gen_tcp:recv/2 - will get {error, closed}. In active - mode the controlling process will receive a +

When this option is set to false, which is + default, an RST received from the TCP peer is treated + as a normal close (as though an FIN was sent). A caller to + gen_tcp:recv/2 + gets {error, closed}. In active + mode, the controlling process receives a {tcp_close, Socket} message, indicating that the peer has closed the connection.

-

Setting this option to true will allow you to +

Setting this option to true allows you to distinguish between a connection that was closed normally, - and one which was aborted (intentionally or unintentionally) + and one that was aborted (intentionally or unintentionally) by the TCP peer. A call to - gen_tcp:recv/2 - will return {error, econnreset}. In - active mode, the controlling process will receive a + gen_tcp:recv/2 + returns {error, econnreset}. In + active mode, the controlling process receives a {tcp_error, Socket, econnreset} message before the usual {tcp_closed, Socket}, as is the case for any other socket error. Calls to - gen_tcp:send/2 - will also return {error, econnreset} when it + gen_tcp:send/2 + also returns {error, econnreset} when it is detected that a TCP peer has sent an RST.

A connected socket returned from - gen_tcp:accept/1 - will inherit the show_econnreset setting from the + gen_tcp:accept/1 + inherits the show_econnreset setting from the listening socket.

- +
- {sndbuf, Size}

The minimum size of the send buffer to use for the socket. - You are encouraged to use - inet:getopts/2, - to retrieve the actual size set by your operating system. -

+ You are encouraged to use + getopts/2, + to retrieve the size set by your operating system.

{priority, Integer} -

Sets the SO_PRIORITY socket level option on platforms where - this is implemented. The behaviour and allowed range varies on - different systems. The option is ignored on platforms where the - option is not implemented. Use with caution.

+

Sets the SO_PRIORITY socket level option on platforms + where this is implemented. The behavior and allowed range varies + between different systems. + The option is ignored on platforms where it + is not implemented. Use with caution.

{tos, Integer} -

Sets IP_TOS IP level options on platforms where this is - implemented. The behaviour and allowed range varies on different - systems. The option is ignored on platforms where the option is - not implemented. Use with caution.

+

Sets IP_TOS IP level options on platforms where this is + implemented. The behavior and allowed range varies between + different systems. + The option is ignored on platforms where it is not + implemented. Use with caution.

- -

In addition to the options mentioned above, raw +

In addition to these options, raw option specifications can be used. The raw options are - specified as a tuple of arity four, beginning with the tag - raw, followed by the protocol level, the option number - and the actual option value specified as a binary. This - corresponds to the second, third and fourth argument to the + specified as a tuple of arity four, beginning with tag + raw, followed by the protocol level, the option number, + and the option value specified as a binary. This + corresponds to the second, third, and fourth arguments to the setsockopt call in the C socket API. The option value - needs to be coded in the native endianess of the platform and, - if a structure is required, needs to follow the struct + must be coded in the native endianess of the platform and, + if a structure is required, must follow the structure alignment conventions on the specific platform.

-

Using raw socket options require detailed knowledge about +

Using raw socket options requires detailed knowledge about the current operating system and TCP stack.

-

As an example of the usage of raw options, consider a Linux - system where you want to set the TCP_LINGER2 option on - the IPPROTO_TCP protocol level in the stack. You know +

Example:

+

This example concerns the use of raw options. Consider a Linux + system where you want to set option TCP_LINGER2 on + protocol level IPPROTO_TCP in the stack. You know that on this particular system it defaults to 60 (seconds), - but you would like to lower it to 30 for a particular - socket. The TCP_LINGER2 option is not explicitly - supported by inet, but you know that the protocol level - translates to the number 6, the option number to the number 8 - and the value is to be given as a 32 bit integer. You can use - this line of code to set the option for the socket named + but you want to lower it to 30 for a particular + socket. Option TCP_LINGER2 is not explicitly + supported by inet, but you know that the protocol level + translates to number 6, the option number to number 8, + and the value is to be specified as a 32-bit integer. You can use + this code line to set the option for the socket named Sock:

>}]),]]> +inet:setopts(Sock,[{raw,6,8,<<30:32/native>>}]),]]>

As many options are silently discarded by the stack if they - are given out of range, it could be a good idea to check that - a raw option really got accepted. This code places the value - in the variable TcpLinger2:

+ are specified out of range; it can be a good idea to check that + a raw option is accepted. The following code places the value + in variable TcpLinger2:

>}]}=inet:getopts(Sock,[{raw,6,8,4}]),]]> -

Code such as the examples above is inherently non portable, - even different versions of the same OS on the same platform - may respond differently to this kind of option +{ok,[{raw,6,8,<>}]}=inet:getopts(Sock,[{raw,6,8,4}]),]]> +

Code such as these examples is inherently non-portable, + even different versions of the same OS on the same platform + can respond differently to this kind of option manipulation. Use with care.

-

Note that the default options for TCP/IP sockets can be - changed with the Kernel configuration parameters mentioned in - the beginning of this document.

+

Notice that the default options for TCP/IP sockets can be + changed with the Kernel configuration parameters mentioned in + the beginning of this manual page.

+
+
+ + + + Return the local address and port number for a socket. + + +

Returns the local address and port number for a socket.

+

Notice that for SCTP sockets this function returns only + one of the socket addresses. Function + socknames/1,2 + returns all.

+
+
+ + + + Return all local address/port numbers for a socket. + +

Equivalent to + socknames(Socket, 0). +

+
+
+ + + + Return all local address/port numbers for a socket. + +

Returns a list of all local address/port number pairs for a socket + for the specified association Assoc.

+

This function can return multiple addresses for multihomed + sockets, such as SCTP sockets. For other sockets it + returns a one-element list.

+

Notice that parameter Assoc is by the + SCTP Sockets API Extensions + defined to be ignored for one-to-one style sockets. + For one-to-many style sockets, the special value 0 + is defined to mean that the returned addresses must be + without any particular association. + How different SCTP implementations interprets this varies somewhat. +

@@ -1143,148 +1123,147 @@ setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp POSIX Error Codes - e2big - argument list too long - eacces - permission denied - eaddrinuse - address already in use - eaddrnotavail - cannot assign requested address - eadv - advertise error - eafnosupport - address family not supported by - protocol family - eagain - resource temporarily unavailable + e2big - Too long argument list + eacces - Permission denied + eaddrinuse - Address already in use + eaddrnotavail - Cannot assign requested address + eadv - Advertise error + eafnosupport - Address family not supported by + protocol family + eagain - Resource temporarily unavailable ealign - EALIGN - ealready - operation already in progress - ebade - bad exchange descriptor - ebadf - bad file number - ebadfd - file descriptor in bad state - ebadmsg - not a data message - ebadr - bad request descriptor - ebadrpc - RPC structure is bad - ebadrqc - bad request code - ebadslt - invalid slot - ebfont - bad font file format - ebusy - file busy - echild - no children - echrng - channel number out of range - ecomm - communication error on send - econnaborted - software caused connection abort - econnrefused - connection refused - econnreset - connection reset by peer - edeadlk - resource deadlock avoided - edeadlock - resource deadlock avoided - edestaddrreq - destination address required - edirty - mounting a dirty fs w/o force - edom - math argument out of range - edotdot - cross mount point - edquot - disk quota exceeded - eduppkg - duplicate package name - eexist - file already exists - efault - bad address in system call argument - efbig - file too large - ehostdown - host is down - ehostunreach - host is unreachable - eidrm - identifier removed - einit - initialization error - einprogress - operation now in progress - eintr - interrupted system call - einval - invalid argument + ealready - Operation already in progress + ebade - Bad exchange descriptor + ebadf - Bad file number + ebadfd - File descriptor in bad state + ebadmsg - Not a data message + ebadr - Bad request descriptor + ebadrpc - Bad RPC structure + ebadrqc - Bad request code + ebadslt - Invalid slot + ebfont - Bad font file format + ebusy - File busy + echild - No children + echrng - Channel number out of range + ecomm - Communication error on send + econnaborted - Software caused connection abort + econnrefused - Connection refused + econnreset - Connection reset by peer + edeadlk - Resource deadlock avoided + edeadlock - Resource deadlock avoided + edestaddrreq - Destination address required + edirty - Mounting a dirty fs without force + edom - Math argument out of range + edotdot - Cross mount point + edquot - Disk quota exceeded + eduppkg - Duplicate package name + eexist - File already exists + efault - Bad address in system call argument + efbig - File too large + ehostdown - Host is down + ehostunreach - Host is unreachable + eidrm - Identifier removed + einit - Initialization error + einprogress - Operation now in progress + eintr - Interrupted system call + einval - Invalid argument eio - I/O error - eisconn - socket is already connected - eisdir - illegal operation on a directory - eisnam - is a named file - el2hlt - level 2 halted - el2nsync - level 2 not synchronized - el3hlt - level 3 halted - el3rst - level 3 reset + eisconn - Socket is already connected + eisdir - Illegal operation on a directory + eisnam - Is a named file + el2hlt - Level 2 halted + el2nsync - Level 2 not synchronized + el3hlt - Level 3 halted + el3rst - Level 3 reset elbin - ELBIN - elibacc - cannot access a needed shared library - elibbad - accessing a corrupted shared library - elibexec - cannot exec a shared library directly - elibmax - attempting to link in more shared - libraries than system limit - elibscn - .lib section in a.out corrupted - elnrng - link number out of range - eloop - too many levels of symbolic links - emfile - too many open files - emlink - too many links - emsgsize - message too long - emultihop - multihop attempted - enametoolong - file name too long - enavail - not available + elibacc - Cannot access a needed shared library + elibbad - Accessing a corrupted shared library + elibexec - Cannot exec a shared library directly + elibmax - Attempting to link in more shared + libraries than system limit + elibscn - .lib section in a.out + corrupted + elnrng - Link number out of range + eloop - Too many levels of symbolic links + emfile - Too many open files + emlink - Too many links + emsgsize - Message too long + emultihop - Multihop attempted + enametoolong - Filename too long + enavail - Unavailable enet - ENET - enetdown - network is down - enetreset - network dropped connection on reset - enetunreach - network is unreachable - enfile - file table overflow - enoano - anode table overflow - enobufs - no buffer space available - enocsi - no CSI structure available - enodata - no data available - enodev - no such device - enoent - no such file or directory - enoexec - exec format error - enolck - no locks available - enolink - link has be severed - enomem - not enough memory - enomsg - no message of desired type - enonet - machine is not on the network - enopkg - package not installed - enoprotoopt - bad protocol option - enospc - no space left on device - enosr - out of stream resources or not a stream - device - enosym - unresolved symbol name - enosys - function not implemented - enotblk - block device required - enotconn - socket is not connected - enotdir - not a directory - enotempty - directory not empty - enotnam - not a named file - enotsock - socket operation on non-socket - enotsup - operation not supported - enotty - inappropriate device for ioctl - enotuniq - name not unique on network - enxio - no such device or address - eopnotsupp - operation not supported on socket - eperm - not owner - epfnosupport - protocol family not supported - epipe - broken pipe - eproclim - too many processes - eprocunavail - bad procedure for program - eprogmismatch - program version wrong - eprogunavail - RPC program not available - eproto - protocol error - eprotonosupport - protocol not supported - eprototype - protocol wrong type for socket - erange - math result unrepresentable + enetdown - Network is down + enetreset - Network dropped connection on reset + enetunreach - Network is unreachable + enfile - File table overflow + enoano - Anode table overflow + enobufs - No buffer space available + enocsi - No CSI structure available + enodata - No data available + enodev - No such device + enoent - No such file or directory + enoexec - Exec format error + enolck - No locks available + enolink - Link has been severed + enomem - Not enough memory + enomsg - No message of desired type + enonet - Machine is not on the network + enopkg - Package not installed + enoprotoopt - Bad protocol option + enospc - No space left on device + enosr - Out of stream resources or not a stream device + enosym - Unresolved symbol name + enosys - Function not implemented + enotblk - Block device required + enotconn - Socket is not connected + enotdir - Not a directory + enotempty - Directory not empty + enotnam - Not a named file + enotsock - Socket operation on non-socket + enotsup - Operation not supported + enotty - Inappropriate device for ioctl + enotuniq - Name not unique on network + enxio - No such device or address + eopnotsupp - Operation not supported on socket + eperm - Not owner + epfnosupport - Protocol family not supported + epipe - Broken pipe + eproclim - Too many processes + eprocunavail - Bad procedure for program + eprogmismatch - Wrong program version + eprogunavail - RPC program unavailable + eproto - Protocol error + eprotonosupport - Protocol not supported + eprototype - Wrong protocol type for socket + erange - Math result unrepresentable erefused - EREFUSED - eremchg - remote address changed - eremdev - remote device - eremote - pathname hit remote file system - eremoteio - remote i/o error + eremchg - Remote address changed + eremdev - Remote device + eremote - Pathname hit remote filesystem + eremoteio - Remote I/O error eremoterelease - EREMOTERELEASE - erofs - read-only file system - erpcmismatch - RPC version is wrong - erremote - object is remote - eshutdown - cannot send after socket shutdown - esocktnosupport - socket type not supported - espipe - invalid seek - esrch - no such process - esrmnt - srmount error - estale - stale remote file handle + erofs - Read-only filesystem + erpcmismatch - Wrong RPC version + erremote - Object is remote + eshutdown - Cannot send after socket shutdown + esocktnosupport - Socket type not supported + espipe - Invalid seek + esrch - No such process + esrmnt - Srmount error + estale - Stale remote file handle esuccess - Error 0 - etime - timer expired - etimedout - connection timed out - etoomanyrefs - too many references - etxtbsy - text file or pseudo-device busy - euclean - structure needs cleaning - eunatch - protocol driver not attached - eusers - too many users - eversion - version mismatch - ewouldblock - operation would block - exdev - cross-domain link - exfull - message tables full - nxdomain - the hostname or domain name could not be - found + etime - Timer expired + etimedout - Connection timed out + etoomanyrefs - Too many references + etxtbsy - Text file or pseudo-device busy + euclean - Structure needs cleaning + eunatch - Protocol driver not attached + eusers - Too many users + eversion - Version mismatch + ewouldblock - Operation would block + exdev - Cross-domain link + exfull - Message tables full + nxdomain - Hostname or domain name cannot be found -- cgit v1.2.3 From 348227049f0183854adea2d71d9555fda0ed19c8 Mon Sep 17 00:00:00 2001 From: Hans Bolinder Date: Tue, 17 May 2016 13:01:57 +0200 Subject: kernel: Remove no longer needed anchors in documentation --- lib/kernel/doc/src/inet.xml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index cfff393b8c..bca04aa244 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -4,7 +4,7 @@
- 19972015 + 19972016 Ericsson AB. All Rights Reserved. @@ -128,7 +128,7 @@ fe80::204:acff:fe17:bf38 socket() -

See +

See gen_tcp:type-socket and gen_udp:type-socket. -- cgit v1.2.3 From 5d7dcfc2e0de7e93b29d01f07a2f970720d62f9d Mon Sep 17 00:00:00 2001 From: Daniel Sommermann Date: Fri, 20 May 2016 15:47:16 -0700 Subject: Make inet:gethostbyname respect resolver option `inet6` This makes the implementation text of inet:gethostbyname/1 identical to that of inet_res:gethostbyname/1. I also copied over the doc note about this resolver option. --- lib/kernel/doc/src/inet.xml | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index bca04aa244..5ff167bcb3 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -11,7 +11,7 @@ Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at - + http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software @@ -207,6 +207,10 @@ fe80::204:acff:fe17:bf38

Returns a hostent record for the host with the specified hostname.

+

If resolver option inet6 is true, + an IPv6 address is looked up. If that fails, + the IPv4 address is looked up and returned on + IPv6-mapped IPv4 format.

@@ -1267,4 +1271,3 @@ inet:setopts(Sock,[{raw,6,8,<<30:32/native>>}]),]]> - -- cgit v1.2.3 From 16e895198a541ccbbbe6c970bd9572cf347a9c77 Mon Sep 17 00:00:00 2001 From: Raimo Niskanen Date: Wed, 8 Jun 2016 14:46:44 +0200 Subject: Document the local (unix) address family --- lib/kernel/doc/src/inet.xml | 53 +++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 53 insertions(+) (limited to 'lib/kernel/doc/src/inet.xml') diff --git a/lib/kernel/doc/src/inet.xml b/lib/kernel/doc/src/inet.xml index 5ff167bcb3..c0dce2f50c 100644 --- a/lib/kernel/doc/src/inet.xml +++ b/lib/kernel/doc/src/inet.xml @@ -117,6 +117,59 @@ fe80::204:acff:fe17:bf38 + + + +

+ This address family only works on Unix-like systems. +

+

+ File is normally a file pathname + in a local filesystem. It is limited in length by the + operating system, traditionally to 108 bytes. +

+

+ A binary() is passed as is to the operating system, + but a string() is encoded according to the + + system filename encoding mode. + +

+

+ Other addresses are possible, for example Linux implements + "Abstract Addresses". See the documentation for + Unix Domain Sockets on your system, + normally unix in manual section 7. +

+

+ In most API functions where you can use + this address family the port number must be 0. +

+
+
+ + + + + + +

+ Addresses besides + + ip_address() + + ones that are returned from socket API functions. + See in particular + + local_address(). + + The unspec family corresponds to AF_UNSPEC and can + occur if the other side has no socket address. + The undefined family can only occur in the unlikely + event of an address family that the VM does not recognize. +

+
+
-- cgit v1.2.3