1inet(3)                    Erlang Module Definition                    inet(3)
2
3
4

NAME

6       inet - Access to TCP/IP protocols.
7

DESCRIPTION

9       This module provides access to TCP/IP protocols.
10
11       See  also  ERTS  User's  Guide: Inet Configuration for more information
12       about how to configure an Erlang runtime system for IP communication.
13
14       The following two Kernel configuration parameters affect  the  behavior
15       of all sockets opened on an Erlang node:
16
17         * inet_default_connect_options  can contain a list of default options
18           used for all sockets returned when doing connect.
19
20         * inet_default_listen_options can contain a list of  default  options
21           used when issuing a listen call.
22
23       When  accept  is issued, the values of the listening socket options are
24       inherited. No such application variable is therefore needed for accept.
25
26       Using the Kernel configuration parameters above, one  can  set  default
27       options  for all TCP sockets on a node, but use this with care. Options
28       such as {delay_send,true} can be specified in this way.  The  following
29       is an example of starting an Erlang node with all sockets using delayed
30       send:
31
32       $ erl -sname test -kernel \
33       inet_default_connect_options '[{delay_send,true}]' \
34       inet_default_listen_options '[{delay_send,true}]'
35
36       Notice that default option {active, true} cannot be changed, for inter‐
37       nal reasons.
38
39       Addresses as inputs to functions can be either a string or a tuple. For
40       example, the IP address 150.236.20.73 can be passed to gethostbyaddr/1,
41       either as string "150.236.20.73" or as tuple {150, 236, 20, 73}.
42
43       IPv4 address examples:
44
45       Address          ip_address()
46       -------          ------------
47       127.0.0.1        {127,0,0,1}
48       192.168.42.2     {192,168,42,2}
49
50       IPv6 address examples:
51
52       Address          ip_address()
53       -------          ------------
54       ::1             {0,0,0,0,0,0,0,1}
55       ::192.168.42.2  {0,0,0,0,0,0,(192 bsl 8) bor 168,(42 bsl 8) bor 2}
56       ::FFFF:192.168.42.2
57                       {0,0,0,0,0,16#FFFF,(192 bsl 8) bor 168,(42 bsl 8) bor 2}
58       3ffe:b80:1f8d:2:204:acff:fe17:bf38
59                       {16#3ffe,16#b80,16#1f8d,16#2,16#204,16#acff,16#fe17,16#bf38}
60       fe80::204:acff:fe17:bf38
61                       {16#fe80,0,0,0,16#204,16#acff,16#fe17,16#bf38}
62
63       Function parse_address/1 can be useful:
64
65       1> inet:parse_address("192.168.42.2").
66       {ok,{192,168,42,2}}
67       2> inet:parse_address("::FFFF:192.168.42.2").
68       {ok,{0,0,0,0,0,65535,49320,10754}}
69

DATA TYPES

71       hostent() =
72           #hostent{h_name = inet:hostname(),
73                    h_aliases = [inet:hostname()],
74                    h_addrtype = inet | inet6,
75                    h_length = integer() >= 0,
76                    h_addr_list = [inet:ip_address()]}
77
78              The record is defined in the Kernel include file "inet.hrl".
79
80              Add the following directive to the module:
81
82              -include_lib("kernel/include/inet.hrl").
83
84       hostname() = atom() | string()
85
86       ip_address() = ip4_address() | ip6_address()
87
88       ip4_address() = {0..255, 0..255, 0..255, 0..255}
89
90       ip6_address() =
91           {0..65535,
92            0..65535,
93            0..65535,
94            0..65535,
95            0..65535,
96            0..65535,
97            0..65535,
98            0..65535}
99
100       port_number() = 0..65535
101
102       family_address() =
103           inet_address() | inet6_address() | local_address()
104
105              A general address format on the form {Family, Destination} where
106              Family is an atom such as local and the  format  of  Destination
107              depends  on Family, and is a complete address (for example an IP
108              address including port number).
109
110       inet_address() =
111           {inet, {ip4_address() | any | loopback, port_number()}}
112
113          Warning:
114              This address format is for now experimental and for completeness
115              to make all address families have a {Family, Destination} repre‐
116              sentation.
117
118
119       inet6_address() =
120           {inet6, {ip6_address() | any | loopback, port_number()}}
121
122          Warning:
123              This address format is for now experimental and for completeness
124              to make all address families have a {Family, Destination} repre‐
125              sentation.
126
127
128       local_address() = {local, File :: binary() | string()}
129
130              This address family only works on Unix-like systems.
131
132              File is normally a file pathname in a local  filesystem.  It  is
133              limited  in length by the operating system, traditionally to 108
134              bytes.
135
136              A binary() is passed as  is  to  the  operating  system,  but  a
137              string()  is  encoded according to the  system filename encoding
138              mode.
139
140              Other addresses are possible, for example Linux implements  "Ab‐
141              stract Addresses". See the documentation for Unix Domain Sockets
142              on your system, normally unix in manual section 7.
143
144              In most API functions where you can use this address family  the
145              port number must be 0.
146
147       socket_address() =
148           ip_address() | any | loopback | local_address()
149
150       socket_getopt() =
151           gen_sctp:option_name() |
152           gen_tcp:option_name() |
153           gen_udp:option_name()
154
155       socket_setopt() =
156           gen_sctp:option() | gen_tcp:option() | gen_udp:option()
157
158       returned_non_ip_address() =
159           {local, binary()} | {unspec, <<>>} | {undefined, any()}
160
161              Addresses  besides  ip_address()  ones  that  are  returned from
162              socket API functions. See in  particular  local_address().   The
163              unspec  family  corresponds  to  AF_UNSPEC  and can occur if the
164              other side has no socket address. The undefined family can  only
165              occur  in  the  unlikely  event of an address family that the VM
166              does not recognize.
167
168       ancillary_data() =
169           [{tos, byte()} | {tclass, byte()} | {ttl, byte()}]
170
171              Ancillary data received with the  data  packet,  read  with  the
172              socket  option pktoptions from a TCP socket, or to set in a call
173              to gen_udp:send/4 or gen_udp:send/5.
174
175              The value(s) correspond to the currently active  socket  options
176              recvtos,  recvtclass and recvttl, or for a single send operation
177              the option(s) to override the currently active socket option(s).
178
179       getifaddrs_ifopts() =
180           [Ifopt ::
181                {flags,
182                 Flags ::
183                     [up | broadcast | loopback | pointtopoint |
184                      running | multicast]} |
185                {addr, Addr :: ip_address()} |
186                {netmask, Netmask :: ip_address()} |
187                {broadaddr, Broadaddr :: ip_address()} |
188                {dstaddr, Dstaddr :: ip_address()} |
189                {hwaddr, Hwaddr :: [byte()]}]
190
191              Interface address description list returned from  getifaddrs/0,1
192              for  a named interface, translated from the returned data of the
193              POSIX API function getaddrinfo().
194
195              Hwaddr is hardware dependent, for example,  on  Ethernet  inter‐
196              faces it is the 6-byte Ethernet address (MAC address (EUI-48 ad‐
197              dress)).
198
199              The tuples {addr,Addr}, {netmask,Netmask}, and possibly  {broad‐
200              addr,Broadaddr} or {dstaddr,Dstaddr} are repeated in the list if
201              the interface has got multiple addresses. An interface may  have
202              multiple  {flag,_}  tuples for example if it has different flags
203              for different address families. Multiple {hwaddr,Hwaddr}  tuples
204              is  hard  to  say  anything  definite  about,  though. The tuple
205              {flag,Flags} is mandatory, all others are optional.
206
207              Do not rely too much on the order of Flags atoms  or  the  Ifopt
208              tuples. There are however some rules:
209
210                * A {flag,_} tuple applies to all other tuples that follow.
211
212                * Immediately after {addr,_} follows {netmask,_}.
213
214                * Immediately thereafter may {broadaddr,_} follow if broadcast
215                  is member of Flags, or {dstaddr,_} if pointtopoint is member
216                  of  Flags. Both {dstaddr,_} and {broadaddr,_} does not occur
217                  for the same {addr,_}.
218
219                * Any {netmask,_}, {broadaddr,_}, or {dstaddr,_}  tuples  that
220                  follow an {addr,Addr} tuple concerns the address Addr.
221
222              The tuple {hwaddr,_} is not returned on Solaris, as the hardware
223              address historically belongs to the link layer and it is not re‐
224              turned by the Solaris API function getaddrinfo().
225
226          Warning:
227              On Windows, the data is fetched from different OS API functions,
228              so the Netmask and Broadaddr values may be calculated,  just  as
229              some Flags values.
230
231
232       posix() =
233           eaddrinuse | eaddrnotavail | eafnosupport | ealready |
234           econnaborted | econnrefused | econnreset | edestaddrreq |
235           ehostdown | ehostunreach | einprogress | eisconn | emsgsize |
236           enetdown | enetunreach | enopkg | enoprotoopt | enotconn |
237           enotty | enotsock | eproto | eprotonosupport | eprototype |
238           esocktnosupport | etimedout | ewouldblock | exbadport |
239           exbadseq |
240           file:posix()
241
242              An  atom  that is named from the POSIX error codes used in Unix,
243              and in the runtime libraries of most C  compilers.  See  section
244              POSIX Error Codes.
245
246       socket()
247
248              See gen_tcp:type-socket and gen_udp:type-socket.
249
250       address_family() = inet | inet6 | local
251
252       socket_protocol() = tcp | udp | sctp
253
254       stat_option() =
255           recv_cnt | recv_max | recv_avg | recv_oct | recv_dvi |
256           send_cnt | send_max | send_avg | send_oct | send_pend
257

EXPORTS

259       close(Socket) -> ok
260
261              Types:
262
263                 Socket = socket()
264
265              Closes a socket of any type.
266
267       format_error(Reason) -> string()
268
269              Types:
270
271                 Reason = posix() | system_limit
272
273              Returns a diagnostic error string. For possible POSIX values and
274              corresponding strings, see section POSIX Error Codes.
275
276       get_rc() ->
277                 [{Par :: atom(), Val :: any()} |
278                  {Par :: atom(), Val1 :: any(), Val2 :: any()}]
279
280              Returns the state of the Inet configuration database in form  of
281              a  list  of recorded configuration parameters. For more informa‐
282              tion, see ERTS User's Guide: Inet Configuration.
283
284              Only actual parameters with other than default  values  are  re‐
285              turned,  for  example  not directives that specify other sources
286              for configuration parameters nor directives that  clear  parame‐
287              ters.
288
289       getaddr(Host, Family) -> {ok, Address} | {error, posix()}
290
291              Types:
292
293                 Host = ip_address() | hostname()
294                 Family = address_family()
295                 Address = ip_address()
296
297              Returns the IP address for Host as a tuple of integers. Host can
298              be an IP address, a single hostname, or a fully qualified  host‐
299              name.
300
301       getaddrs(Host, Family) -> {ok, Addresses} | {error, posix()}
302
303              Types:
304
305                 Host = ip_address() | hostname()
306                 Family = address_family()
307                 Addresses = [ip_address()]
308
309              Returns  a  list of all IP addresses for Host. Host can be an IP
310              address, a single hostname, or a fully qualified hostname.
311
312       gethostbyaddr(Address) -> {ok, Hostent} | {error, posix()}
313
314              Types:
315
316                 Address = string() | ip_address()
317                 Hostent = hostent()
318
319              Returns a hostent record for the host  with  the  specified  ad‐
320              dress.
321
322       gethostbyname(Hostname) -> {ok, Hostent} | {error, posix()}
323
324              Types:
325
326                 Hostname = hostname()
327                 Hostent = hostent()
328
329              Returns  a  hostent record for the host with the specified host‐
330              name.
331
332              If resolver option inet6 is true, an IPv6 address is looked up.
333
334       gethostbyname(Hostname, Family) ->
335                        {ok, Hostent} | {error, posix()}
336
337              Types:
338
339                 Hostname = hostname()
340                 Family = address_family()
341                 Hostent = hostent()
342
343              Returns a hostent record for the host with the  specified  name,
344              restricted to the specified address family.
345
346       gethostname() -> {ok, Hostname}
347
348              Types:
349
350                 Hostname = string()
351
352              Returns the local hostname. Never fails.
353
354       getifaddrs() ->
355                     {ok,
356                      [{Ifname :: string(),
357                        Ifopts :: getifaddrs_ifopts()}]} |
358                     {error, posix()}
359
360              Returns  a  list  of 2-tuples containing interface names and the
361              interfaces' addresses. Ifname is a Unicode string and Ifopts  is
362              a list of interface address description tuples.
363
364              The  interface  address  description tuples are documented under
365              the type of the Ifopts value.
366
367       getifaddrs(Opts) -> {ok, [{Ifname, Ifopts}]} | {error, Posix}
368
369              Types:
370
371                  Opts = [{netns, Namespace}]
372                  Namespace =  file:filename_all()
373                 Ifname = string()
374                  Ifopts =  getifaddrs_ifopts()
375                 Posix = posix()
376
377              The same as getifaddrs/0 but the Option {netns, Namespace}  sets
378              a  network namespace for the OS call, on platforms that supports
379              that feature.
380
381              See the socket option {netns, Namespace} under setopts/2.
382
383       getopts(Socket, Options) -> {ok, OptionValues} | {error, posix()}
384
385              Types:
386
387                 Socket = socket()
388                 Options = [socket_getopt()]
389                 OptionValues = [socket_setopt() | gen_tcp:pktoptions_value()]
390
391              Gets one or more options for a socket. For a list  of  available
392              options,  see  setopts/2.  See also the description for the type
393              gen_tcp:pktoptions_value().
394
395              The number of elements in the returned  OptionValues  list  does
396              not  necessarily  correspond to the number of options asked for.
397              If the operating system fails to support an option, it  is  left
398              out  in  the returned list. An error tuple is returned only when
399              getting options for the  socket  is  impossible  (that  is,  the
400              socket  is  closed  or  the  buffer size in a raw request is too
401              large). This behavior is kept for  backward  compatibility  rea‐
402              sons.
403
404              A raw option request RawOptReq = {raw, Protocol, OptionNum, Val‐
405              ueSpec} can be used to get information about socket options  not
406              (explicitly)  supported  by  the emulator. The use of raw socket
407              options makes the code non-portable, but allows the Erlang  pro‐
408              grammer  to take advantage of unusual features present on a par‐
409              ticular platform.
410
411              RawOptReq consists of tag raw followed by  the  protocol  level,
412              the option number, and either a binary or the size, in bytes, of
413              the buffer in which the option value is to be stored.  A  binary
414              is  to  be used when the underlying getsockopt requires input in
415              the argument field. In this case, the binary size is  to  corre‐
416              spond  to the required buffer size of the return value. The sup‐
417              plied values in a RawOptReq correspond to the second, third, and
418              fourth/fifth  parameters  to the getsockopt call in the C socket
419              API. The value stored in the buffer is returned as a binary Val‐
420              ueBin, where all values are coded in the native endianess.
421
422              Asking  for  and inspecting raw socket options require low-level
423              information about the current operating system and TCP stack.
424
425              Example:
426
427              Consider a Linux machine where option TCP_INFO can  be  used  to
428              collect  TCP  statistics for a socket. Assume you are interested
429              in field tcpi_sacked of struct tcp_info filled  in  when  asking
430              for TCP_INFO. To be able to access this information, you need to
431              know the following:
432
433                * The numeric value of protocol level IPPROTO_TCP
434
435                * The numeric value of option TCP_INFO
436
437                * The size of struct tcp_info
438
439                * The size and offset of the specific field
440
441              By inspecting the headers or writing a small C  program,  it  is
442              found  that IPPROTO_TCP is 6, TCP_INFO is 11, the structure size
443              is 92 (bytes), the offset of tcpi_sacked is 28  bytes,  and  the
444              value is a 32-bit integer. The following code can be used to re‐
445              trieve the value:
446
447              get_tcpi_sacked(Sock) ->
448                  {ok,[{raw,_,_,Info}]} = inet:getopts(Sock,[{raw,6,11,92}]),
449                  <<_:28/binary,TcpiSacked:32/native,_/binary>> = Info,
450                  TcpiSacked.
451
452              Preferably, you would check the machine type, the operating sys‐
453              tem, and the Kernel version before executing anything similar to
454              this code.
455
456       getstat(Socket) -> {ok, OptionValues} | {error, posix()}
457
458       getstat(Socket, Options) -> {ok, OptionValues} | {error, posix()}
459
460              Types:
461
462                 Socket = socket()
463                 Options = [stat_option()]
464                 OptionValues = [{stat_option(), integer()}]
465                 stat_option() =
466                     recv_cnt | recv_max | recv_avg | recv_oct | recv_dvi |
467                     send_cnt | send_max | send_avg | send_oct | send_pend
468
469              Gets one or more statistic options for a socket.
470
471              getstat(Socket)  is  equivalent  to  getstat(Socket,  [recv_avg,
472              recv_cnt,  recv_dvi,  recv_max,  recv_oct,  send_avg,  send_cnt,
473              send_pend, send_max, send_oct]).
474
475              The following options are available:
476
477                recv_avg:
478                  Average size of packets, in bytes, received by the socket.
479
480                recv_cnt:
481                  Number of packets received by the socket.
482
483                recv_dvi:
484                  Average packet size deviation, in  bytes,  received  by  the
485                  socket.
486
487                recv_max:
488                  Size  of  the  largest  packet,  in  bytes,  received by the
489                  socket.
490
491                recv_oct:
492                  Number of bytes received by the socket.
493
494                send_avg:
495                  Average size of packets, in bytes, sent from the socket.
496
497                send_cnt:
498                  Number of packets sent from the socket.
499
500                send_pend:
501                  Number of bytes waiting to be sent by the socket.
502
503                send_max:
504                  Size of the largest packet, in bytes, sent from the socket.
505
506                send_oct:
507                  Number of bytes sent from the socket.
508
509       i() -> ok
510
511       i(Proto :: socket_protocol()) -> ok
512
513       i(X1 :: socket_protocol(), Fs :: [atom()]) -> ok
514
515              Lists all TCP, UDP and SCTP sockets, including  those  that  the
516              Erlang  runtime  system uses as well as those created by the ap‐
517              plication.
518
519              The following options are available:
520
521                port:
522                  The internal index of the port.
523
524                module:
525                  The callback module of the socket.
526
527                recv:
528                  Number of bytes received by the socket.
529
530                sent:
531                  Number of bytes sent from the socket.
532
533                owner:
534                  The socket owner process.
535
536                local_address:
537                  The local address of the socket.
538
539                foreign_address:
540                  The address and port of the other end of the connection.
541
542                state:
543                  The connection state.
544
545                type:
546                  STREAM or DGRAM or SEQPACKET.
547
548       ntoa(IpAddress) -> Address | {error, einval}
549
550              Types:
551
552                 Address = string()
553                 IpAddress = ip_address()
554
555              Parses an ip_address() and  returns  an  IPv4  or  IPv6  address
556              string.
557
558       parse_address(Address) -> {ok, IPAddress} | {error, einval}
559
560              Types:
561
562                 Address = string()
563                 IPAddress = ip_address()
564
565              Parses  an  IPv4  or  IPv6 address string and returns an ip4_ad‐
566              dress() or  ip6_address().  Accepts  a  shortened  IPv4  address
567              string.
568
569       parse_ipv4_address(Address) -> {ok, IPv4Address} | {error, einval}
570
571              Types:
572
573                 Address = string()
574                 IPv4Address = ip_address()
575
576              Parses  an IPv4 address string and returns an ip4_address(). Ac‐
577              cepts a shortened IPv4 address string.
578
579       parse_ipv4strict_address(Address) ->
580                                   {ok, IPv4Address} | {error, einval}
581
582              Types:
583
584                 Address = string()
585                 IPv4Address = ip_address()
586
587              Parses an IPv4 address string containing four fields,  that  is,
588              not shortened, and returns an ip4_address().
589
590       parse_ipv6_address(Address) -> {ok, IPv6Address} | {error, einval}
591
592              Types:
593
594                 Address = string()
595                 IPv6Address = ip_address()
596
597              Parses  an  IPv6 address string and returns an ip6_address(). If
598              an IPv4 address string is specified, an IPv4-mapped IPv6 address
599              is returned.
600
601       parse_ipv6strict_address(Address) ->
602                                   {ok, IPv6Address} | {error, einval}
603
604              Types:
605
606                 Address = string()
607                 IPv6Address = ip_address()
608
609              Parses an IPv6 address string and returns an ip6_address(). Does
610              not accept IPv4 addresses.
611
612       ipv4_mapped_ipv6_address(X1 :: ip_address()) -> ip_address()
613
614              Convert an IPv4 address to an IPv4-mapped IPv6  address  or  the
615              reverse.  When converting from an IPv6 address all but the 2 low
616              words are ignored so this function  also  works  on  some  other
617              types of addresses than IPv4-mapped.
618
619       parse_strict_address(Address) -> {ok, IPAddress} | {error, einval}
620
621              Types:
622
623                 Address = string()
624                 IPAddress = ip_address()
625
626              Parses  an  IPv4  or  IPv6 address string and returns an ip4_ad‐
627              dress() or ip6_address(). Does not accept a shortened  IPv4  ad‐
628              dress string.
629
630       peername(Socket :: socket()) ->
631                   {ok,
632                    {ip_address(), port_number()} |
633                    returned_non_ip_address()} |
634                   {error, posix()}
635
636              Returns the address and port for the other end of a connection.
637
638              Notice  that for SCTP sockets, this function returns only one of
639              the peer addresses of the socket. Function peernames/1,2 returns
640              all.
641
642       peernames(Socket :: socket()) ->
643                    {ok,
644                     [{ip_address(), port_number()} |
645                      returned_non_ip_address()]} |
646                    {error, posix()}
647
648              Equivalent to peernames(Socket, 0).
649
650              Notice  that  the  behavior of this function for an SCTP one-to-
651              many style socket is not defined by the SCTP Sockets API  Exten‐
652              sions.
653
654       peernames(Socket, Assoc) ->
655                    {ok, [{Address, Port}]} | {error, posix()}
656
657              Types:
658
659                 Socket = socket()
660                 Assoc = #sctp_assoc_change{} | gen_sctp:assoc_id()
661                 Address = ip_address()
662                 Port = integer() >= 0
663
664              Returns  a  list  of all address/port number pairs for the other
665              end of an association Assoc of a socket.
666
667              This function can return multiple addresses for multihomed sock‐
668              ets,  such  as SCTP sockets. For other sockets it returns a one-
669              element list.
670
671              Notice that parameter Assoc is by the SCTP  Sockets  API  Exten‐
672              sions  defined  to be ignored for one-to-one style sockets. What
673              the special value 0 means, hence its  behavior  for  one-to-many
674              style sockets, is unfortunately undefined.
675
676       port(Socket) -> {ok, Port} | {error, any()}
677
678              Types:
679
680                 Socket = socket()
681                 Port = port_number()
682
683              Returns the local port number for a socket.
684
685       setopts(Socket, Options) -> ok | {error, posix()}
686
687              Types:
688
689                 Socket = socket()
690                 Options = [socket_setopt()]
691
692              Sets one or more options for a socket.
693
694              The following options are available:
695
696                {active, true | false | once | N}:
697                  If  the  value is true, which is the default, everything re‐
698                  ceived from the socket is sent as messages to the  receiving
699                  process.
700
701                  If  the  value is false (passive mode), the process must ex‐
702                  plicitly receive incoming data by calling  gen_tcp:recv/2,3,
703                  gen_udp:recv/2,3,  or  gen_sctp:recv/1,2  (depending  on the
704                  type of socket).
705
706                  If the value is once ({active, once}), one data message from
707                  the  socket is sent to the process. To receive one more mes‐
708                  sage, setopts/2 must be called again  with  option  {active,
709                  once}.
710
711                  If  the  value  is an integer N in the range -32768 to 32767
712                  (inclusive), the value is added to  the  socket's  count  of
713                  data  messages  sent  to the controlling process. A socket's
714                  default message count is 0. If a negative  value  is  speci‐
715                  fied,  and  its  magnitude  is  equal to or greater than the
716                  socket's current message count, the socket's  message  count
717                  is  set to 0. Once the socket's message count reaches 0, ei‐
718                  ther because  of  sending  received  data  messages  to  the
719                  process  or by being explicitly set, the process is then no‐
720                  tified by a special message, specific to the type of socket,
721                  that  the  socket  has entered passive mode. Once the socket
722                  enters passive mode, to receive more messages setopts/2 must
723                  be called again to set the socket back into an active mode.
724
725                  When using {active, once} or {active, N}, the socket changes
726                  behavior automatically when data is received.  This  can  be
727                  confusing  in  combination  with connection-oriented sockets
728                  (that is, gen_tcp), as a socket with {active, false}  behav‐
729                  ior  reports closing differently than a socket with {active,
730                  true} behavior. To simplify programming, a socket where  the
731                  peer  closed,  and this is detected while in {active, false}
732                  mode, still generates message {tcp_closed,Socket}  when  set
733                  to  {active,  once}, {active, true}, or {active, N} mode. It
734                  is    therefore    safe    to    assume     that     message
735                  {tcp_closed,Socket}, possibly followed by socket port termi‐
736                  nation (depending on option  exit_on_close)  eventually  ap‐
737                  pears  when a socket changes back and forth between {active,
738                  true} and {active, false} mode. However, when  peer  closing
739                  is  detected it is all up to the underlying TCP/IP stack and
740                  protocol.
741
742                  Notice that {active, true} mode provides no flow control;  a
743                  fast  sender  can easily overflow the receiver with incoming
744                  messages. The same is true for {active, N} mode,  while  the
745                  message count is greater than zero.
746
747                  Use  active  mode  only if your high-level protocol provides
748                  its own flow control (for  example,  acknowledging  received
749                  messages) or the amount of data exchanged is small. {active,
750                  false} mode, use of the {active, once} mode, or {active,  N}
751                  mode  with  values of N appropriate for the application pro‐
752                  vides flow control. The other side cannot send  faster  than
753                  the receiver can read.
754
755                {broadcast, Boolean} (UDP sockets):
756                  Enables/disables permission to send broadcasts.
757
758                {buffer, Size}:
759                  The size of the user-level buffer used by the driver. Not to
760                  be confused with options sndbuf and recbuf, which correspond
761                  to  the  Kernel socket buffers. For TCP it is recommended to
762                  have val(buffer) >= val(recbuf) to avoid performance  issues
763                  because of unnecessary copying. For UDP the same recommenda‐
764                  tion applies, but the max should not be larger than the  MTU
765                  of the network path. val(buffer) is automatically set to the
766                  above maximum when recbuf is set. However, as the  size  set
767                  for  recbuf usually become larger, you are encouraged to use
768                  getopts/2 to analyze the behavior of your operating system.
769
770                  Note that this is also the maximum amount of data  that  can
771                  be received from a single recv call. If you are using higher
772                  than normal MTU consider setting buffer higher.
773
774                {delay_send, Boolean}:
775                  Normally, when an Erlang process  sends  to  a  socket,  the
776                  driver  tries  to  send the data immediately. If that fails,
777                  the driver uses any means available to queue up the  message
778                  to  be sent whenever the operating system says it can handle
779                  it. Setting {delay_send, true} makes all messages queue  up.
780                  The  messages sent to the network are then larger but fewer.
781                  The option affects the scheduling of  send  requests  versus
782                  Erlang  processes  instead  of changing any real property of
783                  the socket. The option is implementation-specific.  Defaults
784                  to false.
785
786                {deliver, port | term}:
787                  When  {active,  true},  data is delivered on the form port :
788                  {S, {data, [H1,..Hsz | Data]}} or term : {tcp, S, [H1..Hsz |
789                  Data]}.
790
791                {dontroute, Boolean}:
792                  Enables/disables routing bypass for outgoing messages.
793
794                {exit_on_close, Boolean}:
795                  This option is set to true by default.
796
797                  The  only  reason  to set it to false is if you want to con‐
798                  tinue sending data to the socket after a close is  detected,
799                  for  example,  if  the  peer uses gen_tcp:shutdown/2 to shut
800                  down the write side.
801
802                {header, Size}:
803                  This option is only meaningful if option binary  was  speci‐
804                  fied when the socket was created. If option header is speci‐
805                  fied, the first Size number bytes of data received from  the
806                  socket  are  elements of a list, and the remaining data is a
807                  binary specified as the tail of the same list. For  example,
808                  if  Size  ==  2,  the data received matches [Byte1,Byte2|Bi‐
809                  nary].
810
811                {high_msgq_watermark, Size}:
812                  The socket message queue is set to a  busy  state  when  the
813                  amount  of data on the message queue reaches this limit. No‐
814                  tice that this limit only concerns data  that  has  not  yet
815                  reached the ERTS internal socket implementation. Defaults to
816                  8 kB.
817
818                  Senders of data to the socket are suspended  if  either  the
819                  socket message queue is busy or the socket itself is busy.
820
821                  For   more   information,  see  options  low_msgq_watermark,
822                  high_watermark, and low_watermark.
823
824                  Notice  that  distribution  sockets  disable  the   use   of
825                  high_msgq_watermark  and low_msgq_watermark. Instead use the
826                  distribution buffer busy limit, which is a similar feature.
827
828                {high_watermark, Size} (TCP/IP sockets):
829                  The socket is set to a busy state when the  amount  of  data
830                  queued  internally by the ERTS socket implementation reaches
831                  this limit. Defaults to 8 kB.
832
833                  Senders of data to the socket are suspended  if  either  the
834                  socket message queue is busy or the socket itself is busy.
835
836                  For    more    information,   see   options   low_watermark,
837                  high_msgq_watermark, and low_msqg_watermark.
838
839                {ipv6_v6only, Boolean}:
840                  Restricts the socket to use only IPv6, prohibiting any  IPv4
841                  connections.  This  is only applicable for IPv6 sockets (op‐
842                  tion inet6).
843
844                  On most platforms this option must be set on the socket  be‐
845                  fore associating it to an address. It is therefore only rea‐
846                  sonable to specify it when creating the socket  and  not  to
847                  use it when calling function (setopts/2) containing this de‐
848                  scription.
849
850                  The behavior of a socket with this option set to true is the
851                  only  portable  one.  The original idea when IPv6 was new of
852                  using IPv6 for all traffic is now not recommended by FreeBSD
853                  (you can use {ipv6_v6only,false} to override the recommended
854                  system default value), forbidden by OpenBSD  (the  supported
855                  GENERIC  kernel), and impossible on Windows (which has sepa‐
856                  rate IPv4 and IPv6  protocol  stacks).  Most  Linux  distros
857                  still  have  a  system  default  value of false. This policy
858                  shift among operating systems to  separate  IPv6  from  IPv4
859                  traffic has evolved, as it gradually proved hard and compli‐
860                  cated to get a dual stack implementation correct and secure.
861
862                  On some platforms, the only allowed value for this option is
863                  true,  for  example, OpenBSD and Windows. Trying to set this
864                  option to false, when creating the  socket,  fails  in  this
865                  case.
866
867                  Setting  this option on platforms where it does not exist is
868                  ignored. Getting  this  option  with  getopts/2  returns  no
869                  value,  that  is,  the  returned  list  does  not contain an
870                  {ipv6_v6only,_} tuple. On Windows, the option does  not  ex‐
871                  ist,  but  it  is  emulated as a read-only option with value
872                  true.
873
874                  Therefore, setting this  option  to  true  when  creating  a
875                  socket  never fails, except possibly on a platform where you
876                  have customized the kernel to only allow false, which can be
877                  doable (but awkward) on, for example, OpenBSD.
878
879                  If you read back the option value using getopts/2 and get no
880                  value, the option does not exist in the host operating  sys‐
881                  tem. The behavior of both an IPv6 and an IPv4 socket listen‐
882                  ing on the same port, and for an IPv6  socket  getting  IPv4
883                  traffic is then no longer predictable.
884
885                {keepalive, Boolean}(TCP/IP sockets):
886                  Enables/disables periodic transmission on a connected socket
887                  when no other data is exchanged. If the other end  does  not
888                  respond,  the  connection  is considered broken and an error
889                  message is sent to the controlling process. Defaults to dis‐
890                  abled.
891
892                {linger, {true|false, Seconds}}:
893                  Determines  the  time-out,  in  seconds, for flushing unsent
894                  data in the close/1 socket call.
895
896                  The first component is if linger is enabled, the second com‐
897                  ponent is the flushing time-out, in seconds. There are 3 al‐
898                  ternatives:
899
900                  {false, _}:
901                    close/1 or shutdown/2 returns immediately, not waiting for
902                    data  to  be  flushed, with closing happening in the back‐
903                    ground.
904
905                  {true, 0}:
906                    Aborts the connection when it is closed. Discards any data
907                    still  remaining  in the send buffers and sends RST to the
908                    peer.
909
910                    This avoids TCP's TIME_WAIT state,  but  leaves  open  the
911                    possibility  that another "incarnation" of this connection
912                    being created.
913
914                  {true, Time} when Time > 0:
915                    close/1 or shutdown/2 will not  return  until  all  queued
916                    messages for the socket have been successfully sent or the
917                    linger timeout (Time) has been reached.
918
919                {low_msgq_watermark, Size}:
920                  If the socket message queue is in a busy state,  the  socket
921                  message  queue is set in a not busy state when the amount of
922                  data queued in the message queue falls below this limit. No‐
923                  tice  that  this  limit  only concerns data that has not yet
924                  reached the ERTS internal socket implementation. Defaults to
925                  4 kB.
926
927                  Senders  that are suspended because of either a busy message
928                  queue or a busy socket are resumed when the  socket  message
929                  queue and the socket are not busy.
930
931                  For   more  information,  see  options  high_msgq_watermark,
932                  high_watermark, and low_watermark.
933
934                  Notice  that  distribution  sockets  disable  the   use   of
935                  high_msgq_watermark and low_msgq_watermark. Instead they use
936                  the distribution buffer busy limit, which is a similar  fea‐
937                  ture.
938
939                {low_watermark, Size} (TCP/IP sockets):
940                  If the socket is in a busy state, the socket is set in a not
941                  busy state when the amount of data queued internally by  the
942                  ERTS  socket implementation falls below this limit. Defaults
943                  to 4 kB.
944
945                  Senders that are suspended because of a busy  message  queue
946                  or  a  busy socket are resumed when the socket message queue
947                  and the socket are not busy.
948
949                  For   more   information,   see   options    high_watermark,
950                  high_msgq_watermark, and low_msgq_watermark.
951
952                {mode, Mode :: binary | list}:
953                  Received Packet is delivered as defined by Mode.
954
955                {netns, Namespace :: file:filename_all()}:
956                  Sets a network namespace for the socket. Parameter Namespace
957                  is  a  filename  defining  the   namespace,   for   example,
958                  "/var/run/netns/example",  typically  created  by command ip
959                  netns add example. This option must be used  in  a  function
960                  call  that  creates  a socket, that is, gen_tcp:connect/3,4,
961                  gen_tcp:listen/2, gen_udp:open/1,2  or  gen_sctp:open/0,1,2,
962                  and also getifaddrs/1.
963
964                  This option uses the Linux-specific syscall setns(), such as
965                  in Linux kernel 3.0 or later, and therefore only exists when
966                  the runtime system is compiled for such an operating system.
967
968                  The  virtual  machine also needs elevated privileges, either
969                  running  as  superuser  or  (for  Linux)  having  capability
970                  CAP_SYS_ADMIN  according  to the documentation for setns(2).
971                  However,   during   testing    also    CAP_SYS_PTRACE    and
972                  CAP_DAC_READ_SEARCH have proven to be necessary.
973
974                  Example:
975
976                setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp
977
978                  Notice  that  the  filesystem containing the virtual machine
979                  executable (beam.smp in the example) must be local,  mounted
980                  without  flag nosetuid, support extended attributes, and the
981                  kernel must support file capabilities. All this runs out  of
982                  the box on at least Ubuntu 12.04 LTS, except that SCTP sock‐
983                  ets appear to not support network namespaces.
984
985                  Namespace is a filename and is encoded and decoded  as  dis‐
986                  cussed in module file, with the following exceptions:
987
988                  * Emulator flag +fnu is ignored.
989
990                  * getopts/2  for  this option returns a binary for the file‐
991                    name if the stored filename cannot  be  decoded.  This  is
992                    only  to  occur  if you set the option using a binary that
993                    cannot be decoded with the emulator's  filename  encoding:
994                    file:native_name_encoding/0.
995
996                {bind_to_device, Ifname :: binary()}:
997                  Binds  a socket to a specific network interface. This option
998                  must be used in a function call that creates a socket,  that
999                  is, gen_tcp:connect/3,4, gen_tcp:listen/2, gen_udp:open/1,2,
1000                  or gen_sctp:open/0,1,2.
1001
1002                  Unlike getifaddrs/0, Ifname is encoded a binary. In the  un‐
1003                  likely  case  that a system is using non-7-bit-ASCII charac‐
1004                  ters in network device names, special care has to  be  taken
1005                  when encoding this argument.
1006
1007                  This  option  uses the Linux-specific socket option SO_BIND‐
1008                  TODEVICE, such as in  Linux  kernel  2.0.30  or  later,  and
1009                  therefore  only  exists  when the runtime system is compiled
1010                  for such an operating system.
1011
1012                  Before Linux 3.8, this socket option could be set, but could
1013                  not  retrieved  with getopts/2. Since Linux 3.8, it is read‐
1014                  able.
1015
1016                  The virtual machine also needs elevated  privileges,  either
1017                  running  as  superuser  or  (for  Linux)  having  capability
1018                  CAP_NET_RAW.
1019
1020                  The primary use case for this option is to bind sockets into
1021                  Linux VRF instances.
1022
1023                list:
1024                  Received Packet is delivered as a list.
1025
1026                binary:
1027                  Received Packet is delivered as a binary.
1028
1029                {nodelay, Boolean}(TCP/IP sockets):
1030                  If  Boolean == true, option TCP_NODELAY is turned on for the
1031                  socket, which means that also small amounts of data are sent
1032                  immediately.
1033
1034                {nopush, Boolean}(TCP/IP sockets):
1035                  This  translates  to  TCP_NOPUSH  on  BSD and to TCP_CORK on
1036                  Linux.
1037
1038                  If Boolean == true, the corresponding option  is  turned  on
1039                  for  the  socket, which means that small amounts of data are
1040                  accumulated until a full MSS-worth of data is  available  or
1041                  this option is turned off.
1042
1043                  Note  that  while  TCP_NOPUSH  socket option is available on
1044                  OSX, its semantics is very  different  (e.g.,  unsetting  it
1045                  does  not  cause immediate send of accumulated data). Hence,
1046                  nopush option is intentionally ignored on OSX.
1047
1048                {packet, PacketType}(TCP/IP sockets):
1049                  Defines the type of packets to use for  a  socket.  Possible
1050                  values:
1051
1052                  raw | 0:
1053                    No packaging is done.
1054
1055                  1 | 2 | 4:
1056                    Packets consist of a header specifying the number of bytes
1057                    in the packet, followed  by  that  number  of  bytes.  The
1058                    header length can be one, two, or four bytes, and contain‐
1059                    ing an unsigned integer in  big-endian  byte  order.  Each
1060                    send  operation  generates  the  header, and the header is
1061                    stripped off on each receive operation.
1062
1063                    The 4-byte header is limited to 2Gb.
1064
1065                  asn1 | cdr | sunrm | fcgi | tpkt | line:
1066                    These packet types only have  effect  on  receiving.  When
1067                    sending a packet, it is the responsibility of the applica‐
1068                    tion to supply a correct header.  On  receiving,  however,
1069                    one  message  is  sent to the controlling process for each
1070                    complete packet received, and,  similarly,  each  call  to
1071                    gen_tcp:recv/2,3  returns  one complete packet. The header
1072                    is not stripped off.
1073
1074                    The meanings of the packet types are as follows:
1075
1076                    * asn1 - ASN.1 BER
1077
1078                    * sunrm - Sun's RPC encoding
1079
1080                    * cdr - CORBA (GIOP 1.1)
1081
1082                    * fcgi - Fast CGI
1083
1084                    * tpkt - TPKT format [RFC1006]
1085
1086                    * line - Line mode, a packet  is  a  line-terminated  with
1087                      newline,  lines longer than the receive buffer are trun‐
1088                      cated
1089
1090                  http | http_bin:
1091                    The Hypertext Transfer Protocol. The packets are  returned
1092                    with  the  format according to HttpPacket described in er‐
1093                    lang:decode_packet/3 in ERTS. A socket in passive mode re‐
1094                    turns  {ok,  HttpPacket} from gen_tcp:recv while an active
1095                    socket sends messages like {http, Socket, HttpPacket}.
1096
1097                  httph | httph_bin:
1098                    These two types are often not needed, as the socket  auto‐
1099                    matically  switches  from http/http_bin to httph/httph_bin
1100                    internally after the first line is  read.  However,  there
1101                    can  be  occasions  when  they are useful, such as parsing
1102                    trailers from chunked encoding.
1103
1104                {packet_size, Integer}(TCP/IP sockets):
1105                  Sets the maximum allowed length of the packet body.  If  the
1106                  packet  header  indicates  that  the length of the packet is
1107                  longer than the maximum allowed length, the packet  is  con‐
1108                  sidered invalid. The same occurs if the packet header is too
1109                  large for the socket receive buffer.
1110
1111                  For   line-oriented   protocols   (line,   http*),    option
1112                  packet_size  also  guarantees that lines up to the indicated
1113                  length are accepted and not considered  invalid  because  of
1114                  internal buffer limitations.
1115
1116                {line_delimiter, Char}(TCP/IP sockets):
1117                  Sets  the line delimiting character for line-oriented proto‐
1118                  cols (line). Defaults to $\n.
1119
1120                {raw, Protocol, OptionNum, ValueBin}:
1121                  See below.
1122
1123                {read_packets, Integer}(UDP sockets):
1124                  Sets the maximum number of UDP packets to read  without  in‐
1125                  tervention from the socket when data is available. When this
1126                  many packets have been read and delivered to the destination
1127                  process,  new  packets are not read until a new notification
1128                  of available data has arrived. Defaults to 5. If this param‐
1129                  eter is set too high, the system can become unresponsive be‐
1130                  cause of UDP packet flooding.
1131
1132                {recbuf, Size}:
1133                  The minimum size of  the  receive  buffer  to  use  for  the
1134                  socket.  You are encouraged to use getopts/2 to retrieve the
1135                  size set by your operating system.
1136
1137                {recvtclass, Boolean}:
1138                  If set to true activates returning the received TCLASS value
1139                  on  platforms  that implements the protocol IPPROTO_IPV6 op‐
1140                  tion IPV6_RECVTCLASS or IPV6_2292RECVTCLASS for the  socket.
1141                  The  value is returned as a {tclass,TCLASS} tuple regardless
1142                  of if the platform returns an IPV6_TCLASS or an  IPV6_RECVT‐
1143                  CLASS CMSG value.
1144
1145                  For  packet  oriented sockets that supports receiving ancil‐
1146                  lary data with the payload data (gen_udp and gen_sctp),  the
1147                  TCLASS  value  is  returned in an extended return tuple con‐
1148                  tained in an  ancillary  data   list.  For  stream  oriented
1149                  sockets (gen_tcp) the only way to get the TCLASS value is if
1150                  the platform supports the pktoptions option.
1151
1152                {recvtos, Boolean}:
1153                  If set to true activates returning the received TOS value on
1154                  platforms  that  implements  the  protocol IPPROTO_IP option
1155                  IP_RECVTOS for the  socket.  The  value  is  returned  as  a
1156                  {tos,TOS}  tuple  regardless  of  if the platform returns an
1157                  IP_TOS or an IP_RECVTOS CMSG value.
1158
1159                  For packet oriented sockets that supports  receiving  ancil‐
1160                  lary  data with the payload data (gen_udp and gen_sctp), the
1161                  TOS value is returned in an extended return tuple  contained
1162                  in  an   ancillary  data   list. For stream oriented sockets
1163                  (gen_tcp) the only way to get the TOS value is if the  plat‐
1164                  form supports the pktoptions option.
1165
1166                {recvttl, Boolean}:
1167                  If set to true activates returning the received TTL value on
1168                  platforms that implements  the  protocol  IPPROTO_IP  option
1169                  IP_RECVTTL  for  the  socket.  The  value  is  returned as a
1170                  {ttl,TTL} tuple regardless of if  the  platform  returns  an
1171                  IP_TTL or an IP_RECVTTL CMSG value.
1172
1173                  For  packet  oriented sockets that supports receiving ancil‐
1174                  lary data with the payload data (gen_udp and gen_sctp),  the
1175                  TTL  value is returned in an extended return tuple contained
1176                  in an  ancillary data  list.  For  stream  oriented  sockets
1177                  (gen_tcp)  the only way to get the TTL value is if the plat‐
1178                  form supports the pktoptions option.
1179
1180                {reuseaddr, Boolean}:
1181                  Allows or disallows local reuse of port numbers. By default,
1182                  reuse is disallowed.
1183
1184                {send_timeout, Integer}:
1185                  Only allowed for connection-oriented sockets.
1186
1187                  Specifies  a longest time to wait for a send operation to be
1188                  accepted by the underlying TCP stack. When the limit is  ex‐
1189                  ceeded, the send operation returns {error,timeout}. How much
1190                  of a packet that got sent is unknown; the socket  is  there‐
1191                  fore  to  be  closed  whenever  a time-out has occurred (see
1192                  send_timeout_close below). Defaults to infinity.
1193
1194                {send_timeout_close, Boolean}:
1195                  Only allowed for connection-oriented sockets.
1196
1197                  Used together  with  send_timeout  to  specify  whether  the
1198                  socket is to be automatically closed when the send operation
1199                  returns {error,timeout}. The recommended  setting  is  true,
1200                  which automatically closes the socket. Defaults to false be‐
1201                  cause of backward compatibility.
1202
1203                {show_econnreset, Boolean}(TCP/IP sockets):
1204                  When this option is set to false, which is default,  an  RST
1205                  received  from the TCP peer is treated as a normal close (as
1206                  though an FIN was sent). A  caller  to  gen_tcp:recv/2  gets
1207                  {error, closed}. In active mode, the controlling process re‐
1208                  ceives a {tcp_closed, Socket} message, indicating  that  the
1209                  peer has closed the connection.
1210
1211                  Setting  this  option  to true allows you to distinguish be‐
1212                  tween a connection that was closed normally,  and  one  that
1213                  was  aborted  (intentionally  or unintentionally) by the TCP
1214                  peer. A call to gen_tcp:recv/2 returns {error,  econnreset}.
1215                  In  active mode, the controlling process receives a {tcp_er‐
1216                  ror,  Socket,   econnreset}   message   before   the   usual
1217                  {tcp_closed,  Socket},  as  is the case for any other socket
1218                  error. Calls to gen_tcp:send/2 also returns {error, econnre‐
1219                  set} when it is detected that a TCP peer has sent an RST.
1220
1221                  A  connected  socket returned from gen_tcp:accept/1 inherits
1222                  the show_econnreset setting from the listening socket.
1223
1224                {sndbuf, Size}:
1225                  The minimum size of the send buffer to use for  the  socket.
1226                  You  are  encouraged  to use getopts/2, to retrieve the size
1227                  set by your operating system.
1228
1229                {priority, Integer}:
1230                  Sets the SO_PRIORITY socket level option on platforms  where
1231                  this  is  implemented. The behavior and allowed range varies
1232                  between different systems. The option is  ignored  on  plat‐
1233                  forms where it is not implemented. Use with caution.
1234
1235                {tos, Integer}:
1236                  Sets  IP_TOS IP level options on platforms where this is im‐
1237                  plemented. The behavior and  allowed  range  varies  between
1238                  different  systems. The option is ignored on platforms where
1239                  it is not implemented. Use with caution.
1240
1241                {tclass, Integer}:
1242                  Sets IPV6_TCLASS IP level options on platforms where this is
1243                  implemented.  The  behavior and allowed range varies between
1244                  different systems. The option is ignored on platforms  where
1245                  it is not implemented. Use with caution.
1246
1247              In  addition  to these options, raw option specifications can be
1248              used. The raw options are specified as a tuple  of  arity  four,
1249              beginning  with tag raw, followed by the protocol level, the op‐
1250              tion number, and the option value specified as  a  binary.  This
1251              corresponds  to  the  second, third, and fourth arguments to the
1252              setsockopt call in the C socket API. The option  value  must  be
1253              coded  in  the native endianess of the platform and, if a struc‐
1254              ture is required, must follow the  structure  alignment  conven‐
1255              tions on the specific platform.
1256
1257              Using  raw  socket options requires detailed knowledge about the
1258              current operating system and TCP stack.
1259
1260              Example:
1261
1262              This example concerns the use of raw options. Consider  a  Linux
1263              system  where  you  want  to  set option TCP_LINGER2 on protocol
1264              level IPPROTO_TCP in the stack. You know that on this particular
1265              system  it defaults to 60 (seconds), but you want to lower it to
1266              30 for a particular socket. Option TCP_LINGER2 is not explicitly
1267              supported  by  inet, but you know that the protocol level trans‐
1268              lates to number 6, the option number to number 8, and the  value
1269              is  to  be  specified as a 32-bit integer. You can use this code
1270              line to set the option for the socket named Sock:
1271
1272              inet:setopts(Sock,[{raw,6,8,<<30:32/native>>}]),
1273
1274              As many options are silently discarded by the stack if they  are
1275              specified  out  of  range; it can be a good idea to check that a
1276              raw option is accepted. The following code places the  value  in
1277              variable TcpLinger2:
1278
1279              {ok,[{raw,6,8,<<TcpLinger2:32/native>>}]}=inet:getopts(Sock,[{raw,6,8,4}]),
1280
1281              Code  such  as  these  examples is inherently non-portable, even
1282              different versions of the same OS on the same platform  can  re‐
1283              spond  differently to this kind of option manipulation. Use with
1284              care.
1285
1286              Notice that the  default  options  for  TCP/IP  sockets  can  be
1287              changed  with  the  Kernel configuration parameters mentioned in
1288              the beginning of this manual page.
1289
1290       sockname(Socket :: socket()) ->
1291                   {ok,
1292                    {ip_address(), port_number()} |
1293                    returned_non_ip_address()} |
1294                   {error, posix()}
1295
1296              Returns the local address and port number for a socket.
1297
1298              Notice that for SCTP sockets this function returns only  one  of
1299              the socket addresses. Function socknames/1,2 returns all.
1300
1301       socknames(Socket :: socket()) ->
1302                    {ok,
1303                     [{ip_address(), port_number()} |
1304                      returned_non_ip_address()]} |
1305                    {error, posix()}
1306
1307              Equivalent to socknames(Socket, 0).
1308
1309       socknames(Socket, Assoc) ->
1310                    {ok, [{Address, Port}]} | {error, posix()}
1311
1312              Types:
1313
1314                 Socket = socket()
1315                 Assoc = #sctp_assoc_change{} | gen_sctp:assoc_id()
1316                 Address = ip_address()
1317                 Port = integer() >= 0
1318
1319              Returns  a  list  of  all  local address/port number pairs for a
1320              socket for the specified association Assoc.
1321
1322              This function can return multiple addresses for multihomed sock‐
1323              ets,  such  as SCTP sockets. For other sockets it returns a one-
1324              element list.
1325
1326              Notice that parameter Assoc is by the SCTP  Sockets  API  Exten‐
1327              sions  defined  to  be ignored for one-to-one style sockets. For
1328              one-to-many style sockets, the special value  0  is  defined  to
1329              mean  that the returned addresses must be without any particular
1330              association. How different SCTP implementations  interpret  this
1331              varies somewhat.
1332

POSIX ERROR CODES

1334         * e2big - Too long argument list
1335
1336         * eacces - Permission denied
1337
1338         * eaddrinuse - Address already in use
1339
1340         * eaddrnotavail - Cannot assign requested address
1341
1342         * eadv - Advertise error
1343
1344         * eafnosupport - Address family not supported by protocol family
1345
1346         * eagain - Resource temporarily unavailable
1347
1348         * ealign - EALIGN
1349
1350         * ealready - Operation already in progress
1351
1352         * ebade - Bad exchange descriptor
1353
1354         * ebadf - Bad file number
1355
1356         * ebadfd - File descriptor in bad state
1357
1358         * ebadmsg - Not a data message
1359
1360         * ebadr - Bad request descriptor
1361
1362         * ebadrpc - Bad RPC structure
1363
1364         * ebadrqc - Bad request code
1365
1366         * ebadslt - Invalid slot
1367
1368         * ebfont - Bad font file format
1369
1370         * ebusy - File busy
1371
1372         * echild - No children
1373
1374         * echrng - Channel number out of range
1375
1376         * ecomm - Communication error on send
1377
1378         * econnaborted - Software caused connection abort
1379
1380         * econnrefused - Connection refused
1381
1382         * econnreset - Connection reset by peer
1383
1384         * edeadlk - Resource deadlock avoided
1385
1386         * edeadlock - Resource deadlock avoided
1387
1388         * edestaddrreq - Destination address required
1389
1390         * edirty - Mounting a dirty fs without force
1391
1392         * edom - Math argument out of range
1393
1394         * edotdot - Cross mount point
1395
1396         * edquot - Disk quota exceeded
1397
1398         * eduppkg - Duplicate package name
1399
1400         * eexist - File already exists
1401
1402         * efault - Bad address in system call argument
1403
1404         * efbig - File too large
1405
1406         * ehostdown - Host is down
1407
1408         * ehostunreach - Host is unreachable
1409
1410         * eidrm - Identifier removed
1411
1412         * einit - Initialization error
1413
1414         * einprogress - Operation now in progress
1415
1416         * eintr - Interrupted system call
1417
1418         * einval - Invalid argument
1419
1420         * eio - I/O error
1421
1422         * eisconn - Socket is already connected
1423
1424         * eisdir - Illegal operation on a directory
1425
1426         * eisnam - Is a named file
1427
1428         * el2hlt - Level 2 halted
1429
1430         * el2nsync - Level 2 not synchronized
1431
1432         * el3hlt - Level 3 halted
1433
1434         * el3rst - Level 3 reset
1435
1436         * elbin - ELBIN
1437
1438         * elibacc - Cannot access a needed shared library
1439
1440         * elibbad - Accessing a corrupted shared library
1441
1442         * elibexec - Cannot exec a shared library directly
1443
1444         * elibmax  -  Attempting to link in more shared libraries than system
1445           limit
1446
1447         * elibscn - .lib section in a.out corrupted
1448
1449         * elnrng - Link number out of range
1450
1451         * eloop - Too many levels of symbolic links
1452
1453         * emfile - Too many open files
1454
1455         * emlink - Too many links
1456
1457         * emsgsize - Message too long
1458
1459         * emultihop - Multihop attempted
1460
1461         * enametoolong - Filename too long
1462
1463         * enavail - Unavailable
1464
1465         * enet - ENET
1466
1467         * enetdown - Network is down
1468
1469         * enetreset - Network dropped connection on reset
1470
1471         * enetunreach - Network is unreachable
1472
1473         * enfile - File table overflow
1474
1475         * enoano - Anode table overflow
1476
1477         * enobufs - No buffer space available
1478
1479         * enocsi - No CSI structure available
1480
1481         * enodata - No data available
1482
1483         * enodev - No such device
1484
1485         * enoent - No such file or directory
1486
1487         * enoexec - Exec format error
1488
1489         * enolck - No locks available
1490
1491         * enolink - Link has been severed
1492
1493         * enomem - Not enough memory
1494
1495         * enomsg - No message of desired type
1496
1497         * enonet - Machine is not on the network
1498
1499         * enopkg - Package not installed
1500
1501         * enoprotoopt - Bad protocol option
1502
1503         * enospc - No space left on device
1504
1505         * enosr - Out of stream resources or not a stream device
1506
1507         * enosym - Unresolved symbol name
1508
1509         * enosys - Function not implemented
1510
1511         * enotblk - Block device required
1512
1513         * enotconn - Socket is not connected
1514
1515         * enotdir - Not a directory
1516
1517         * enotempty - Directory not empty
1518
1519         * enotnam - Not a named file
1520
1521         * enotsock - Socket operation on non-socket
1522
1523         * enotsup - Operation not supported
1524
1525         * enotty - Inappropriate device for ioctl
1526
1527         * enotuniq - Name not unique on network
1528
1529         * enxio - No such device or address
1530
1531         * eopnotsupp - Operation not supported on socket
1532
1533         * eperm - Not owner
1534
1535         * epfnosupport - Protocol family not supported
1536
1537         * epipe - Broken pipe
1538
1539         * eproclim - Too many processes
1540
1541         * eprocunavail - Bad procedure for program
1542
1543         * eprogmismatch - Wrong program version
1544
1545         * eprogunavail - RPC program unavailable
1546
1547         * eproto - Protocol error
1548
1549         * eprotonosupport - Protocol not supported
1550
1551         * eprototype - Wrong protocol type for socket
1552
1553         * erange - Math result unrepresentable
1554
1555         * erefused - EREFUSED
1556
1557         * eremchg - Remote address changed
1558
1559         * eremdev - Remote device
1560
1561         * eremote - Pathname hit remote filesystem
1562
1563         * eremoteio - Remote I/O error
1564
1565         * eremoterelease - EREMOTERELEASE
1566
1567         * erofs - Read-only filesystem
1568
1569         * erpcmismatch - Wrong RPC version
1570
1571         * erremote - Object is remote
1572
1573         * eshutdown - Cannot send after socket shutdown
1574
1575         * esocktnosupport - Socket type not supported
1576
1577         * espipe - Invalid seek
1578
1579         * esrch - No such process
1580
1581         * esrmnt - Srmount error
1582
1583         * estale - Stale remote file handle
1584
1585         * esuccess - Error 0
1586
1587         * etime - Timer expired
1588
1589         * etimedout - Connection timed out
1590
1591         * etoomanyrefs - Too many references
1592
1593         * etxtbsy - Text file or pseudo-device busy
1594
1595         * euclean - Structure needs cleaning
1596
1597         * eunatch - Protocol driver not attached
1598
1599         * eusers - Too many users
1600
1601         * eversion - Version mismatch
1602
1603         * ewouldblock - Operation would block
1604
1605         * exdev - Cross-domain link
1606
1607         * exfull - Message tables full
1608
1609         * nxdomain - Hostname or domain name cannot be found
1610
1611Ericsson AB                     kernel 7.3.1.1                         inet(3)
Impressum