PageRenderTime 72ms CodeModel.GetById 29ms RepoModel.GetById 1ms app.codeStats 0ms

/lib/kernel/doc/src/inet.xml

https://github.com/bsmr-erlang/otp
XML | 1703 lines | 1665 code | 38 blank | 0 comment | 0 complexity | 1f633f9b429f318c3e5a0c8a36e3e7ab MD5 | raw file
Possible License(s): BSD-3-Clause, LGPL-2.1, MPL-2.0-no-copyleft-exception, Apache-2.0
  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <!DOCTYPE erlref SYSTEM "erlref.dtd">
  3. <erlref>
  4. <header>
  5. <copyright>
  6. <year>1997</year><year>2018</year>
  7. <holder>Ericsson AB. All Rights Reserved.</holder>
  8. </copyright>
  9. <legalnotice>
  10. Licensed under the Apache License, Version 2.0 (the "License");
  11. you may not use this file except in compliance with the License.
  12. You may obtain a copy of the License at
  13. http://www.apache.org/licenses/LICENSE-2.0
  14. Unless required by applicable law or agreed to in writing, software
  15. distributed under the License is distributed on an "AS IS" BASIS,
  16. WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  17. See the License for the specific language governing permissions and
  18. limitations under the License.
  19. </legalnotice>
  20. <title>inet</title>
  21. <prepared>bjorn@erix.ericsson.se</prepared>
  22. <docno></docno>
  23. <date>1998-02-04</date>
  24. <rev>A</rev>
  25. </header>
  26. <module since="">inet</module>
  27. <modulesummary>Access to TCP/IP protocols.</modulesummary>
  28. <description>
  29. <p>This module provides access to TCP/IP protocols.</p>
  30. <p>See also
  31. <seealso marker="erts:inet_cfg">ERTS User's Guide:
  32. Inet Configuration</seealso> for more information about how to
  33. configure an Erlang runtime system for IP communication.</p>
  34. <p>The following two Kernel configuration parameters affect the
  35. behavior of all sockets opened on an Erlang node:</p>
  36. <list type="bulleted">
  37. <item><p><c>inet_default_connect_options</c> can contain a list of
  38. default options used for all sockets returned when doing
  39. <c>connect</c>.</p></item>
  40. <item><p><c>inet_default_listen_options</c> can contain a list of
  41. default options used when issuing a <c>listen</c> call.</p></item>
  42. </list>
  43. <p>When <c>accept</c> is issued, the values of the listening socket options
  44. are inherited. No such application variable is therefore needed for
  45. <c>accept</c>.</p>
  46. <p>Using the Kernel configuration parameters above, one
  47. can set default options for all TCP sockets on a node, but use this
  48. with care. Options such as <c>{delay_send,true}</c> can be
  49. specified in this way. The following is an example of starting an Erlang
  50. node with all sockets using delayed send:</p>
  51. <pre>
  52. $ <input>erl -sname test -kernel \</input>
  53. <input>inet_default_connect_options '[{delay_send,true}]' \</input>
  54. <input>inet_default_listen_options '[{delay_send,true}]'</input></pre>
  55. <p>Notice that default option <c>{active, true}</c>
  56. cannot be changed, for internal reasons.</p>
  57. <p>Addresses as inputs to functions can be either a string or a
  58. tuple. For example, the IP address 150.236.20.73 can be passed to
  59. <c>gethostbyaddr/1</c>, either as string <c>"150.236.20.73"</c>
  60. or as tuple <c>{150, 236, 20, 73}</c>.</p>
  61. <p><em>IPv4 address examples:</em></p>
  62. <code type="none">
  63. Address ip_address()
  64. ------- ------------
  65. 127.0.0.1 {127,0,0,1}
  66. 192.168.42.2 {192,168,42,2}</code>
  67. <p><em>IPv6 address examples:</em></p>
  68. <code type="none">
  69. Address ip_address()
  70. ------- ------------
  71. ::1 {0,0,0,0,0,0,0,1}
  72. ::192.168.42.2 {0,0,0,0,0,0,(192 bsl 8) bor 168,(42 bsl 8) bor 2}
  73. ::FFFF:192.168.42.2
  74. {0,0,0,0,0,16#FFFF,(192 bsl 8) bor 168,(42 bsl 8) bor 2}
  75. 3ffe:b80:1f8d:2:204:acff:fe17:bf38
  76. {16#3ffe,16#b80,16#1f8d,16#2,16#204,16#acff,16#fe17,16#bf38}
  77. fe80::204:acff:fe17:bf38
  78. {16#fe80,0,0,0,0,16#204,16#acff,16#fe17,16#bf38}</code>
  79. <p>Function
  80. <seealso marker="#parse_address/1"><c>parse_address/1</c></seealso>
  81. can be useful:</p>
  82. <pre>
  83. 1> <input>inet:parse_address("192.168.42.2").</input>
  84. {ok,{192,168,42,2}}
  85. 2> <input>inet:parse_address("::FFFF:192.168.42.2").</input>
  86. {ok,{0,0,0,0,0,65535,49320,10754}}</pre>
  87. </description>
  88. <datatypes>
  89. <datatype>
  90. <name name="hostent"/>
  91. <desc>
  92. <p>The record is defined in the Kernel include file
  93. <c>"inet.hrl"</c>.</p>
  94. <p>Add the following directive to the module:</p>
  95. <code>
  96. -include_lib("kernel/include/inet.hrl").</code>
  97. </desc>
  98. </datatype>
  99. <datatype>
  100. <name name="hostname"/>
  101. </datatype>
  102. <datatype>
  103. <name name="ip_address"/>
  104. </datatype>
  105. <datatype>
  106. <name name="ip4_address"/>
  107. </datatype>
  108. <datatype>
  109. <name name="ip6_address"/>
  110. </datatype>
  111. <datatype>
  112. <name name="port_number"/>
  113. </datatype>
  114. <datatype>
  115. <name name="local_address"/>
  116. <desc>
  117. <p>
  118. This address family only works on Unix-like systems.
  119. </p>
  120. <p>
  121. <c><anno>File</anno></c> is normally a file pathname
  122. in a local filesystem. It is limited in length by the
  123. operating system, traditionally to 108 bytes.
  124. </p>
  125. <p>
  126. A <c>binary()</c> is passed as is to the operating system,
  127. but a <c>string()</c> is encoded according to the
  128. <seealso marker="file#native_name_encoding/0">
  129. system filename encoding mode.
  130. </seealso>
  131. </p>
  132. <p>
  133. Other addresses are possible, for example Linux implements
  134. "Abstract Addresses". See the documentation for
  135. Unix Domain Sockets on your system,
  136. normally <c>unix</c> in manual section 7.
  137. </p>
  138. <p>
  139. In most API functions where you can use
  140. this address family the port number must be <c>0</c>.
  141. </p>
  142. </desc>
  143. </datatype>
  144. <datatype>
  145. <name name="socket_address"/>
  146. </datatype>
  147. <datatype>
  148. <name name="socket_getopt"/>
  149. </datatype>
  150. <datatype>
  151. <name name="socket_setopt"/>
  152. </datatype>
  153. <datatype>
  154. <name name="returned_non_ip_address"/>
  155. <desc>
  156. <p>
  157. Addresses besides
  158. <seealso marker="#type-ip_address">
  159. <c>ip_address()</c>
  160. </seealso>
  161. ones that are returned from socket API functions.
  162. See in particular
  163. <seealso marker="#type-local_address">
  164. <c>local_address()</c>.
  165. </seealso>
  166. The <c>unspec</c> family corresponds to AF_UNSPEC and can
  167. occur if the other side has no socket address.
  168. The <c>undefined</c> family can only occur in the unlikely
  169. event of an address family that the VM does not recognize.
  170. </p>
  171. </desc>
  172. </datatype>
  173. <datatype>
  174. <name name="ancillary_data"/>
  175. <desc>
  176. <p>
  177. Ancillary data received with the data packet
  178. or read with the socket option
  179. <seealso marker="gen_tcp#type-pktoptions_value">
  180. <c>pktoptions</c>
  181. </seealso>
  182. from a TCP socket.
  183. </p>
  184. <p>
  185. The value(s) correspond to the currently active socket
  186. <seealso marker="#type-socket_setopt">options</seealso>
  187. <seealso marker="inet#option-recvtos"><c>recvtos</c></seealso>,
  188. <seealso marker="inet#option-recvtclass"><c>recvtclass</c></seealso>
  189. and
  190. <seealso marker="inet#option-recvttl"><c>recvttl</c></seealso>.
  191. </p>
  192. </desc>
  193. </datatype>
  194. <datatype>
  195. <name name="getifaddrs_ifopts"/>
  196. <desc>
  197. <p>
  198. Interface address description list returned from
  199. <seealso marker="#getifaddrs/0"><c>getifaddrs/0,1</c></seealso>
  200. for a named interface, translated from the returned
  201. data of the POSIX API function <c>getaddrinfo()</c>.
  202. </p>
  203. <p>
  204. <c><anno>Hwaddr</anno></c> is hardware dependent,
  205. for example, on Ethernet interfaces it is
  206. the 6-byte Ethernet address (MAC address (EUI-48 address)).
  207. </p>
  208. <p>
  209. The tuples <c>{addr,<anno>Addr</anno>}</c>,
  210. <c>{netmask,<anno>Netmask</anno>}</c>, and possibly
  211. <c>{broadaddr,<anno>Broadaddr</anno>}</c> or
  212. <c>{dstaddr,<anno>Dstaddr</anno>}</c>
  213. are repeated in the list
  214. if the interface has got multiple addresses.
  215. An interface may have multiple <c>{flag,_}</c> tuples
  216. for example if it has different flags
  217. for different address families.
  218. Multiple <c>{hwaddr,<anno>Hwaddr</anno>}</c> tuples
  219. is hard to say anything definite about, though.
  220. The tuple <c>{flag,<anno>Flags</anno>}</c> is mandatory,
  221. all others are optional.
  222. </p>
  223. <p>
  224. Do not rely too much on the order
  225. of <c><anno>Flags</anno></c> atoms
  226. or the <c><anno>Ifopt</anno></c> tuples.
  227. There are however some rules:
  228. </p>
  229. <list type="bulleted">
  230. <item><p>
  231. A <c>{flag,_}</c> tuple applies to all other tuples that follow.
  232. </p></item>
  233. <item><p>
  234. Immediately after <c>{addr,_}</c> follows <c>{netmask,_}</c>.
  235. </p></item>
  236. <item><p>
  237. Immediately thereafter may <c>{broadaddr,_}</c> follow
  238. if <c>broadcast</c> is member of <c><anno>Flags</anno></c>,
  239. or <c>{dstaddr,_}</c> if <c>pointtopoint</c>
  240. is member of <c><anno>Flags</anno></c>.
  241. Both <c>{dstaddr,_}</c> and <c>{broadaddr,_}</c>
  242. does not occur for the same <c>{addr,_}</c>.
  243. </p></item>
  244. <item><p>
  245. Any <c>{netmask,_}</c>, <c>{broadaddr,_}</c>, or
  246. <c>{dstaddr,_}</c> tuples that follow an
  247. <c>{addr,<anno>Addr</anno>}</c>
  248. tuple concerns the address <c><anno>Addr</anno></c>.
  249. </p></item>
  250. </list>
  251. <p>
  252. The tuple <c>{hwaddr,_}</c> is not returned on Solaris, as the
  253. hardware address historically belongs to the link layer
  254. and it is not returned by the Solaris API function
  255. <c>getaddrinfo()</c>.
  256. </p>
  257. <warning>
  258. <p>
  259. On Windows, the data is fetched from different
  260. OS API functions, so the <c><anno>Netmask</anno></c>
  261. and <c><anno>Broadaddr</anno></c> values may be calculated,
  262. just as some <c><anno>Flags</anno></c> values.
  263. </p>
  264. </warning>
  265. </desc>
  266. </datatype>
  267. <datatype>
  268. <name name="posix"/>
  269. <desc>
  270. <p>An atom that is named from the POSIX error codes used in Unix,
  271. and in the runtime libraries of most C compilers. See section
  272. <seealso marker="#error_codes">POSIX Error Codes</seealso>.</p>
  273. </desc>
  274. </datatype>
  275. <datatype>
  276. <name>socket()</name>
  277. <desc>
  278. <p>See
  279. <seealso marker="gen_tcp#type-socket"><c>gen_tcp:type-socket</c></seealso>
  280. and
  281. <seealso marker="gen_udp#type-socket"><c>gen_udp:type-socket</c></seealso>.
  282. </p>
  283. </desc>
  284. </datatype>
  285. <datatype>
  286. <name name="address_family"/>
  287. </datatype>
  288. <datatype>
  289. <name name="socket_protocol"/>
  290. </datatype>
  291. <datatype>
  292. <name name="stat_option"/>
  293. </datatype>
  294. </datatypes>
  295. <funcs>
  296. <func>
  297. <name name="close" arity="1" since=""/>
  298. <fsummary>Close a socket of any type.</fsummary>
  299. <desc>
  300. <p>Closes a socket of any type.</p>
  301. </desc>
  302. </func>
  303. <func>
  304. <name name="format_error" arity="1" since=""/>
  305. <fsummary>Return a descriptive string for an error reason.</fsummary>
  306. <desc>
  307. <p>Returns a diagnostic error string. For possible POSIX values and
  308. corresponding strings, see section
  309. <seealso marker="#error_codes">POSIX Error Codes</seealso>.</p>
  310. </desc>
  311. </func>
  312. <func>
  313. <name name="get_rc" arity="0" since=""/>
  314. <fsummary>Return a list of IP configuration parameters.</fsummary>
  315. <desc>
  316. <p>
  317. Returns the state of the <c>Inet</c> configuration database in
  318. form of a list of recorded configuration parameters. For more
  319. information, see <seealso marker="erts:inet_cfg">ERTS User's Guide:
  320. Inet Configuration</seealso>.
  321. </p>
  322. <p>
  323. Only actual parameters with other than default values
  324. are returned, for example not directives that specify
  325. other sources for configuration parameters nor
  326. directives that clear parameters.
  327. </p>
  328. </desc>
  329. </func>
  330. <func>
  331. <name name="getaddr" arity="2" since=""/>
  332. <fsummary>Return the IP address for a host.</fsummary>
  333. <desc>
  334. <p>Returns the IP address for <c><anno>Host</anno></c> as a tuple of
  335. integers. <c><anno>Host</anno></c> can be an IP address, a single
  336. hostname, or a fully qualified hostname.</p>
  337. </desc>
  338. </func>
  339. <func>
  340. <name name="getaddrs" arity="2" since=""/>
  341. <fsummary>Return the IP addresses for a host.</fsummary>
  342. <desc>
  343. <p>Returns a list of all IP addresses for <c><anno>Host</anno></c>.
  344. <c><anno>Host</anno></c> can be an IP address, a single hostname, or
  345. a fully qualified hostname.</p>
  346. </desc>
  347. </func>
  348. <func>
  349. <name name="gethostbyaddr" arity="1" since=""/>
  350. <fsummary>Return a hostent record for the host with the specified
  351. address.</fsummary>
  352. <desc>
  353. <p>Returns a <c>hostent</c> record for the host with the specified
  354. address.</p></desc>
  355. </func>
  356. <func>
  357. <name name="gethostbyname" arity="1" since=""/>
  358. <fsummary>Return a hostent record for the host with the specified name.
  359. </fsummary>
  360. <desc>
  361. <p>Returns a <c>hostent</c> record for the host with the specified
  362. hostname.</p>
  363. <p>If resolver option <c>inet6</c> is <c>true</c>,
  364. an IPv6 address is looked up.</p>
  365. </desc>
  366. </func>
  367. <func>
  368. <name name="gethostbyname" arity="2" since=""/>
  369. <fsummary>Return a hostent record for the host with the specified name.
  370. </fsummary>
  371. <desc>
  372. <p>Returns a <c>hostent</c> record for the host with the specified
  373. name, restricted to the specified address family.</p>
  374. </desc>
  375. </func>
  376. <func>
  377. <name name="gethostname" arity="0" since=""/>
  378. <fsummary>Return the local hostname.</fsummary>
  379. <desc>
  380. <p>Returns the local hostname. Never fails.</p>
  381. </desc>
  382. </func>
  383. <func>
  384. <name name="getifaddrs" arity="0" since="OTP R14B01"/>
  385. <fsummary>Return a list of interfaces and their addresses.</fsummary>
  386. <desc>
  387. <p>
  388. Returns a list of 2-tuples containing interface names and
  389. the interfaces' addresses. <c><anno>Ifname</anno></c>
  390. is a Unicode string and
  391. <c><anno>Ifopts</anno></c> is a list of
  392. interface address description tuples.
  393. </p>
  394. <p>
  395. The interface address description tuples
  396. are documented under the type of the
  397. <seealso marker="#type-getifaddrs_ifopts">
  398. <c><anno>Ifopts</anno></c>
  399. </seealso>
  400. value.
  401. </p>
  402. </desc>
  403. </func>
  404. <func>
  405. <name since="OTP 21.2">getifaddrs(Opts) ->
  406. {ok, [{Ifname, Ifopts}]} | {error, Posix}
  407. </name>
  408. <fsummary>Return a list of interfaces and their addresses.</fsummary>
  409. <type>
  410. <v>
  411. Opts = [{netns, Namespace}]
  412. </v>
  413. <v>
  414. Namespace =
  415. <seealso marker="file#type-filename_all">
  416. file:filename_all()
  417. </seealso>
  418. </v>
  419. <v>Ifname = string()</v>
  420. <v>
  421. Ifopts =
  422. <seealso marker="#type-getifaddrs_ifopts">
  423. getifaddrs_ifopts()
  424. </seealso>
  425. </v>
  426. <v>Posix = <seealso marker="#type-posix">posix()</seealso></v>
  427. </type>
  428. <desc>
  429. <p>
  430. The same as
  431. <seealso marker="#getifaddrs/0"><c>getifaddrs/0</c></seealso>
  432. but the <c>Option</c>
  433. <c>{netns, Namespace}</c> sets a network namespace
  434. for the OS call, on platforms that supports that feature.
  435. </p>
  436. <p>
  437. See the socket option
  438. <seealso marker="#option-netns">
  439. <c>{netns, Namespace}</c>
  440. </seealso>
  441. under
  442. <seealso marker="#setopts/2"><c>setopts/2</c></seealso>.
  443. </p>
  444. </desc>
  445. </func>
  446. <func>
  447. <name name="getopts" arity="2" since=""/>
  448. <fsummary>Get one or more options for a socket.</fsummary>
  449. <desc>
  450. <p>Gets one or more options for a socket. For a list of available
  451. options, see
  452. <seealso marker="#setopts/2"><c>setopts/2</c></seealso>.
  453. See also the description for the type
  454. <seealso marker="gen_tcp#type-pktoptions_value">
  455. <c>gen_tcp:pktoptions_value()</c>
  456. </seealso>.</p>
  457. <p>The number of elements in the returned
  458. <c><anno>OptionValues</anno></c>
  459. list does not necessarily correspond to the number of options
  460. asked for. If the operating system fails to support an option,
  461. it is left out in the returned list. An error tuple is returned
  462. only when getting options for the socket is impossible (that is,
  463. the socket is closed or the buffer size in a raw request
  464. is too large). This behavior is kept for backward
  465. compatibility reasons.</p>
  466. <p>A raw option request
  467. <c>RawOptReq = {raw, Protocol, OptionNum, ValueSpec}</c>
  468. can be used to get information about
  469. socket options not (explicitly) supported by the emulator. The
  470. use of raw socket options makes the code non-portable, but
  471. allows the Erlang programmer to take advantage of unusual features
  472. present on a particular platform.</p>
  473. <p><c>RawOptReq</c> consists of tag <c>raw</c> followed
  474. by the protocol level, the option number, and either a binary
  475. or the size, in bytes, of the
  476. buffer in which the option value is to be stored. A binary is to be
  477. used when the underlying <c>getsockopt</c> requires <em>input</em>
  478. in the argument field. In this case, the binary size
  479. is to correspond to the required buffer
  480. size of the return value. The supplied values in a <c>RawOptReq</c>
  481. correspond to the second, third, and fourth/fifth parameters to the
  482. <c>getsockopt</c> call in the C socket API. The value stored
  483. in the buffer is returned as a binary <c>ValueBin</c>,
  484. where all values are coded in the native endianess.</p>
  485. <p>Asking for and inspecting raw socket options require low-level
  486. information about the current operating system and TCP stack.</p>
  487. <p><em>Example:</em></p>
  488. <p>Consider a Linux machine where option
  489. <c>TCP_INFO</c> can be used to collect TCP statistics
  490. for a socket. Assume you are interested in field
  491. <c>tcpi_sacked</c> of <c>struct tcp_info</c>
  492. filled in when asking for <c>TCP_INFO</c>. To be able to access
  493. this information, you need to know the following:</p>
  494. <list type="bulleted">
  495. <item>The numeric value of protocol level <c>IPPROTO_TCP</c></item>
  496. <item>The numeric value of option <c>TCP_INFO</c></item>
  497. <item>The size of <c>struct tcp_info</c></item>
  498. <item>The size and offset of the specific field</item>
  499. </list>
  500. <p>By inspecting the headers or writing a small C program, it is found
  501. that <c>IPPROTO_TCP</c> is 6, <c>TCP_INFO</c> is 11, the structure
  502. size is 92 (bytes), the offset of <c>tcpi_sacked</c> is 28 bytes,
  503. and the value is a 32-bit integer. The following code can be used
  504. to retrieve the value:</p>
  505. <code type="none"><![CDATA[
  506. get_tcpi_sacked(Sock) ->
  507. {ok,[{raw,_,_,Info}]} = inet:getopts(Sock,[{raw,6,11,92}]),
  508. <<_:28/binary,TcpiSacked:32/native,_/binary>> = Info,
  509. TcpiSacked.]]></code>
  510. <p>Preferably, you would check the machine type, the operating system,
  511. and the Kernel version before executing anything similar to
  512. this code.</p>
  513. </desc>
  514. </func>
  515. <func>
  516. <name name="getstat" arity="1" since=""/>
  517. <name name="getstat" arity="2" since=""/>
  518. <fsummary>Get one or more statistic options for a socket.</fsummary>
  519. <type name="stat_option"/>
  520. <desc>
  521. <p>Gets one or more statistic options for a socket.</p>
  522. <p><c>getstat(<anno>Socket</anno>)</c> is equivalent to
  523. <c>getstat(<anno>Socket</anno>, [recv_avg, recv_cnt, recv_dvi,
  524. recv_max, recv_oct, send_avg, send_cnt, send_dvi, send_max,
  525. send_oct])</c>.</p>
  526. <p>The following options are available:</p>
  527. <taglist>
  528. <tag><c>recv_avg</c></tag>
  529. <item>
  530. <p>Average size of packets, in bytes, received by the socket.</p>
  531. </item>
  532. <tag><c>recv_cnt</c></tag>
  533. <item>
  534. <p>Number of packets received by the socket.</p>
  535. </item>
  536. <tag><c>recv_dvi</c></tag>
  537. <item>
  538. <p>Average packet size deviation, in bytes, received by the socket.</p>
  539. </item>
  540. <tag><c>recv_max</c></tag>
  541. <item>
  542. <p>Size of the largest packet, in bytes, received by the socket.</p>
  543. </item>
  544. <tag><c>recv_oct</c></tag>
  545. <item>
  546. <p>Number of bytes received by the socket.</p>
  547. </item>
  548. <tag><c>send_avg</c></tag>
  549. <item>
  550. <p>Average size of packets, in bytes, sent from the socket.</p>
  551. </item>
  552. <tag><c>send_cnt</c></tag>
  553. <item>
  554. <p>Number of packets sent from the socket.</p>
  555. </item>
  556. <tag><c>send_dvi</c></tag>
  557. <item>
  558. <p>Average packet size deviation, in bytes, sent from the socket.</p>
  559. </item>
  560. <tag><c>send_max</c></tag>
  561. <item>
  562. <p>Size of the largest packet, in bytes, sent from the socket.</p>
  563. </item>
  564. <tag><c>send_oct</c></tag>
  565. <item>
  566. <p>Number of bytes sent from the socket.</p>
  567. </item>
  568. </taglist>
  569. </desc>
  570. </func>
  571. <func>
  572. <name name="i" arity="0" since="OTP 21.0"/>
  573. <name name="i" arity="1" since="OTP 21.0"/>
  574. <name name="i" arity="2" since="OTP 21.0"/>
  575. <fsummary>Displays information and statistics about sockets on the terminal</fsummary>
  576. <desc>
  577. <p>
  578. Lists all TCP, UDP and SCTP sockets, including those that the Erlang runtime system uses as well as
  579. those created by the application.
  580. </p>
  581. <p>
  582. The following options are available:
  583. </p>
  584. <taglist>
  585. <tag><c>port</c></tag>
  586. <item>
  587. <p>The internal index of the port.</p>
  588. </item>
  589. <tag><c>module</c></tag>
  590. <item>
  591. <p>The callback module of the socket.</p>
  592. </item>
  593. <tag><c>recv</c></tag>
  594. <item>
  595. <p>Number of bytes received by the socket.</p>
  596. </item>
  597. <tag><c>sent</c></tag>
  598. <item>
  599. <p>Number of bytes sent from the socket.</p>
  600. </item>
  601. <tag><c>owner</c></tag>
  602. <item>
  603. <p>The socket owner process.</p>
  604. </item>
  605. <tag><c>local_address</c></tag>
  606. <item>
  607. <p>The local address of the socket.</p>
  608. </item>
  609. <tag><c>foreign_address</c></tag>
  610. <item>
  611. <p>The address and port of the other end of the connection.</p>
  612. </item>
  613. <tag><c>state</c></tag>
  614. <item>
  615. <p>The connection state.</p>
  616. </item>
  617. <tag><c>type</c></tag>
  618. <item>
  619. <p>STREAM or DGRAM or SEQPACKET.</p>
  620. </item>
  621. </taglist>
  622. </desc>
  623. </func>
  624. <func>
  625. <name name="ntoa" arity="1" since="OTP R16B02"/>
  626. <fsummary>Convert IPv6/IPV4 address to ASCII.</fsummary>
  627. <desc>
  628. <p>Parses an
  629. <seealso marker="#type-ip_address"><c>ip_address()</c></seealso>
  630. and returns an IPv4 or IPv6 address string.</p>
  631. </desc>
  632. </func>
  633. <func>
  634. <name name="parse_address" arity="1" since="OTP R16B"/>
  635. <fsummary>Parse an IPv4 or IPv6 address.</fsummary>
  636. <desc>
  637. <p>Parses an IPv4 or IPv6 address string and returns an
  638. <seealso marker="#type-ip4_address"><c>ip4_address()</c></seealso> or
  639. <seealso marker="#type-ip6_address"><c>ip6_address()</c></seealso>.
  640. Accepts a shortened IPv4 address string.</p>
  641. </desc>
  642. </func>
  643. <func>
  644. <name name="parse_ipv4_address" arity="1" since="OTP R16B"/>
  645. <fsummary>Parse an IPv4 address.</fsummary>
  646. <desc>
  647. <p>Parses an IPv4 address string and returns an
  648. <seealso marker="#type-ip4_address"><c>ip4_address()</c></seealso>.
  649. Accepts a shortened IPv4 address string.</p>
  650. </desc>
  651. </func>
  652. <func>
  653. <name name="parse_ipv4strict_address" arity="1" since="OTP R16B"/>
  654. <fsummary>Parse an IPv4 address strict.</fsummary>
  655. <desc>
  656. <p>Parses an IPv4 address string containing four fields, that is,
  657. <em>not</em> shortened, and returns an
  658. <seealso marker="#type-ip4_address"><c>ip4_address()</c></seealso>.
  659. </p>
  660. </desc>
  661. </func>
  662. <func>
  663. <name name="parse_ipv6_address" arity="1" since="OTP R16B"/>
  664. <fsummary>Parse an IPv6 address.</fsummary>
  665. <desc>
  666. <p>Parses an IPv6 address string and returns an
  667. <seealso marker="#type-ip6_address"><c>ip6_address()</c></seealso>.
  668. If an IPv4 address string is specified, an IPv4-mapped IPv6 address
  669. is returned.</p>
  670. </desc>
  671. </func>
  672. <func>
  673. <name name="parse_ipv6strict_address" arity="1" since="OTP R16B"/>
  674. <fsummary>Parse an IPv6 address strict.</fsummary>
  675. <desc>
  676. <p>Parses an IPv6 address string and returns an
  677. <seealso marker="#type-ip6_address"><c>ip6_address()</c></seealso>.
  678. Does <em>not</em> accept IPv4 addresses.</p>
  679. </desc>
  680. </func>
  681. <func>
  682. <name name="ipv4_mapped_ipv6_address" arity="1" since="OTP 21.0"/>
  683. <fsummary>Convert to and from IPv4-mapped IPv6 address.</fsummary>
  684. <desc>
  685. <p>
  686. Convert an IPv4 address to an IPv4-mapped IPv6 address
  687. or the reverse. When converting from an IPv6 address
  688. all but the 2 low words are ignored so this function also
  689. works on some other types of addresses than IPv4-mapped.
  690. </p>
  691. </desc>
  692. </func>
  693. <func>
  694. <name name="parse_strict_address" arity="1" since="OTP R16B"/>
  695. <fsummary>Parse an IPv4 or IPv6 address strict.</fsummary>
  696. <desc>
  697. <p>Parses an IPv4 or IPv6 address string and returns an
  698. <seealso marker="#type-ip4_address"><c>ip4_address()</c></seealso> or
  699. <seealso marker="#type-ip6_address"><c>ip6_address()</c></seealso>.
  700. Does <em>not</em> accept a shortened IPv4 address string.</p>
  701. </desc>
  702. </func>
  703. <func>
  704. <name name="peername" arity="1" since=""/>
  705. <fsummary>Return the address and port for the other end of a connection.
  706. </fsummary>
  707. <desc>
  708. <p>Returns the address and port for the other end of a connection.</p>
  709. <p>Notice that for SCTP sockets, this function returns only
  710. one of the peer addresses of the socket. Function
  711. <seealso marker="#peernames/1"><c>peernames/1,2</c></seealso>
  712. returns all.</p>
  713. </desc>
  714. </func>
  715. <func>
  716. <name name="peernames" arity="1" since="OTP R16B03"/>
  717. <fsummary>Return all address/port numbers for the other end of a
  718. connection.</fsummary>
  719. <desc>
  720. <p>Equivalent to
  721. <seealso marker="#peernames/2"><c>peernames(<anno>Socket</anno>, 0)</c></seealso>.
  722. </p>
  723. <p>Notice that the behavior of this function for an SCTP
  724. one-to-many style socket is not defined by the
  725. <url href="http://tools.ietf.org/html/draft-ietf-tsvwg-sctpsocket-13">SCTP Sockets API Extensions</url>.</p>
  726. </desc>
  727. </func>
  728. <func>
  729. <name name="peernames" arity="2" since="OTP R16B03"/>
  730. <fsummary>Return all address/port numbers for the other end of a
  731. connection.</fsummary>
  732. <desc>
  733. <p>Returns a list of all address/port number pairs for the other end
  734. of an association <c><anno>Assoc</anno></c> of a socket.</p>
  735. <p>This function can return multiple addresses for multihomed
  736. sockets, such as SCTP sockets. For other sockets it
  737. returns a one-element list.</p>
  738. <p>Notice that parameter <c><anno>Assoc</anno></c> is by the
  739. <url href="http://tools.ietf.org/html/draft-ietf-tsvwg-sctpsocket-13">SCTP Sockets API Extensions</url>
  740. defined to be ignored for
  741. one-to-one style sockets. What the special value <c>0</c>
  742. means, hence its behavior for one-to-many style sockets,
  743. is unfortunately undefined.</p>
  744. </desc>
  745. </func>
  746. <func>
  747. <name name="port" arity="1" since=""/>
  748. <fsummary>Return the local port number for a socket.</fsummary>
  749. <desc>
  750. <p>Returns the local port number for a socket.</p>
  751. </desc>
  752. </func>
  753. <func>
  754. <name name="setopts" arity="2" since=""/>
  755. <fsummary>Set one or more options for a socket.</fsummary>
  756. <desc>
  757. <p>Sets one or more options for a socket.</p>
  758. <p>The following options are available:</p>
  759. <taglist>
  760. <tag><c>{active, true | false | once | N}</c></tag>
  761. <item>
  762. <p>If the value is <c>true</c>, which is the default,
  763. everything received from the socket is sent as
  764. messages to the receiving process.</p>
  765. <p>If the value is <c>false</c> (passive mode), the process must
  766. explicitly receive incoming data by calling
  767. <seealso marker="gen_tcp#recv/2"><c>gen_tcp:recv/2,3</c></seealso>,
  768. <seealso marker="gen_udp#recv/2"><c>gen_udp:recv/2,3</c></seealso>,
  769. or <seealso marker="gen_sctp#recv/1"><c>gen_sctp:recv/1,2</c></seealso>
  770. (depending on the type of socket).</p>
  771. <p>If the value is <c>once</c> (<c>{active, once}</c>),
  772. <em>one</em> data message from the socket is sent
  773. to the process. To receive one more message,
  774. <c>setopts/2</c> must be called again with option
  775. <c>{active, once}</c>.</p>
  776. <p>If the value is an integer <c>N</c> in the range -32768 to 32767
  777. (inclusive), the value is added to the socket's count of data
  778. messages sent to the controlling process. A socket's default
  779. message count is <c>0</c>. If a negative value is specified, and
  780. its magnitude is equal to or greater than the socket's current
  781. message count, the socket's message count is set to <c>0</c>.
  782. Once the socket's message count reaches <c>0</c>, either because
  783. of sending
  784. received data messages to the process or by being explicitly set,
  785. the process is then notified by a special message, specific to
  786. the type of socket, that the socket has entered passive
  787. mode. Once the socket enters passive mode, to receive more
  788. messages <c>setopts/2</c> must be called again to set the
  789. socket back into an active mode.</p>
  790. <p>When using <c>{active, once}</c> or <c>{active, N}</c>, the
  791. socket changes behavior automatically when data is received.
  792. This can be confusing in combination with connection-oriented
  793. sockets (that is, <c>gen_tcp</c>), as a socket
  794. with <c>{active, false}</c> behavior reports closing
  795. differently than a socket with <c>{active, true}</c>
  796. behavior. To simplify programming, a socket where
  797. the peer closed, and this is detected while in
  798. <c>{active, false}</c> mode, still generates message
  799. <c>{tcp_closed,Socket}</c> when set to <c>{active, once}</c>,
  800. <c>{active, true}</c>, or <c>{active, N}</c> mode.
  801. It is therefore safe to assume that message
  802. <c>{tcp_closed,Socket}</c>, possibly followed by socket port
  803. termination (depending on option <c>exit_on_close</c>)
  804. eventually appears when a socket changes
  805. back and forth between <c>{active, true}</c> and
  806. <c>{active, false}</c> mode. However,
  807. <em>when</em> peer closing is detected it is all up to the
  808. underlying TCP/IP stack and protocol.</p>
  809. <p>Notice that <c>{active, true}</c> mode provides no flow
  810. control; a fast sender can easily overflow the
  811. receiver with incoming messages. The same is true for
  812. <c>{active, N}</c> mode, while the message count is greater
  813. than zero.</p>
  814. <p>Use active mode only if
  815. your high-level protocol provides its own flow control
  816. (for example, acknowledging received messages) or the
  817. amount of data exchanged is small. <c>{active, false}</c>
  818. mode, use of the <c>{active, once}</c> mode, or <c>{active, N}</c>
  819. mode with values of <c>N</c> appropriate for the application
  820. provides flow control. The other side cannot send
  821. faster than the receiver can read.</p>
  822. </item>
  823. <tag><c>{broadcast, Boolean}</c> (UDP sockets)</tag>
  824. <item>
  825. <p>Enables/disables permission to send broadcasts.</p>
  826. <marker id="option-buffer"></marker>
  827. </item>
  828. <tag><c>{buffer, Size}</c></tag>
  829. <item>
  830. <p>The size of the user-level buffer used by
  831. the driver. Not to be confused with options <c>sndbuf</c>
  832. and <c>recbuf</c>, which correspond to the
  833. Kernel socket buffers. For TCP it is recommended
  834. to have <c>val(buffer) &gt;= val(recbuf)</c> to
  835. avoid performance issues because of unnecessary copying.
  836. For UDP the same recommendation applies, but the max should
  837. not be larger than the MTU of the network path.
  838. <c>val(buffer)</c> is automatically set to the above
  839. maximum when <c>recbuf</c> is set.
  840. However, as the size set for <c>recbuf</c>
  841. usually become larger, you are encouraged to use
  842. <seealso marker="#getopts/2"><c>getopts/2</c></seealso>
  843. to analyze the behavior of your operating system.</p>
  844. <p>Note that this is also the maximum amount of data that can be
  845. received from a single recv call. If you are using higher than
  846. normal MTU consider setting buffer higher.</p>
  847. </item>
  848. <tag><c>{delay_send, Boolean}</c></tag>
  849. <item>
  850. <p>Normally, when an Erlang process sends to a socket,
  851. the driver tries to send the data immediately. If that
  852. fails, the driver uses any means available to queue
  853. up the message to be sent whenever the operating system
  854. says it can handle it. Setting <c>{delay_send, true}</c>
  855. makes <em>all</em> messages queue up. The messages sent
  856. to the network are then larger but fewer.
  857. The option affects the scheduling of send
  858. requests versus Erlang processes instead of changing any
  859. real property of the socket. The option is
  860. implementation-specific. Defaults to <c>false</c>.</p>
  861. </item>
  862. <tag><c>{deliver, port | term}</c></tag>
  863. <item>
  864. <p>When <c>{active, true}</c>, data is delivered on the form
  865. <c>port</c> : <c>{S, {data, [H1,..Hsz | Data]}}</c> or
  866. <c>term</c> : <c>{tcp, S, [H1..Hsz | Data]}</c>.</p>
  867. </item>
  868. <tag><c>{dontroute, Boolean}</c></tag>
  869. <item>
  870. <p>Enables/disables routing bypass for outgoing messages.</p>
  871. </item>
  872. <tag><c>{exit_on_close, Boolean}</c></tag>
  873. <item>
  874. <p>This option is set to <c>true</c> by default.</p>
  875. <p>The only reason to set it to <c>false</c> is if you want
  876. to continue sending data to the socket after a close is
  877. detected, for example, if the peer uses
  878. <seealso marker="gen_tcp#shutdown/2"><c>gen_tcp:shutdown/2</c></seealso>
  879. to shut down the write side.</p>
  880. </item>
  881. <tag><c>{header, Size}</c></tag>
  882. <item>
  883. <p>This option is only meaningful if option <c>binary</c>
  884. was specified when the socket was created. If option
  885. <c>header</c> is specified, the first
  886. <c>Size</c> number bytes of data received from the socket
  887. are elements of a list, and the remaining data is
  888. a binary specified as the tail of the same list. For example,
  889. if <c>Size == 2</c>, the data received matches
  890. <c>[Byte1,Byte2|Binary]</c>.</p>
  891. </item>
  892. <tag><c>{high_msgq_watermark, Size}</c></tag>
  893. <item>
  894. <p>The socket message queue is set to a busy
  895. state when the amount of data on the message
  896. queue reaches this limit. Notice that this limit only
  897. concerns data that has not yet reached the ERTS internal
  898. socket implementation. Defaults to 8 kB.</p>
  899. <p>Senders of data to the socket are suspended if
  900. either the socket message queue is busy or the socket
  901. itself is busy.</p>
  902. <p>For more information, see options <c>low_msgq_watermark</c>,
  903. <c>high_watermark</c>, and <c>low_watermark</c>.</p>
  904. <p>Notice that distribution sockets disable the use of
  905. <c>high_msgq_watermark</c> and <c>low_msgq_watermark</c>.
  906. Instead use the
  907. <seealso marker="erts:erlang#system_info_dist_buf_busy_limit">distribution buffer busy limit</seealso>,
  908. which is a similar feature.</p>
  909. </item>
  910. <tag><c>{high_watermark, Size}</c> (TCP/IP sockets)</tag>
  911. <item>
  912. <p>The socket is set to a busy state when the amount
  913. of data queued internally by the ERTS socket implementation
  914. reaches this limit. Defaults to 8 kB.</p>
  915. <p>Senders of data to the socket are suspended if
  916. either the socket message queue is busy or the socket
  917. itself is busy.</p>
  918. <p>For more information, see options <c>low_watermark</c>,
  919. <c>high_msgq_watermark</c>, and <c>low_msqg_watermark</c>.</p>
  920. </item>
  921. <tag><c>{ipv6_v6only, Boolean}</c></tag>
  922. <item>
  923. <p>Restricts the socket to use only IPv6, prohibiting any
  924. IPv4 connections. This is only applicable for
  925. IPv6 sockets (option <c>inet6</c>).</p>
  926. <p>On most platforms this option must be set on the socket
  927. before associating it to an address. It is therefore only
  928. reasonable to specify it when creating the socket and not
  929. to use it when calling function
  930. (<seealso marker="#setopts/2"><c>setopts/2</c></seealso>)
  931. containing this description.</p>
  932. <p>The behavior of a socket with this option set to
  933. <c>true</c> is the only portable one. The original
  934. idea when IPv6 was new of using IPv6 for all traffic
  935. is now not recommended by FreeBSD (you can use
  936. <c>{ipv6_v6only,false}</c> to override the recommended
  937. system default value),
  938. forbidden by OpenBSD (the supported GENERIC kernel),
  939. and impossible on Windows (which has separate
  940. IPv4 and IPv6 protocol stacks). Most Linux distros
  941. still have a system default value of <c>false</c>.
  942. This policy shift among operating systems to
  943. separate IPv6 from IPv4 traffic has evolved, as
  944. it gradually proved hard and complicated to get
  945. a dual stack implementation correct and secure.</p>
  946. <p>On some platforms, the only allowed value for this option
  947. is <c>true</c>, for example, OpenBSD and Windows. Trying to set
  948. this option to <c>false</c>, when creating the socket, fails
  949. in this case.</p>
  950. <p>Setting this option on platforms where it does not exist
  951. is ignored. Getting this option with
  952. <seealso marker="#getopts/2"><c>getopts/2</c></seealso>
  953. returns no value, that is, the returned list does not contain an
  954. <c>{ipv6_v6only,_}</c> tuple. On Windows, the option
  955. does not exist, but it is emulated as a
  956. read-only option with value <c>true</c>.</p>
  957. <p>Therefore, setting this option to <c>true</c>
  958. when creating a socket never fails, except possibly on a
  959. platform where you
  960. have customized the kernel to only allow <c>false</c>,
  961. which can be doable (but awkward) on, for example, OpenBSD.</p>
  962. <p>If you read back the option value using
  963. <seealso marker="#getopts/2"><c>getopts/2</c></seealso>
  964. and get no value, the option does not exist in the host
  965. operating system. The behavior of both an IPv6 and an IPv4
  966. socket listening on the same port, and for an IPv6 socket
  967. getting IPv4 traffic is then no longer predictable.</p>
  968. </item>
  969. <tag><c>{keepalive, Boolean}</c>(TCP/IP sockets)</tag>
  970. <item>
  971. <p>Enables/disables periodic transmission on a connected
  972. socket when no other data is exchanged. If
  973. the other end does not respond, the connection is
  974. considered broken and an error message is sent to
  975. the controlling process. Defaults to <c>disabled</c>.</p>
  976. <marker id="option-linger"></marker>
  977. </item>
  978. <tag><c>{linger, {true|false, Seconds}}</c></tag>
  979. <item>
  980. <p>Determines the time-out, in seconds, for flushing unsent data
  981. in the <c>close/1</c> socket call. </p>
  982. <p>The first component is if linger is enabled, the second component
  983. is the flushing time-out, in seconds. There are 3 alternatives:</p>
  984. <taglist>
  985. <tag><c>{false, _}</c></tag>
  986. <item>
  987. <p>close/1 or shutdown/2 returns immediately,
  988. not waiting for data to be flushed, with closing
  989. happening in the background.</p>
  990. </item>
  991. <tag><c>{true, 0}</c></tag>
  992. <item>
  993. <p>Aborts the connection when it is closed.
  994. Discards any data still remaining in the send buffers
  995. and sends RST to the peer.</p>
  996. <p>This avoids TCP's TIME_WAIT state, but leaves open
  997. the possibility that another "incarnation" of this connection
  998. being created.</p>
  999. </item>
  1000. <tag><c>{true, Time} when Time > 0</c></tag>
  1001. <item>
  1002. <p>close/1 or shutdown/2 will not return until
  1003. all queued messages for the socket have been successfully
  1004. sent or the linger timeout (Time) has been reached.</p>
  1005. </item>
  1006. </taglist>
  1007. </item>
  1008. <tag><c>{low_msgq_watermark, Size}</c></tag>
  1009. <item>
  1010. <p>If the socket message queue is in a busy state, the
  1011. socket message queue is set in a not busy state when
  1012. the amount of data queued in the message queue falls
  1013. below this limit. Notice that this limit only concerns data
  1014. that has not yet reached the ERTS internal socket
  1015. implementation. Defaults to 4 kB.</p>
  1016. <p>Senders that are suspended because of either a
  1017. busy message queue or a busy socket are resumed
  1018. when the socket message queue and the socket
  1019. are not busy.</p>
  1020. <p>For more information, see options <c>high_msgq_watermark</c>,
  1021. <c>high_watermark</c>, and <c>low_watermark</c>.</p>
  1022. <p>Notice that distribution sockets disable the use of
  1023. <c>high_msgq_watermark</c> and <c>low_msgq_watermark</c>.
  1024. Instead they use the
  1025. <seealso marker="erts:erlang#system_info_dist_buf_busy_limit">distribution
  1026. buffer busy limit</seealso>, which is a similar feature.</p>
  1027. </item>
  1028. <tag><c>{low_watermark, Size}</c> (TCP/IP sockets)</tag>
  1029. <item>
  1030. <p>If the socket is in a busy state, the socket is
  1031. set in a not busy state when the amount of data
  1032. queued internally by the ERTS socket implementation
  1033. falls below this limit. Defaults to 4 kB.</p>
  1034. <p>Senders that are suspended because of a
  1035. busy message queue or a busy socket are resumed
  1036. when the socket message queue and the socket are not busy.</p>
  1037. <p>For more information, see options <c>high_watermark</c>,
  1038. <c>high_msgq_watermark</c>, and <c>low_msgq_watermark</c>.</p>
  1039. </item>
  1040. <tag><c>{mode, Mode :: binary | list}</c></tag>
  1041. <item>
  1042. <p>
  1043. Received <c>Packet</c> is delivered as defined by <c>Mode</c>.
  1044. </p>
  1045. </item>
  1046. <tag>
  1047. <marker id="option-netns"/>
  1048. <c>{netns, Namespace :: file:filename_all()}</c>
  1049. </tag>
  1050. <item>
  1051. <p>
  1052. Sets a network namespace for the socket. Parameter
  1053. <c>Namespace</c> is a filename defining the namespace, for
  1054. example, <c>"/var/run/netns/example"</c>, typically created by
  1055. command <c>ip netns add example</c>. This option must be used in
  1056. a function call that creates a socket, that is,
  1057. <seealso marker="gen_tcp#connect/3"><c>gen_tcp:connect/3,4</c></seealso>,
  1058. <seealso marker="gen_tcp#listen/2"><c>gen_tcp:listen/2</c></seealso>,
  1059. <seealso marker="gen_udp#open/1"><c>gen_udp:open/1,2</c></seealso>
  1060. or
  1061. <seealso marker="gen_sctp#open/0"><c>gen_sctp:open/0,1,2</c></seealso>,
  1062. and also
  1063. <seealso marker="#getifaddrs/1"><c>getifaddrs/1</c></seealso>.
  1064. </p>
  1065. <p>This option uses the Linux-specific syscall
  1066. <c>setns()</c>, such as in Linux kernel 3.0 or later,
  1067. and therefore only exists when the runtime system
  1068. is compiled for such an operating system.</p>
  1069. <p>The virtual machine also needs elevated privileges, either
  1070. running as superuser or (for Linux) having capability
  1071. <c>CAP_SYS_ADMIN</c> according to the documentation for
  1072. <c>setns(2)</c>.
  1073. However, during testing also <c>CAP_SYS_PTRACE</c>
  1074. and <c>CAP_DAC_READ_SEARCH</c> have proven to be necessary.</p>
  1075. <p><em>Example:</em></p>
  1076. <code>
  1077. setcap cap_sys_admin,cap_sys_ptrace,cap_dac_read_search+epi beam.smp</code>
  1078. <p>Notice that the filesystem containing the virtual machine
  1079. executable (<c>beam.smp</c> in the example) must be local,
  1080. mounted without flag <c>nosetuid</c>,
  1081. support extended attributes, and
  1082. the kernel must support file capabilities.
  1083. All this runs out of the box on at least Ubuntu 12.04 LTS,
  1084. except that SCTP sockets appear to not support
  1085. network namespaces.</p>
  1086. <p><c>Namespace</c> is a filename and is encoded
  1087. and decoded as discussed in module
  1088. <seealso marker="file">file</seealso>, with the
  1089. following exceptions:</p>
  1090. <list type="bulleted">
  1091. <item><p>Emulator flag <c>+fnu</c> is ignored.</p></item>
  1092. <item><p><seealso marker="#getopts/2"><c>getopts/2</c></seealso>
  1093. for this option returns a binary for the filename if the stored
  1094. filename cannot be decoded. This is only to occur if you set the
  1095. option using a binary that cannot be decoded with the emulator's
  1096. filename encoding:
  1097. <seealso marker="file#native_name_encoding/0"><c>file:native_name_encoding/0</c></seealso>.</p></item>
  1098. </list>
  1099. </item>
  1100. <tag><c>{bind_to_device, Ifname :: binary()}</c></tag>
  1101. <item>
  1102. <p>Binds a socket to a specific network interface. This option
  1103. must be used in a function call that creates a socket, that is,
  1104. <seealso marker="gen_tcp#connect/3"><c>gen_tcp:connect/3,4</c></seealso>,
  1105. <seealso marker="gen_tcp#listen/2"><c>gen_tcp:listen/2</c></seealso>,
  1106. <seealso marker="gen_udp#open/1"><c>gen_udp:open/1,2</c></seealso>, or
  1107. <seealso marker="gen_sctp#open/0"><c>gen_sctp:open/0,1,2</c></seealso>.</p>
  1108. <p>Unlike <seealso marker="#getifaddrs/0"><c>getifaddrs/0</c></seealso>, Ifname
  1109. is encoded a binary. In the unlikely case that a system is using
  1110. non-7-bit-ASCII characters in network device names, special care
  1111. has to be taken when encoding this argument.</p>
  1112. <p>This option uses the Linux-specific socket option
  1113. <c>SO_BINDTODEVICE</c>, such as in Linux kernel 2.0.30 or later,
  1114. and therefore only exists when the runtime system
  1115. is compiled for such an operating system.</p>
  1116. <p>Before Linux 3.8, this socket option could be set, but could not retrieved
  1117. with <seealso marker="#getopts/2"><c>getopts/2</c></seealso>. Since Linux 3.8,
  1118. it is readable.</p>
  1119. <p>The virtual machine also needs elevated privileges, either
  1120. running as superuser or (for Linux) having capability
  1121. <c>CAP_NET_RAW</c>.</p>
  1122. <p>The primary use case for this option is to bind sockets into
  1123. <url href="http://www.kernel.org/doc/Documentation/networking/vrf.txt">Linux VRF instances</url>.
  1124. </p>
  1125. </item>
  1126. <tag><c>list</c></tag>
  1127. <item>
  1128. <p>Received <c>Packet</c> is delivered as a list.</p>
  1129. </item>
  1130. <tag><c>binary</c></tag>
  1131. <item>
  1132. <p>Received <c>Packet</c> is delivered as a binary.</p>
  1133. </item>
  1134. <tag><c>{nodelay, Boolean}</c>(TCP/IP sockets)</tag>
  1135. <item>
  1136. <p>If <c>Boolean == true</c>, option <c>TCP_NODELAY</c>
  1137. is turned on for the socket, which means that also small
  1138. amounts of data are sent immediately.</p>
  1139. </item>
  1140. <tag><c>{nopush, Boolean}</c>(TCP/IP sockets)</tag>
  1141. <item>
  1142. <p>This translates to <c>TCP_NOPUSH</c> on BSD and
  1143. to <c>TCP_CORK</c> on Linux.</p>
  1144. <p>If <c>Boolean == true</c>, the corresponding option
  1145. is turned on for the socket, which means that small
  1146. amounts of data are accumulated until a full MSS-worth
  1147. of data is available or this option is turned off.</p>
  1148. <p>Note that while <c>TCP_NOPUSH</c> socket option is available on OSX, its semantics
  1149. is very different (e.g., unsetting it does not cause immediate send
  1150. of accumulated data). Hence, <c>nopush</c> option is intentionally ignored on OSX.</p>
  1151. </item>
  1152. <tag><c>{packet, PacketType}</c>(TCP/IP sockets)</tag>
  1153. <item>
  1154. <p><marker id="packet"/>Defines the type of packets to use for a socket.
  1155. Possible values:</p>
  1156. <taglist>
  1157. <tag><c>raw | 0</c></tag>
  1158. <item>
  1159. <p>No packaging is done.</p>
  1160. </item>
  1161. <tag><c>1 | 2 | 4</c></tag>
  1162. <item>
  1163. <p>Packets consist of a header specifying the number of
  1164. bytes in the packet, followed by that number of bytes.
  1165. The header length can be one, two, or four bytes, and
  1166. containing an unsigned integer in big-endian byte order.
  1167. Each send operation generates the header, and the header
  1168. is stripped off on each receive operation.</p>
  1169. <p>The 4-byte header is limited to 2Gb.</p>
  1170. </item>
  1171. <tag><c>asn1 | cdr | sunrm | fcgi | tpkt | line</c></tag>
  1172. <item>
  1173. <p>These packet types only have effect on receiving.
  1174. When sending a packet, it is the responsibility of
  1175. the application to supply a correct header. On
  1176. receiving, however, one message is sent to
  1177. the controlling process for each complete packet
  1178. received, and, similarly, each call to
  1179. <c>gen_tcp:recv/2,3</c> returns one complete packet.
  1180. The header is <em>not</em> stripped off.</p>
  1181. <p>The meanings of the packet types are as follows:</p>
  1182. <list type="bulleted">
  1183. <item><c>asn1</c> - ASN.1 BER</item>
  1184. <item><c>sunrm</c> - Sun's RPC encoding</item>
  1185. <item><c>cdr</c> - CORBA (GIOP 1.1)</item>
  1186. <item><c>fcgi</c> - Fast CGI</item>
  1187. <item><c>tpkt</c> - TPKT format [RFC1006]</item>
  1188. <item><c>line</c> - Line mode, a packet is a line-terminated
  1189. with newline, lines longer than the receive buffer are
  1190. truncated</item>
  1191. </list>
  1192. </item>
  1193. <tag><c>http | http_bin</c></tag>
  1194. <item>
  1195. <p>The Hypertext Transfer Protocol. The packets
  1196. are returned with the format according to <c>HttpPacket</c>
  1197. described in
  1198. <seealso marker="erts:erlang#decode_packet/3">
  1199. <c>erlang:decode_packet/3</c></seealso> in ERTS.
  1200. A socket in passive
  1201. mode returns <c>{ok, HttpPacket}</c> from <c>gen_tcp:recv</c>
  1202. while an active socket sends messages like
  1203. <c>{http, Socket, HttpPacket}</c>.</p>
  1204. </item>
  1205. <tag><c>httph | httph_bin</c></tag>
  1206. <item>
  1207. <p>These two types are often not needed, as the socket
  1208. automatically switches from <c>http</c>/<c>http_bin</c> to
  1209. <c>httph</c>/<c>httph_bin</c> internally after the first line
  1210. is read. However, there can be occasions when they are
  1211. useful, such as parsing trailers from chunked encoding.</p>
  1212. </item>
  1213. </taglist>
  1214. </item>
  1215. <tag><c>{packet_size, Integer}</c>(TCP/IP sockets)</tag>
  1216. <item>
  1217. <p>Sets the maximum allowed length of the packet body. If
  1218. the packet header indicates that the length of the packet
  1219. is longer than the maximum allowed length, the packet is
  1220. considered invalid. The same occurs if the packet header
  1221. is too large for the socket receive buffer.</p>
  1222. <p>For line-oriented protocols (<c>line</c>, <c>http*</c>),
  1223. option <c>packet_size</c> also guarantees that lines up to the
  1224. indicated length are accepted and not considered invalid
  1225. because of internal buffer limitations.</p>
  1226. </item>
  1227. <tag><c>{line_delimiter, Char}</c>(TCP/IP sockets)</tag>
  1228. <item>
  1229. <p>Sets the line delimiting character for line-oriented protocols
  1230. (<c>line</c>). Defaults to <c>$\n</c>.</p>
  1231. </item>
  1232. <tag><c>{raw, Protocol, OptionNum, ValueBin}</c></tag>
  1233. <item>
  1234. <p>See below.</p>
  1235. </item>
  1236. <tag><c>{read_packets, Integer}</c>(UDP sockets)</tag>
  1237. <item>
  1238. <p>Sets the maximum number of UDP packets to read without
  1239. intervention from the socket when data is available.
  1240. When this many packets have been read and delivered
  1241. to the destination process, new packets are not read
  1242. until a new notification of available data has arrived.
  1243. Defaults to <c>5</c>. If this parameter is set too
  1244. high, the system can become unresponsive because of
  1245. UDP packet flooding.</p>
  1246. </item>
  1247. <tag><c>{recbuf, Size}</c></tag>
  1248. <item>
  1249. <p>The minimum size of the receive buffer to use for
  1250. the socket. You are encouraged to use
  1251. <seealso marker="#getopts/2"><c>getopts/2</c></seealso>
  1252. to retrieve the size set by your operating system.</p>
  1253. <marker id="option-recvtclass"></marker>
  1254. </item>
  1255. <tag><c>{recvtclass, Boolean}</c></tag>
  1256. <item>
  1257. <p>
  1258. If set to <c>true</c> activates returning the received
  1259. <c>TCLASS</c> value on platforms that implements
  1260. the protocol <c>IPPROTO_IPV6</c>
  1261. option <c>IPV6_RECVTCLASS</c> or <c>IPV6_2292RECVTCLASS</c>
  1262. for the socket.
  1263. The value is returned as a <c>{tclass,TCLASS}</c> tuple
  1264. regardless of if the platform returns an <c>IPV6_TCLASS</c>
  1265. or an <c>IPV6_RECVTCLASS</c> CMSG value.
  1266. </p>
  1267. <p>
  1268. For packet oriented sockets that supports receiving
  1269. ancillary data with the payload data
  1270. (<c>gen_udp</c> and <c>gen_sctp</c>),
  1271. the <c>TCLASS</c> value is returned
  1272. in an extended return tuple contained in an
  1273. <seealso marker="inet#type-ancillary_data">
  1274. ancillary data
  1275. </seealso>
  1276. list.
  1277. For stream oriented sockets (<c>gen_tcp</c>)
  1278. the only way to get the <c>TCLASS</c>
  1279. value is if the platform supports the
  1280. <seealso marker="gen_tcp#type-pktoptions_value">
  1281. <c>pktoptions</c>
  1282. </seealso>
  1283. option.
  1284. </p>
  1285. <marker id="option-recvtos"></marker>
  1286. </item>
  1287. <tag><c>{recvtos, Boolean}</c></tag>
  1288. <item>
  1289. <p>
  1290. If set to <c>true</c> activates returning the received
  1291. <c>TOS</c> value on platforms that implements
  1292. the protocol <c>IPPROTO_IP</c> option <c>IP_RECVTOS</c>
  1293. for the socket.
  1294. The value is returned as a <c>{tos,TOS}</c> tuple
  1295. regardless of if the platform returns an <c>IP_TOS</c>
  1296. or an <c>IP_RECVTOS</c> CMSG value.
  1297. </p>
  1298. <p>
  1299. For packet oriented sockets that supports receiving
  1300. ancillary data with the payload data
  1301. (<c>gen_udp</c> and <c>gen_sctp</c>),
  1302. the <c>TOS</c> value is returned
  1303. in an extended return tuple contained in an
  1304. <seealso marker="inet#type-ancillary_data">
  1305. ancillary data
  1306. </seealso>
  1307. list.
  1308. For stream oriented sockets (<c>gen_tcp</c>)
  1309. the only way to get the <c>TOS</c>
  1310. value is if the platform supports the
  1311. <seealso marker="gen_tcp#type-pktoptions_value">
  1312. <c>pktoptions</c>
  1313. </seealso>
  1314. option.
  1315. </p>
  1316. <marker id="option-recvttl"></marker>
  1317. </item>
  1318. <tag><c>{recvttl, Boolean}</c></tag>
  1319. <item>
  1320. <p>
  1321. If set to <c>true</c> activates returning the received
  1322. <c>TTL</c> value on platforms that implements
  1323. the protocol <c>IPPROTO_IP</c> option <c>IP_RECVTTL</c>
  1324. for the socket.
  1325. The value is returned as a <c>{ttl,TTL}</c> tuple
  1326. regardless of if the platform returns an <c>IP_TTL</c>
  1327. or an <c>IP_RECVTTL</c> CMSG value.
  1328. </p>
  1329. <p>
  1330. For packet oriented sockets that supports receiving
  1331. ancillary data with the payload data
  1332. (<c>gen_udp</c> and <c>gen_sctp</c>),
  1333. the <c>TTL</c> value is returned
  1334. in an extended return tuple contained in an
  1335. <seealso marker="inet#type-ancillary_data">
  1336. ancillary data
  1337. </seealso>
  1338. list.
  1339. For stream oriented sockets (<c>gen_tcp</c>)
  1340. the only way to get the <c>TTL</c>
  1341. value is if the platform supports the
  1342. <seealso marker="gen_tcp#type-pktoptions_value">
  1343. <c>pktoptions</c>
  1344. </seealso>
  1345. option.
  1346. </p>
  1347. </item>
  1348. <tag><c>{reuseaddr, Boolean}</c></tag>
  1349. <item>
  1350. <p>Allows or disallows local reuse of port numbers. By
  1351. default, reuse is disallowed.</p>
  1352. </item>
  1353. <tag><c>{send_timeout, Integer}</c></tag>
  1354. <item>
  1355. <p>Only allowed for connection-oriented sockets.</p>
  1356. <p>Specifies a longest time to wait for a send operation to
  1357. be accepted by the underlying TCP stack. When the limit is
  1358. exceeded, the send operation returns
  1359. <c>{error,timeout}</c>. How much of a packet that
  1360. got sent is unknown; the socket is therefore to be closed
  1361. whenever a time-out has occurred (see <c>send_timeout_close</c>
  1362. below). Defaults to <c>infinity</c>.</p>
  1363. </item>
  1364. <tag><c>{send_timeout_close, Boolean}</c></tag>
  1365. <item>
  1366. <p>Only allowed for connection-oriented sockets.</p>
  1367. <p>Used together with <c>send_timeout</c> to specify whether
  1368. the socket is to be automatically closed when the send operation
  1369. returns <c>{error,timeout}</c>. The recommended setting is
  1370. <c>true</c>, which automatically closes the socket.
  1371. Defaults to <c>false</c> because of backward compatibility.</p>
  1372. <marker id="option-sndbuf"></marker>
  1373. </item>
  1374. <tag><c>{show_econnreset, Boolean}</c>(TCP/IP sockets)</tag>
  1375. <item>
  1376. <p>When this option is set to <c>false</c>, which is
  1377. default, an RST received from the TCP peer is treated
  1378. as a normal close (as though an FIN was sent). A caller to
  1379. <seealso marker="gen_tcp#recv/2"><c>gen_tcp:recv/2</c></seealso>
  1380. gets <c>{error, closed}</c>. In active
  1381. mode, the controlling process receives a
  1382. <c>{tcp_closed, Socket}</c> message, indicating that the
  1383. peer has closed the connection.</p>
  1384. <p>Setting this option to <c>true</c> allows you to
  1385. distinguish between a connection that was closed normally,
  1386. and one that was aborted (intentionally or unintentionally)
  1387. by the TCP peer. A call to
  1388. <seealso marker="gen_tcp#recv/2"><c>gen_tcp:recv/2</c></seealso>
  1389. returns <c>{error, econnreset}</c>. In
  1390. active mode, the controlling process receives a
  1391. <c>{tcp_error, Socket, econnreset}</c> message
  1392. before the usual <c>{tcp_closed, Socket}</c>, as is
  1393. the case for any other socket error. Calls to
  1394. <seealso marker="gen_tcp#send/2"><c>gen_tcp:send/2</c></seealso>
  1395. also returns <c>{error, econnreset}</c> when it
  1396. is detected that a TCP peer has sent an RST.</p>
  1397. <p>A connected socket returned from
  1398. <seealso marker="gen_tcp#accept/1"><c>gen_tcp:accept/1</c></seealso>
  1399. inherits the <c>show_econnreset</c> setting from the
  1400. listening socket.</p>
  1401. <marker id="option-show_econnreset"></marker>
  1402. </item>
  1403. <tag><c>{sndbuf, Size}</c></tag>
  1404. <item>
  1405. <p>The minimum size of the send buffer to use for the socket.
  1406. You are encouraged to use
  1407. <seealso marker="#getopts/2"><c>getopts/2</c></seealso>,
  1408. to retrieve the size set by your operating system.</p>
  1409. </item>
  1410. <tag><c>{priority, Integer}</c></tag>
  1411. <item>
  1412. <p>Sets the <c>SO_PRIORITY</c> socket level option on platforms
  1413. where this is implemented. The behavior and allowed range varies
  1414. between different systems.
  1415. The option is ignored on platforms where it
  1416. is not implemented. Use with caution.</p>
  1417. </item>
  1418. <tag><c>{tos, Integer}</c></tag>
  1419. <item>
  1420. <p>Sets <c>IP_TOS IP</c> level options on platforms where this is
  1421. implemented. The behavior and allowed range varies between
  1422. different systems.
  1423. The option is ignored on platforms where it is not
  1424. implemented. Use with caution.</p>
  1425. </item>
  1426. <tag><c>{tclass, Integer}</c></tag>
  1427. <item>
  1428. <p>
  1429. Sets <c>IPV6_TCLASS IP</c> level options on platforms
  1430. where this is implemented. The behavior and allowed range
  1431. varies between different systems.
  1432. The option is ignored on platforms where it is not
  1433. implemented. Use with caution.</p>
  1434. </item>
  1435. </taglist>
  1436. <p>In addition to these options, <em>raw</em>
  1437. option specifications can be used. The raw options are
  1438. specified as a tuple of arity four, beginning with tag
  1439. <c>raw</c>, followed by the protocol level, the option number,
  1440. and the option value specified as a binary. This
  1441. corresponds to the second, third, and fourth arguments to the
  1442. <c>setsockopt</c> call in the C socket API. The option value
  1443. must be coded in the native endianess of the platform and,
  1444. if a structure is required, must follow the structure
  1445. alignment conventions on the specific platform.</p>
  1446. <p>Using raw socket options requires detailed knowledge about
  1447. the current operating system and TCP stack.</p>
  1448. <p><em>Example:</em></p>
  1449. <p>This example concerns the use of raw options. Consider a Linux
  1450. system where you want to set option <c>TCP_LINGER2</c> on
  1451. protocol level <c>IPPROTO_TCP</c> in the stack. You know
  1452. that on this particular system it defaults to 60 (seconds),
  1453. but you want to lower it to 30 for a particular
  1454. socket. Option <c>TCP_LINGER2</c> is not explicitly
  1455. supported by <c>inet</c>, but you know that the protocol level
  1456. translates to number 6, the option number to number 8,
  1457. and the value is to be specified as a 32-bit integer. You can use
  1458. this code line to set the option for the socket named
  1459. <c>Sock</c>:</p>
  1460. <code type="none"><![CDATA[
  1461. inet:setopts(Sock,[{raw,6,8,<<30:32/native>>}]),]]></code>
  1462. <p>As many options are silently discarded by the stack if they
  1463. are specified out of range; it can be a good idea to check that
  1464. a raw option is accepted. The following code places the value
  1465. in variable <c>TcpLinger2:</c></p>
  1466. <code type="none"><![CDATA[
  1467. {ok,[{raw,6,8,<<TcpLinger2:32/native>>}]}=inet:getopts(Sock,[{raw,6,8,4}]),]]></code>
  1468. <p>Code such as these examples is inherently non-portable,
  1469. even different versions of the same OS on the same platform
  1470. can respond differently to this kind of option
  1471. manipulation. Use with care.</p>
  1472. <p>Notice that the default options for TCP/IP sockets can be
  1473. changed with the Kernel configuration parameters mentioned in
  1474. the beginning of this manual page.</p>
  1475. </desc>
  1476. </func>
  1477. <func>
  1478. <name name="sockname" arity="1" since=""/>
  1479. <fsummary>Return the local address and port number for a socket.
  1480. </fsummary>
  1481. <desc>
  1482. <p>Returns the local address and port number for a socket.</p>
  1483. <p>Notice that for SCTP sockets this function returns only
  1484. one of the socket addresses. Function
  1485. <seealso marker="#socknames/1"><c>socknames/1,2</c></seealso>
  1486. returns all.</p>
  1487. </desc>
  1488. </func>
  1489. <func>
  1490. <name name="socknames" arity="1" since="OTP R16B03"/>
  1491. <fsummary>Return all local address/port numbers for a socket.</fsummary>
  1492. <desc>
  1493. <p>Equivalent to
  1494. <seealso marker="#socknames/2"><c>socknames(<anno>Socket</anno>, 0)</c></seealso>.
  1495. </p>
  1496. </desc>
  1497. </func>
  1498. <func>
  1499. <name name="socknames" arity="2" since="OTP R16B03"/>
  1500. <fsummary>Return all local address/port numbers for a socket.</fsummary>
  1501. <desc>
  1502. <p>Returns a list of all local address/port number pairs for a socket
  1503. for the specified association <c><anno>Assoc</anno></c>.</p>
  1504. <p>This function can return multiple addresses for multihomed
  1505. sockets, such as SCTP sockets. For other sockets it
  1506. returns a one-element list.</p>
  1507. <p>Notice that parameter <c><anno>Assoc</anno></c> is by the
  1508. <url href="http://tools.ietf.org/html/draft-ietf-tsvwg-sctpsocket-13">SCTP Sockets API Extensions</url>
  1509. defined to be ignored for one-to-one style sockets.
  1510. For one-to-many style sockets, the special value <c>0</c>
  1511. is defined to mean that the returned addresses must be
  1512. without any particular association.
  1513. How different SCTP implementations interpret this varies somewhat.
  1514. </p>
  1515. </desc>
  1516. </func>
  1517. </funcs>
  1518. <section>
  1519. <marker id="error_codes"></marker>
  1520. <title>POSIX Error Codes</title>
  1521. <list type="bulleted">
  1522. <item><c>e2big</c> - Too long argument list</item>
  1523. <item><c>eacces</c> - Permission denied</item>
  1524. <item><c>eaddrinuse</c> - Address already in use</item>
  1525. <item><c>eaddrnotavail</c> - Cannot assign requested address</item>
  1526. <item><c>eadv</c> - Advertise error</item>
  1527. <item><c>eafnosupport</c> - Address family not supported by
  1528. protocol family</item>
  1529. <item><c>eagain</c> - Resource temporarily unavailable</item>
  1530. <item><c>ealign</c> - EALIGN</item>
  1531. <item><c>ealready</c> - Operation already in progress</item>
  1532. <item><c>ebade</c> - Bad exchange descriptor</item>
  1533. <item><c>ebadf</c> - Bad file number</item>
  1534. <item><c>ebadfd</c> - File descriptor in bad state</item>
  1535. <item><c>ebadmsg</c> - Not a data message</item>
  1536. <item><c>ebadr</c> - Bad request descriptor</item>
  1537. <item><c>ebadrpc</c> - Bad RPC structure</item>
  1538. <item><c>ebadrqc</c> - Bad request code</item>
  1539. <item><c>ebadslt</c> - Invalid slot</item>
  1540. <item><c>ebfont</c> - Bad font file format</item>
  1541. <item><c>ebusy</c> - File busy</item>
  1542. <item><c>echild</c> - No children</item>
  1543. <item><c>echrng</c> - Channel number out of range</item>
  1544. <item><c>ecomm</c> - Communication error on send</item>
  1545. <item><c>econnaborted</c> - Software caused connection abort</item>
  1546. <item><c>econnrefused</c> - Connection refused</item>
  1547. <item><c>econnreset</c> - Connection reset by peer</item>
  1548. <item><c>edeadlk</c> - Resource deadlock avoided</item>
  1549. <item><c>edeadlock</c> - Resource deadlock avoided</item>
  1550. <item><c>edestaddrreq</c> - Destination address required</item>
  1551. <item><c>edirty</c> - Mounting a dirty fs without force</item>
  1552. <item><c>edom</c> - Math argument out of range</item>
  1553. <item><c>edotdot</c> - Cross mount point</item>
  1554. <item><c>edquot</c> - Disk quota exceeded</item>
  1555. <item><c>eduppkg</c> - Duplicate package name</item>
  1556. <item><c>eexist</c> - File already exists</item>
  1557. <item><c>efault</c> - Bad address in system call argument</item>
  1558. <item><c>efbig</c> - File too large</item>
  1559. <item><c>ehostdown</c> - Host is down</item>
  1560. <item><c>ehostunreach</c> - Host is unreachable</item>
  1561. <item><c>eidrm</c> - Identifier removed</item>
  1562. <item><c>einit</c> - Initialization error</item>
  1563. <item><c>einprogress</c> - Operation now in progress</item>
  1564. <item><c>eintr</c> - Interrupted system call</item>
  1565. <item><c>einval</c> - Invalid argument</item>
  1566. <item><c>eio</c> - I/O error</item>
  1567. <item><c>eisconn</c> - Socket is already connected</item>
  1568. <item><c>eisdir</c> - Illegal operation on a directory</item>
  1569. <item><c>eisnam</c> - Is a named file</item>
  1570. <item><c>el2hlt</c> - Level 2 halted</item>
  1571. <item><c>el2nsync</c> - Level 2 not synchronized</item>
  1572. <item><c>el3hlt</c> - Level 3 halted</item>
  1573. <item><c>el3rst</c> - Level 3 reset</item>
  1574. <item><c>elbin</c> - ELBIN</item>
  1575. <item><c>elibacc</c> - Cannot access a needed shared library</item>
  1576. <item><c>elibbad</c> - Accessing a corrupted shared library</item>
  1577. <item><c>elibexec</c> - Cannot exec a shared library directly</item>
  1578. <item><c>elibmax</c> - Attempting to link in more shared
  1579. libraries than system limit</item>
  1580. <item><c>elibscn</c> - <c>.lib</c> section in <c>a.out</c>
  1581. corrupted</item>
  1582. <item><c>elnrng</c> - Link number out of range</item>
  1583. <item><c>eloop</c> - Too many levels of symbolic links</item>
  1584. <item><c>emfile</c> - Too many open files</item>
  1585. <item><c>emlink</c> - Too many links</item>
  1586. <item><c>emsgsize</c> - Message too long</item>
  1587. <item><c>emultihop</c> - Multihop attempted</item>
  1588. <item><c>enametoolong</c> - Filename too long</item>
  1589. <item><c>enavail</c> - Unavailable</item>
  1590. <item><c>enet</c> - ENET</item>
  1591. <item><c>enetdown</c> - Network is down</item>
  1592. <item><c>enetreset</c> - Network dropped connection on reset</item>
  1593. <item><c>enetunreach</c> - Network is unreachable</item>
  1594. <item><c>enfile</c> - File table overflow</item>
  1595. <item><c>enoano</c> - Anode table overflow</item>
  1596. <item><c>enobufs</c> - No buffer space available</item>
  1597. <item><c>enocsi</c> - No CSI structure available</item>
  1598. <item><c>enodata</c> - No data available</item>
  1599. <item><c>enodev</c> - No such device</item>
  1600. <item><c>enoent</c> - No such file or directory</item>
  1601. <item><c>enoexec</c> - Exec format error</item>
  1602. <item><c>enolck</c> - No locks available</item>
  1603. <item><c>enolink</c> - Link has been severed</item>
  1604. <item><c>enomem</c> - Not enough memory</item>
  1605. <item><c>enomsg</c> - No message of desired type</item>
  1606. <item><c>enonet</c> - Machine is not on the network</item>
  1607. <item><c>enopkg</c> - Package not installed</item>
  1608. <item><c>enoprotoopt</c> - Bad protocol option</item>
  1609. <item><c>enospc</c> - No space left on device</item>
  1610. <item><c>enosr</c> - Out of stream resources or not a stream device</item>
  1611. <item><c>enosym</c> - Unresolved symbol name</item>
  1612. <item><c>enosys</c> - Function not implemented</item>
  1613. <item><c>enotblk</c> - Block device required</item>
  1614. <item><c>enotconn</c> - Socket is not connected</item>
  1615. <item><c>enotdir</c> - Not a directory</item>
  1616. <item><c>enotempty</c> - Directory not empty</item>
  1617. <item><c>enotnam</c> - Not a named file</item>
  1618. <item><c>enotsock</c> - Socket operation on non-socket</item>
  1619. <item><c>enotsup</c> - Operation not supported</item>
  1620. <item><c>enotty</c> - Inappropriate device for <c>ioctl</c></item>
  1621. <item><c>enotuniq</c> - Name not unique on network</item>
  1622. <item><c>enxio</c> - No such device or address</item>
  1623. <item><c>eopnotsupp</c> - Operation not supported on socket</item>
  1624. <item><c>eperm</c> - Not owner</item>
  1625. <item><c>epfnosupport</c> - Protocol family not supported</item>
  1626. <item><c>epipe</c> - Broken pipe</item>
  1627. <item><c>eproclim</c> - Too many processes</item>
  1628. <item><c>eprocunavail</c> - Bad procedure for program</item>
  1629. <item><c>eprogmismatch</c> - Wrong program version</item>
  1630. <item><c>eprogunavail</c> - RPC program unavailable</item>
  1631. <item><c>eproto</c> - Protocol error</item>
  1632. <item><c>eprotonosupport</c> - Protocol not supported</item>
  1633. <item><c>eprototype</c> - Wrong protocol type for socket</item>
  1634. <item><c>erange</c> - Math result unrepresentable</item>
  1635. <item><c>erefused</c> - EREFUSED</item>
  1636. <item><c>eremchg</c> - Remote address changed</item>
  1637. <item><c>eremdev</c> - Remote device</item>
  1638. <item><c>eremote</c> - Pathname hit remote filesystem</item>
  1639. <item><c>eremoteio</c> - Remote I/O error</item>
  1640. <item><c>eremoterelease</c> - EREMOTERELEASE</item>
  1641. <item><c>erofs</c> - Read-only filesystem</item>
  1642. <item><c>erpcmismatch</c> - Wrong RPC version</item>
  1643. <item><c>erremote</c> - Object is remote</item>
  1644. <item><c>eshutdown</c> - Cannot send after socket shutdown</item>
  1645. <item><c>esocktnosupport</c> - Socket type not supported</item>
  1646. <item><c>espipe</c> - Invalid seek</item>
  1647. <item><c>esrch</c> - No such process</item>
  1648. <item><c>esrmnt</c> - Srmount error</item>
  1649. <item><c>estale</c> - Stale remote file handle</item>
  1650. <item><c>esuccess</c> - Error 0</item>
  1651. <item><c>etime</c> - Timer expired</item>
  1652. <item><c>etimedout</c> - Connection timed out</item>
  1653. <item><c>etoomanyrefs</c> - Too many references</item>
  1654. <item><c>etxtbsy</c> - Text file or pseudo-device busy</item>
  1655. <item><c>euclean</c> - Structure needs cleaning</item>
  1656. <item><c>eunatch</c> - Protocol driver not attached</item>
  1657. <item><c>eusers</c> - Too many users</item>
  1658. <item><c>eversion</c> - Version mismatch</item>
  1659. <item><c>ewouldblock</c> - Operation would block</item>
  1660. <item><c>exdev</c> - Cross-domain link</item>
  1661. <item><c>exfull</c> - Message tables full</item>
  1662. <item><c>nxdomain</c> - Hostname or domain name cannot be found</item>
  1663. </list>
  1664. </section>
  1665. </erlref>