<?xml version="1.0" encoding="utf-8" ?>
<!DOCTYPE chapter SYSTEM "chapter.dtd">

<chapter>
  <header>
    <copyright>
      <year>2018</year><year>2021</year>
      <holder>Ericsson AB. All Rights Reserved.</holder>
    </copyright>
    <legalnotice>
      Licensed under the Apache License, Version 2.0 (the "License");
      you may not use this file except in compliance with the License.
      You may obtain a copy of the License at
 
          http://www.apache.org/licenses/LICENSE-2.0

      Unless required by applicable law or agreed to in writing, software
      distributed under the License is distributed on an "AS IS" BASIS,
      WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
      See the License for the specific language governing permissions and
      limitations under the License.

    </legalnotice>

    <title>Socket Usage</title>
    <prepared>Micael Karlberg</prepared>
    <docno></docno>
    <date>2018-07-17</date>
    <rev>PA1</rev>
    <file>socket_usage.xml</file>
  </header>

  <section>
    <title>Introduction</title>
    <p>The socket interface (module) is basically a "thin" layer on top of
    the OS socket interface. It is assumed that, unless you have special needs,
    gen_[tcp|udp|sctp] should be sufficent (when they become available). </p>
    <p>Note that just because we have a documented and described option,
    it does <em>not</em> mean that the OS supports it. So its recommended
    that the user reads the platform specific documentation for the
    option used. </p>
    <section>
      <title>Asynchronous calls</title>
      <p>Some functions allow for an <i>asynchronous</i> call
      (<seeerl marker="socket#accept-nowait"><c>accept/2</c></seeerl>,
      <seeerl marker="socket#connect-nowait"><c>connect/3</c></seeerl>,
      <seeerl marker="socket#recv-nowait"><c>recv/3,4</c></seeerl>,
      <seeerl marker="socket#recvfrom-nowait"><c>recvfrom/3,4</c></seeerl>,
      <seeerl marker="socket#recvmsg-nowait"><c>recvmsg/2,3,5</c></seeerl>,
      <seeerl marker="socket#send-nowait"><c>send/3,4</c></seeerl>,
      <seeerl marker="socket#sendmsg-nowait"><c>sendmsg/3,4</c></seeerl> and
      <seeerl marker="socket#sendto-nowait"><c>sendto/4,5</c></seeerl>).
      This is achieved by setting the <c>Timeout</c> argument to
      <c>nowait</c>. For instance, if calling the
      <seeerl marker="socket#recv-nowait"><c>recv/3</c></seeerl>
      function with Timeout set to <c>nowait</c> (i.e. 
      <c>recv(Sock, 0, nowait)</c>)
      when there is actually nothing to read, it will return with
      <c>{select, </c>
      <seetype marker="socket#select_info"><c>SelectInfo</c></seetype><c>}</c>
      (<c>SelectInfo</c> contains the
      <seetype marker="socket#select_handle"><c>SelectHandle</c></seetype>).
      When data eventually arrives a 'select message'
      will be sent to the caller:</p>
      <taglist>
	<!-- NOTE THAT THE EMPTY TAG IS INTENTIONAL -->
	<tag></tag>
	<item><c>{'$socket', socket(), select, SelectHandle}</c></item>
      </taglist>
      <p>The caller can then make another
      call to the recv function and now expect data.</p>
      <p>Note that all other users are <em>locked out</em> until the
      'current user' has called the function (recv in this case). So either
      immediately call the function or
      <seemfa marker="socket#cancel/2"><c>cancel</c></seemfa>. </p>
      <p>The user must also be prepared to receive an abort message: </p>
      <taglist>
	<!-- NOTE THAT THE EMPTY TAG IS INTENTIONAL -->
	<tag></tag>
	<item><c>{'$socket', socket(), abort, Info}</c></item>
      </taglist>
      <p>If the operation is aborted
      for whatever reason (e.g. if the socket is closed "by someone else").
      The <c>Info</c> part contains the abort reason (in this case that
      the socket has been closed <c>Info = {SelectHandle, closed}</c>). </p>

      <p>The general form of the 'socket' message is: </p>
      <taglist>
	<!-- NOTE THAT THE EMPTY TAG IS INTENTIONAL -->
	<tag></tag>
	<item><c>{'$socket', Sock :: socket(), Tag :: atom(), Info :: term()}</c></item>
      </taglist>
      <p>Where the format of <c>Info</c> is a function of <c>Tag</c>:</p>
      <table>
	<row>
	  <cell><em>Tag</em></cell>
	  <cell><em>Info value type</em></cell>
	</row>
	<row>
	  <cell>select</cell>
	  <cell>select_handle()</cell>
	</row>
	<row>
	  <cell>abort</cell>
	  <cell>{select_handle(), Reason :: term()}</cell>
	</row>
	<tcaption>socket message info value type</tcaption>
      </table>
      <p>The <c>select_handle()</c> is the same as was returned in the
      <seetype marker="socket#select_info"><c>SelectInfo</c></seetype>. </p>
    </section>
  </section>

  <section>
    <title>Socket Registry</title>
    <p>The <em>socket registry</em> is how we keep track of sockets.
    There are two functions that can be used for interaction:
    <seemfa marker="socket#number_of/0"><c>socket:number_of/0</c></seemfa>
    and
    <seemfa marker="socket#which_sockets/1"><c>socket:which_sockets/1</c></seemfa>.
    </p>
    <p>In systems which create and delete <em>many</em> sockets
    dynamically, it (the socket registry) could become a bottleneck.
    For such systems, there are a couple of
    ways to control the use of the socket registry. </p>

    <p>Firstly, its possible to effect the global default value when
    building OTP from source with the two configure options:</p>
    <code type="none">--enable-esock-socket-registry (default) | --disable-esock-socket-registry</code>

    <p>Second, its possible to effect the global default value by
    setting the environment variable <c>ESOCK_USE_SOCKET_REGISTRY</c>
    (boolean) before starting the erlang. </p>

    <p>Third, its possible to alter the global default value in runtime
    by calling the function
    <seemfa marker="socket#use_registry/1"><c>use_registry/1</c></seemfa>.</p>

    <p>And finally, its possible to override the global default when creating
    a socket (with <seemfa marker="socket#open/2"><c>open/2</c></seemfa> and
    <seemfa marker="socket#open/4"><c>open/4</c></seemfa>) by providing
    the attribute <c>use_registry</c> (boolean) in the their <c>Opts</c>
    argument (which effects <em>that</em> specific
    socket).</p>

  </section>

  <section>
    <marker id="socket_options"></marker>
    <title>Socket Options</title>

    <p>Options for level <c>otp</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>assoc_id</cell>
	<cell>integer()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell>type = seqpacket, protocol = sctp, is an association</cell>
      </row>
      <row>
	<cell>debug</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>iow</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>controlling_process</cell>
	<cell>pid()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>rcvbuf</cell>
	<cell>default | pos_integer() | {pos_integer(), pos_ineteger()}</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>'default' only valid for set.
	The tuple form is only valid for type 'stream' and protocol 'tcp'.</cell>
      </row>
      <row>
	<cell>rcvctrlbuf</cell>
	<cell>default | pos_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>default only valid for set</cell>
      </row>
      <row>
	<cell>sndctrlbuf</cell>
	<cell>default | pos_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>default only valid for set</cell>
      </row>
      <row>
	<cell>fd</cell>
	<cell>integer()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>use_registry</cell>
	<cell>boolean()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell>the value is set when the socket is created, by a call to
	<seemfa marker="socket#open/2"><c>open/2</c></seemfa> or
	<seemfa marker="socket#open/4"><c>open/4</c></seemfa>.</cell>
      </row>
      <tcaption>option levels</tcaption>
    </table>
    
    <p>Options for level <c>socket</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>acceptconn</cell>
	<cell>boolean()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>bindtodevice</cell>
	<cell>string()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>Before Linux 3.8, this socket option could be set, but not get.
	Only works for some socket types (e.g. <c>inet</c>).
	If empty value is set, the binding is removed.</cell>
      </row>
      <row>
	<cell>broadcast</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram</cell>
      </row>
      <row>
	<cell>debug</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>may require admin capability</cell>
      </row>
      <row>
	<cell>domain</cell>
	<cell>domain()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell><em>Not</em> on FreeBSD (for instance)</cell>
      </row>
      <row>
	<cell>dontroute</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>keepalive</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>linger</cell>
	<cell>abort | linger()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>oobinline</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>peek_off</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>domain = local (unix).
	Currently disabled due to a possible infinite loop when
	calling recv([peek]) the second time.
	</cell>
      </row>
      <row>
	<cell>priority</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>protocol</cell>
	<cell>protocol()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell><em>Not</em> on (some) Darwin (for instance)</cell>
      </row>
      <row>
	<cell>rcvbuf</cell>
	<cell>non_neg_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>rcvlowat</cell>
	<cell>non_neg_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>rcvtimeo</cell>
	<cell>timeval()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>
	  This option is not normally supported (see why below).
	  OTP has to be explicitly built with the
	  <c>--enable-esock-rcvsndtime</c> configure option for this
	  to be available.
	  Since our implementation is <em>nonblocking</em>,
	  its unknown if and how this option works, or even if
	  it may cause malfunctions.
	  Therefor, we do not recommend setting this option.
	  Instead, use the <c>Timeout</c> argument to, for instance,
	  the
	  <seemfa marker="socket#recv/3"><c>recv/3</c></seemfa>
	  function.
	</cell>
      </row>
      <row>
	<cell>reuseaddr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>reuseport</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>domain = inet | inet6</cell>
      </row>
      <row>
	<cell>sndbuf</cell>
	<cell>non_neg_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>sndlowat</cell>
	<cell>non_neg_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>not changeable on Linux</cell>
      </row>
      <row>
	<cell>sndtimeo</cell>
	<cell>timeval()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>
	  This option is not normally supported (see why below).
	  OTP has to be explicitly built with the
	  <c>--enable-esock-rcvsndtime</c> configure option for this
	  to be available.
	  Since our implementation is <em>nonblocking</em>,
	  its unknown if and how this option works, or even if
	  it may cause malfunctions.
	  Therefor, we do not recommend setting this option.
	  Instead, use the <c>Timeout</c> argument to, for instance,
	  the
	  <seemfa marker="socket#send/3"><c>send/3</c></seemfa>
	  function.
	</cell>
      </row>
      <row>
	<cell>timestamp</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>type</cell>
	<cell>type()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <tcaption>socket options</tcaption>
    </table>
    
    <p>Options for level <c>ip</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>add_membership</cell>
	<cell>ip_mreq()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>add_source_membership</cell>
	<cell>ip_mreq_source()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>block_source</cell>
	<cell>ip_mreq_source()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>drop_membership</cell>
	<cell>ip_mreq()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>drop_source_membership</cell>
	<cell>ip_mreq_source()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>freebind</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>hdrincl</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = raw</cell>
      </row>
      <row>
	<cell>minttl</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = raw</cell>
      </row>
      <row>
	<cell>msfilter</cell>
	<cell>null | ip_msfilter()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>mtu</cell>
	<cell>integer()</cell>
	<cell>no</cell>
	<cell>yes</cell>
	<cell>type = raw</cell>
      </row>
      <row>
	<cell>mtu_discover</cell>
	<cell>ip_pmtudisc()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>multicast_all</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>multicast_if</cell>
	<cell>any | ip4_address()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>multicast_loop</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>multicast_ttl</cell>
	<cell>uint8()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>nodefrag</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = raw</cell>
      </row>
      <row>
	<cell>pktinfo</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram</cell>
      </row>
      <row>
	<cell>recvdstaddr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram</cell>
      </row>
      <row>
	<cell>recverr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>recvif</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw</cell>
      </row>
      <row>
	<cell>recvopts</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type =/= stream</cell>
      </row>
      <row>
	<cell>recvorigdstaddr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>recvttl</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type =/= stream</cell>
      </row>
      <row>
	<cell>retopts</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type =/= stream</cell>
      </row>
      <row>
	<cell>router_alert</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = raw</cell>
      </row>
      <row>
	<cell>sendsrcaddr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>tos</cell>
	<cell>ip_tos()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>some high-priority levels may require superuser capability</cell>
      </row>
      <row>
	<cell>transparent</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>requires admin capability</cell>
      </row>
      <row>
	<cell>ttl</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>unblock_source</cell>
	<cell>ip_mreq_source()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <tcaption>ip options</tcaption>
    </table>
    
    <p>Options for level <c>ipv6</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>addrform</cell>
	<cell>inet</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>allowed only for IPv6 sockets that are connected and bound to a
	v4-mapped-on-v6 address</cell>
      </row>
      <row>
	<cell>add_membership</cell>
	<cell>ipv6_mreq()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>authhdr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw, obsolete?</cell>
      </row>
      <row>
	<cell>drop_membership</cell>
	<cell>ipv6_mreq()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>dstopts</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw, requires superuser privileges to update</cell>
      </row>
      <row>
	<cell>flowinfo</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw, requires superuser privileges to update</cell>
      </row>
      <row>
	<cell>hoplimit</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw.
	On some platforms (e.g. FreeBSD) is used to set in order to
	get <c>hoplimit</c> as a control message heeader.
	On others (e.g. Linux), <c>recvhoplimit</c> is set in order to get
	<c>hoplimit</c>. </cell>
      </row>
      <row>
	<cell>hopopts</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw, requires superuser privileges to update</cell>
      </row>
      <row>
	<cell>mtu</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>Get: Only after the socket has been connected</cell>
      </row>
      <row>
	<cell>mtu_discover</cell>
	<cell>ipv6_pmtudisc()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>multicast_hops</cell>
	<cell>default | uint8()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>multicast_if</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw</cell>
      </row>
      <row>
	<cell>multicast_loop</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>recverr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>recvhoplimit</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw.
	On some platforms (e.g. Linux), <c>recvhoplimit</c>
	is set in order to get <c>hoplimit</c></cell>
      </row>
      <row>
	<cell>recvpktinfo | pktinfo</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw.
	On some platforms (e.g. FreeBSD) is used to set in order to
	get <c>hoplimit</c> as a control message heeader.
	On others (e.g. Linux), <c>recvhoplimit</c> is set in order to get
	<c>hoplimit</c>. </cell>
      </row>
      <row>
	<cell>recvtclass</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw.
	On some platforms is used to set (=true) in order to
	get the <c>tclass</c> control message heeader.
	On others, <c>tclass</c> is set in order to get
	<c>tclass</c> control message heeader. </cell>
      </row>
      <row>
	<cell>router_alert</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = raw</cell>
      </row>
      <row>
	<cell>rthdr</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>type = dgram | raw, requires superuser privileges to update</cell>
      </row>
      <row>
	<cell>tclass</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>Set the traffic class associated with outgoing packets.
	RFC3542. </cell>
      </row>
      <row>
	<cell>unicast_hops</cell>
	<cell>default | uint8()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>v6only</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <tcaption>ipv6 options</tcaption>
    </table>
    
    <p>Options for level <c>tcp</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>congestion</cell>
	<cell>string()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>maxseg</cell>
	<cell>integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>Set not allowed on all platforms.</cell>
      </row>
      <row>
	<cell>nodelay</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <tcaption>tcp options</tcaption>
    </table>
    
    <p>Options for level <c>udp</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>cork</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <tcaption>udp options</tcaption>
    </table>
    
    <p>Options for level <c>sctp</c>: </p>
    <table>
      <row>
	<cell><em>Option Name</em></cell>
	<cell><em>Value Type</em></cell>
	<cell><em>Set</em></cell>
	<cell><em>Get</em></cell>
	<cell><em>Other Requirements and comments</em></cell>
      </row>
      <row>
	<cell>associnfo</cell>
	<cell>sctp_assocparams()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>autoclose</cell>
	<cell>non_neg_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>disable_fragments</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>events</cell>
	<cell>sctp_event_subscribe()</cell>
	<cell>yes</cell>
	<cell>no</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>initmsg</cell>
	<cell>sctp_initmsg()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>maxseg</cell>
	<cell>non_neg_integer()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>nodelay</cell>
	<cell>boolean()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <row>
	<cell>rtoinfo</cell>
	<cell>sctp_rtoinfo()</cell>
	<cell>yes</cell>
	<cell>yes</cell>
	<cell>none</cell>
      </row>
      <tcaption>sctp options</tcaption>
    </table>
    
  </section>
</chapter>

