| <!-- |
| Documentation/_templates/layout.html |
| |
| Licensed to the Apache Software Foundation (ASF) under one or more |
| contributor license agreements. See the NOTICE file distributed with |
| this work for additional information regarding copyright ownership. The |
| ASF licenses this file to you 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. |
| --> |
| |
| |
| |
| <!DOCTYPE html> |
| <html class="writer-html5" lang="en" > |
| <head> |
| <meta charset="utf-8" /> |
| |
| <meta name="viewport" content="width=device-width, initial-scale=1.0" /> |
| |
| <title>Network Interfaces — NuttX latest documentation</title> |
| |
| |
| |
| <link rel="stylesheet" href="../../_static/css/theme.css" type="text/css" /> |
| <link rel="stylesheet" href="../../_static/pygments.css" type="text/css" /> |
| <link rel="stylesheet" href="../../_static/tabs.css" type="text/css" /> |
| <link rel="stylesheet" href="../../_static/custom.css" type="text/css" /> |
| |
| |
| |
| <link rel="shortcut icon" href="../../_static/favicon.ico"/> |
| |
| |
| |
| |
| |
| |
| |
| |
| <!--[if lt IE 9]> |
| <script src="../../_static/js/html5shiv.min.js"></script> |
| <![endif]--> |
| |
| |
| <script type="text/javascript" id="documentation_options" data-url_root="../../" src="../../_static/documentation_options.js"></script> |
| <script src="../../_static/jquery.js"></script> |
| <script src="../../_static/underscore.js"></script> |
| <script src="../../_static/doctools.js"></script> |
| |
| <script type="text/javascript" src="../../_static/js/theme.js"></script> |
| |
| |
| <link rel="index" title="Index" href="../../genindex.html" /> |
| <link rel="search" title="Search" href="../../search.html" /> |
| <link rel="next" title="Shared Memory Interfaces" href="12_shared_memory.html" /> |
| <link rel="prev" title="File System Interfaces" href="10_filesystem.html" /> |
| </head> |
| |
| <body class="wy-body-for-nav"> |
| |
| |
| <div class="wy-grid-for-nav"> |
| |
| <nav data-toggle="wy-nav-shift" class="wy-nav-side"> |
| <div class="wy-side-scroll"> |
| <div class="wy-side-nav-search" > |
| |
| |
| <a href="../../index.html" class="icon icon-home"> NuttX |
| |
| |
| |
| |
| <img src="../../_static/NuttX.png" class="logo" alt="Logo"/> |
| |
| </a> |
| |
| <!-- this version selector is quite ugly, should be probably replaced by something |
| more modern --> |
| |
| <div class="version-selector"> |
| <select onchange="javascript:location.href = this.value;"> |
| |
| <option value="../../../latest" selected="selected">latest</option> |
| |
| <option value="../../../10.0.0" >10.0.0</option> |
| |
| <option value="../../../10.0.1" >10.0.1</option> |
| |
| <option value="../../../10.1.0" >10.1.0</option> |
| |
| <option value="../../../10.2.0" >10.2.0</option> |
| |
| <option value="../../../10.3.0" >10.3.0</option> |
| |
| <option value="../../../11.0.0" >11.0.0</option> |
| |
| <option value="../../../12.0.0" >12.0.0</option> |
| |
| <option value="../../../12.1.0" >12.1.0</option> |
| |
| <option value="../../../12.2.0" >12.2.0</option> |
| |
| <option value="../../../12.2.1" >12.2.1</option> |
| |
| <option value="../../../12.3.0" >12.3.0</option> |
| |
| <option value="../../../12.4.0" >12.4.0</option> |
| |
| <option value="../../../12.5.0" >12.5.0</option> |
| |
| <option value="../../../12.5.1" >12.5.1</option> |
| |
| <option value="../../../12.6.0" >12.6.0</option> |
| |
| <option value="../../../12.7.0" >12.7.0</option> |
| |
| <option value="../../../12.8.0" >12.8.0</option> |
| |
| <option value="../../../12.9.0" >12.9.0</option> |
| |
| <option value="../../../12.10.0" >12.10.0</option> |
| |
| <option value="../../../12.11.0" >12.11.0</option> |
| |
| </select> |
| </div> |
| |
| |
| <div role="search"> |
| <form id="rtd-search-form" class="wy-form" action="../../search.html" method="get"> |
| <input type="text" name="q" placeholder="Search docs" /> |
| <input type="hidden" name="check_keywords" value="yes" /> |
| <input type="hidden" name="area" value="default" /> |
| </form> |
| </div> |
| |
| </div> |
| |
| |
| <div class="wy-menu wy-menu-vertical" data-spy="affix" role="navigation" aria-label="main navigation"> |
| |
| |
| |
| |
| |
| |
| <p class="caption"><span class="caption-text">Table of Contents</span></p> |
| <ul class="current"> |
| <li class="toctree-l1"><a class="reference internal" href="../../index.html">Home</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../introduction/index.html">Introduction</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../quickstart/index.html">Getting Started</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../contributing/index.html">Contributing</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../introduction/inviolables.html">The Inviolable Principles of NuttX</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../platforms/index.html">Supported Platforms</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../components/index.html">OS Components</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../applications/index.html">Applications</a></li> |
| <li class="toctree-l1 current"><a class="reference internal" href="../index.html">API Reference</a><ul class="current"> |
| <li class="toctree-l2 current"><a class="reference internal" href="index.html">Userspace API</a><ul class="current"> |
| <li class="toctree-l3"><a class="reference internal" href="01_task_control.html">Task Control Interfaces</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="02_task_scheduling.html">Task Scheduling Interfaces</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="03_task_control.html">Task Control Interfaces</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="04_message_queue.html">Named Message Queue Interfaces</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="05_counting_semaphore.html">Counting Semaphore Interfaces</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="06_clocks_timers.html">Clocks and Timers</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="07_signals.html">Signal Interfaces</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="08_pthread.html">Pthread Interfaces</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="09_env_vars.html">Environment Variables</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="10_filesystem.html">File System Interfaces</a></li> |
| <li class="toctree-l3 current"><a class="current reference internal" href="#">Network Interfaces</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="12_shared_memory.html">Shared Memory Interfaces</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="13_boardctl.html">Board IOCTL</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="13_logging.html">Logging</a></li> |
| <li class="toctree-l3"><a class="reference internal" href="structures.html">OS Data Structures</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l2"><a class="reference internal" href="../os/index.html">Architecture APIs</a></li> |
| </ul> |
| </li> |
| <li class="toctree-l1"><a class="reference internal" href="../../faq/index.html">FAQ</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../guides/index.html">Guides</a></li> |
| <li class="toctree-l1"><a class="reference internal" href="../../glossary.html">Glossary</a></li> |
| </ul> |
| |
| |
| |
| </div> |
| |
| </div> |
| </nav> |
| |
| <section data-toggle="wy-nav-shift" class="wy-nav-content-wrap"> |
| |
| |
| <nav class="wy-nav-top" aria-label="top navigation"> |
| |
| <i data-toggle="wy-nav-top" class="fa fa-bars"></i> |
| <a href="../../index.html">NuttX</a> |
| |
| </nav> |
| |
| |
| <div class="wy-nav-content"> |
| |
| <div class="rst-content"> |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| |
| <div role="navigation" aria-label="breadcrumbs navigation"> |
| |
| <ul class="wy-breadcrumbs"> |
| |
| <li><a href="../../index.html" class="icon icon-home"></a> »</li> |
| |
| <li><a href="../index.html">API Reference</a> »</li> |
| |
| <li><a href="index.html">Userspace API</a> »</li> |
| |
| <li>Network Interfaces</li> |
| |
| |
| <li class="wy-breadcrumbs-aside"> |
| |
| |
| <a href="../../_sources/reference/user/11_network.rst.txt" rel="nofollow"> View page source</a> |
| |
| |
| </li> |
| |
| </ul> |
| |
| |
| <hr/> |
| </div> |
| <div role="main" class="document" itemscope="itemscope" itemtype="http://schema.org/Article"> |
| <div itemprop="articleBody"> |
| |
| <div class="section" id="network-interfaces"> |
| <h1>Network Interfaces<a class="headerlink" href="#network-interfaces" title="Permalink to this headline">¶</a></h1> |
| <p>NuttX supports a BSD-compatible socket interface layer. These socket |
| interface can be enabled by settings in the architecture configuration |
| file. Those socket APIs are discussed in |
| the following paragraphs.</p> |
| <blockquote> |
| <div><ul class="simple"> |
| <li><p><a class="reference internal" href="#c.socket" title="socket"><code class="xref c c-func docutils literal notranslate"><span class="pre">socket()</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.bind" title="bind"><code class="xref c c-func docutils literal notranslate"><span class="pre">bind()</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.connect" title="connect"><code class="xref c c-func docutils literal notranslate"><span class="pre">connect()</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.listen" title="listen"><code class="xref c c-func docutils literal notranslate"><span class="pre">listen()</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.accept" title="accept"><code class="xref c c-func docutils literal notranslate"><span class="pre">accept()</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.send" title="send"><code class="xref c c-func docutils literal notranslate"><span class="pre">send()</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.sendto" title="sendto"><code class="xref c c-func docutils literal notranslate"><span class="pre">sendto()</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.recv" title="recv"><code class="xref c c-func docutils literal notranslate"><span class="pre">recv()</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.recvfrom" title="recvfrom"><code class="xref c c-func docutils literal notranslate"><span class="pre">recvfrom()</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.setsockopt" title="setsockopt"><code class="xref c c-func docutils literal notranslate"><span class="pre">setsockopt()</span></code></a></p></li> |
| <li><p><a class="reference internal" href="#c.getsockopt" title="getsockopt"><code class="xref c c-func docutils literal notranslate"><span class="pre">getsockopt()</span></code></a></p></li> |
| </ul> |
| </div></blockquote> |
| <dl class="c function"> |
| <dt id="c.socket"> |
| <span class="pre">int</span> <code class="sig-name descname"><span class="pre">socket</span></code><span class="sig-paren">(</span><span class="pre">int</span> <em><span class="pre">domain</span></em>, <span class="pre">int</span> <em><span class="pre">type</span></em>, <span class="pre">int</span> <em><span class="pre">protocol</span></em><span class="sig-paren">)</span><span class="pre">;</span><a class="headerlink" href="#c.socket" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Creates an endpoint for communication and |
| returns a descriptor.</p> |
| <dl class="field-list simple"> |
| <dt class="field-odd">Parameters</dt> |
| <dd class="field-odd"><ul class="simple"> |
| <li><p><strong>domain</strong> – (see sys/socket.h)</p></li> |
| <li><p><strong>type</strong> – (see sys/socket.h)</p></li> |
| <li><p><strong>protocol</strong> – (see sys/socket.h)</p></li> |
| </ul> |
| </dd> |
| <dt class="field-even">Returns</dt> |
| <dd class="field-even"><p><p>0 on success; -1 on error with |
| <code class="docutils literal notranslate"><span class="pre">errno</span></code> set appropriately:</p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EACCES</span></code>. Permission to create a socket of the specified type |
| and/or protocol is denied.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EAFNOSUPPORT</span></code>. The implementation does not support the specified |
| address family.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EINVAL</span></code>. Unknown protocol, or protocol family not available.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EMFILE</span></code>. Process file table overflow.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENFILE</span></code> The system limit on the total number of open files has |
| been reached.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENOBUFS</span></code> or <code class="docutils literal notranslate"><span class="pre">ENOMEM</span></code>. Insufficient memory is available. The |
| socket cannot be created until sufficient resources are freed.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EPROTONOSUPPORT</span></code>. The protocol type or the specified protocol is |
| not supported within this domain.</p></li> |
| </ul> |
| </p> |
| </dd> |
| </dl> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.bind"> |
| <span class="pre">int</span> <code class="sig-name descname"><span class="pre">bind</span></code><span class="sig-paren">(</span><span class="pre">int</span> <em><span class="pre">sockfd</span></em>, <em class="property"><span class="pre">const</span></em> <em class="property"><span class="pre">struct</span></em> <span class="pre">sockaddr</span> <span class="pre">*</span><em><span class="pre">addr</span></em>, <span class="pre">socklen_t</span> <em><span class="pre">addrlen</span></em><span class="sig-paren">)</span><a class="headerlink" href="#c.bind" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>Gives the socket sockfd the local address |
| <code class="docutils literal notranslate"><span class="pre">addr</span></code>. <code class="docutils literal notranslate"><span class="pre">addr</span></code> is <code class="docutils literal notranslate"><span class="pre">addrlen</span></code> bytes long. Traditionally, this is |
| called “assigning a name to a socket.” When a socket is created with |
| <code class="docutils literal notranslate"><span class="pre">socket()</span></code>, it exists in a name space (address family) but has no name |
| assigned.</p> |
| <dl class="field-list simple"> |
| <dt class="field-odd">Parameters</dt> |
| <dd class="field-odd"><ul class="simple"> |
| <li><p><strong>sockfd</strong> – Socket descriptor from socket.</p></li> |
| <li><p><strong>addr</strong> – Socket local address.</p></li> |
| <li><p><strong>addrlen</strong> – Length of <code class="docutils literal notranslate"><span class="pre">addr</span></code>.</p></li> |
| </ul> |
| </dd> |
| <dt class="field-even">Returns</dt> |
| <dd class="field-even"><p>0 on success; -1 on error with <code class="docutils literal notranslate"><span class="pre">errno</span></code> set appropriately: |
| - <code class="docutils literal notranslate"><span class="pre">EACCES</span></code> The address is protected, and the user is not the |
| superuser. |
| - <code class="docutils literal notranslate"><span class="pre">EADDRINUSE</span></code> The given address is already in use. |
| - <code class="docutils literal notranslate"><span class="pre">EBADF</span></code> <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> is not a valid descriptor. |
| - <code class="docutils literal notranslate"><span class="pre">EINVAL</span></code> The socket is already bound to an address. |
| - <code class="docutils literal notranslate"><span class="pre">ENOTSOCK</span></code> <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> is a descriptor for a file, not a socket.</p> |
| </dd> |
| </dl> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.connect"> |
| <span class="pre">int</span> <code class="sig-name descname"><span class="pre">connect</span></code><span class="sig-paren">(</span><span class="pre">int</span> <em><span class="pre">sockfd</span></em>, <em class="property"><span class="pre">const</span></em> <em class="property"><span class="pre">struct</span></em> <span class="pre">sockaddr</span> <span class="pre">*</span><em><span class="pre">addr</span></em>, <span class="pre">socklen_t</span> <em><span class="pre">addrlen</span></em><span class="sig-paren">)</span><span class="pre">;</span><a class="headerlink" href="#c.connect" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p><code class="docutils literal notranslate"><span class="pre">connect()</span></code> connects the socket referred to by the |
| file descriptor <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> to the address specified by <code class="docutils literal notranslate"><span class="pre">addr</span></code>. The |
| <code class="docutils literal notranslate"><span class="pre">addrlen</span></code> argument specifies the size of <code class="docutils literal notranslate"><span class="pre">addr</span></code>. The format of the |
| address in <code class="docutils literal notranslate"><span class="pre">addr</span></code> is determined by the address space of the socket |
| sockfd. If the socket sockfd is of type SOCK_DGRAM then <code class="docutils literal notranslate"><span class="pre">addr</span></code> is the |
| address to which datagrams are sent by default, and the only address |
| from which datagrams are received. If the socket is of type SOCK_STREAM |
| or SOCK_SEQPACKET, this call attempts to make a connection to the socket |
| that is bound to the address specified by <code class="docutils literal notranslate"><span class="pre">addr</span></code>. Generally, |
| connection-based protocol sockets may successfully <code class="docutils literal notranslate"><span class="pre">connect()</span></code> only |
| once; connectionless protocol sockets may use <code class="docutils literal notranslate"><span class="pre">connect()</span></code> multiple |
| times to change their association. Connectionless sockets may dissolve |
| the association by connecting to an address with the sa_family member of |
| sockaddr set to AF_UNSPEC.</p> |
| <p><strong>Input Parameters:</strong></p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">sockfd</span></code>: Socket descriptor returned by <code class="docutils literal notranslate"><span class="pre">socket()</span></code></p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">addr</span></code>: Server address (form depends on type of socket)</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">addrlen</span></code>: Length of actual <code class="docutils literal notranslate"><span class="pre">addr</span></code></p></li> |
| </ul> |
| <p><strong>Returned Value:</strong> 0 on success; -1 on error with |
| <code class="docutils literal notranslate"><span class="pre">`errno</span></code> <#ErrnoAccess>`__ set appropriately:</p> |
| <p><code class="docutils literal notranslate"><span class="pre">EACCES</span></code> or EPERM: The user tried to connect to a broadcast address |
| without having the socket broadcast flag enabled or the connection |
| request failed because of a local firewall rule.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">EADDRINUSE</span></code> Local address is already in use.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">EAFNOSUPPORT</span></code> The passed address didn’t have the correct address |
| family in its sa_family field.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">EAGAIN</span></code> No more free local ports or insufficient entries in the |
| routing cache. For PF_INET.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">EALREADY</span></code> The socket is non-blocking and a previous connection |
| attempt has not yet been completed.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">EBADF</span></code> The file descriptor is not a valid index in the descriptor |
| table.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">ECONNREFUSED</span></code> No one listening on the remote address.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">EFAULT</span></code> The socket structure address is outside the user’s address |
| space.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">EINPROGRESS</span></code> The socket is non-blocking and the connection cannot be |
| completed immediately.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">EINTR</span></code> The system call was interrupted by a signal that was caught.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">EISCONN</span></code> The socket is already connected.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">ENETUNREACH</span></code> Network is unreachable.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">ENOTSOCK</span></code> The file descriptor is not associated with a socket.</p> |
| <p><code class="docutils literal notranslate"><span class="pre">ETIMEDOUT</span></code> Timeout while attempting connection. The server may be too |
| busy to accept new connections.</p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.listen"> |
| <span class="pre">int</span> <code class="sig-name descname"><span class="pre">listen</span></code><span class="sig-paren">(</span><span class="pre">int</span> <em><span class="pre">sockfd</span></em>, <span class="pre">int</span> <em><span class="pre">backlog</span></em><span class="sig-paren">)</span><span class="pre">;</span><a class="headerlink" href="#c.listen" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>To accept connections, a socket is first created with |
| <code class="docutils literal notranslate"><span class="pre">socket()</span></code>, a willingness to accept incoming connections and a queue |
| limit for incoming connections are specified with <code class="docutils literal notranslate"><span class="pre">listen()</span></code>, and then |
| the connections are accepted with <code class="docutils literal notranslate"><span class="pre">accept()</span></code>. The <code class="docutils literal notranslate"><span class="pre">listen()</span></code> call |
| applies only to sockets of type <code class="docutils literal notranslate"><span class="pre">SOCK_STREAM</span></code> or <code class="docutils literal notranslate"><span class="pre">SOCK_SEQPACKET</span></code>.</p> |
| <p><strong>Input Parameters:</strong></p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">sockfd</span></code>: Socket descriptor of the bound socket.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">backlog</span></code>: The maximum length the queue of pending connections may |
| grow. If a connection request arrives with the queue full, the client |
| may receive an error with an indication of ECONNREFUSED or, if the |
| underlying protocol supports retransmission, the request may be |
| ignored so that retries succeed.</p></li> |
| </ul> |
| <p><strong>Returned Value:</strong> On success, zero is returned. On error, -1 is |
| returned, and <code class="docutils literal notranslate"><span class="pre">`errno</span></code> <#ErrnoAccess>`__ is set appropriately.</p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EADDRINUSE</span></code>: Another socket is already listening on the same port.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EBADF</span></code>: The argument <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> is not a valid descriptor.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENOTSOCK</span></code>: The argument <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> is not a socket.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EOPNOTSUPP</span></code>: The socket is not of a type that supports the listen |
| operation.</p></li> |
| </ul> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.accept"> |
| <span class="pre">int</span> <code class="sig-name descname"><span class="pre">accept</span></code><span class="sig-paren">(</span><span class="pre">int</span> <em><span class="pre">sockfd</span></em>, <em class="property"><span class="pre">struct</span></em> <span class="pre">sockaddr</span> <span class="pre">*</span><em><span class="pre">addr</span></em>, <span class="pre">socklen_t</span> <span class="pre">*</span><em><span class="pre">addrlen</span></em><span class="sig-paren">)</span><span class="pre">;</span><a class="headerlink" href="#c.accept" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>The <code class="docutils literal notranslate"><span class="pre">accept()</span></code> function is used with connection-based |
| socket types (<code class="docutils literal notranslate"><span class="pre">SOCK_STREAM</span></code>, <code class="docutils literal notranslate"><span class="pre">SOCK_SEQPACKET</span></code> and <code class="docutils literal notranslate"><span class="pre">SOCK_RDM</span></code>). It |
| extracts the first connection request on the queue of pending |
| connections, creates a new connected socket with most of the same |
| properties as <code class="docutils literal notranslate"><span class="pre">sockfd</span></code>, and allocates a new socket descriptor for the |
| socket, which is returned. The newly created socket is no longer in the |
| listening state. The original socket <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> is unaffected by this |
| call. Per file descriptor flags are not inherited across an accept.</p> |
| <p>The <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> argument is a socket descriptor that has been created |
| with <code class="docutils literal notranslate"><span class="pre">socket()</span></code>, bound to a local address with <code class="docutils literal notranslate"><span class="pre">bind()</span></code>, and is |
| listening for connections after a call to <code class="docutils literal notranslate"><span class="pre">listen()</span></code>.</p> |
| <p>On return, the <code class="docutils literal notranslate"><span class="pre">addr</span></code> structure is filled in with the address of the |
| connecting entity. The <code class="docutils literal notranslate"><span class="pre">addrlen</span></code> argument initially contains the size |
| of the structure pointed to by <code class="docutils literal notranslate"><span class="pre">addr</span></code>; on return it will contain the |
| actual length of the address returned.</p> |
| <p>If no pending connections are present on the queue, and the socket is |
| not marked as non-blocking, accept blocks the caller until a connection |
| is present. If the socket is marked non-blocking and no pending |
| connections are present on the queue, accept returns <code class="docutils literal notranslate"><span class="pre">EAGAIN</span></code>.</p> |
| <p><strong>Input Parameters:</strong></p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">sockfd</span></code>: Socket descriptor of the listening socket.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">addr</span></code>: Receives the address of the connecting client.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">addrlen</span></code>: Input: allocated size of <code class="docutils literal notranslate"><span class="pre">addr</span></code>, Return: returned size |
| of <code class="docutils literal notranslate"><span class="pre">addr</span></code>.</p></li> |
| </ul> |
| <p><strong>Returned Value:</strong> Returns -1 on error. If it succeeds, it returns a |
| non-negative integer that is a descriptor for the accepted socket.</p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EAGAIN</span></code> or <code class="docutils literal notranslate"><span class="pre">EWOULDBLOCK</span></code>: The socket is marked non-blocking and |
| no connections are present to be accepted.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EBADF</span></code>: The descriptor is invalid.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENOTSOCK</span></code>: The descriptor references a file, not a socket.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EOPNOTSUPP</span></code>: The referenced socket is not of type <code class="docutils literal notranslate"><span class="pre">SOCK_STREAM</span></code>.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EINTR</span></code>: The system call was interrupted by a signal that was |
| caught before a valid connection arrived.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ECONNABORTED</span></code>: A connection has been aborted.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EINVAL</span></code>: Socket is not listening for connections.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EMFILE</span></code>: The per-process limit of open file descriptors has been |
| reached.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENFILE</span></code>: The system maximum for file descriptors has been reached.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EFAULT</span></code>: The addr parameter is not in a writable part of the user |
| address space.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENOBUFS</span></code> or <code class="docutils literal notranslate"><span class="pre">ENOMEM</span></code>: Not enough free memory.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EPROTO</span></code>: Protocol error.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EPERM</span></code>: Firewall rules forbid connection.</p></li> |
| </ul> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.send"> |
| <span class="pre">ssize_t</span> <code class="sig-name descname"><span class="pre">send</span></code><span class="sig-paren">(</span><span class="pre">int</span> <em><span class="pre">sockfd</span></em>, <em class="property"><span class="pre">const</span></em> <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">buf</span></em>, <a class="reference internal" href="structures.html#c.size_t" title="size_t"><span class="pre">size_t</span></a> <em><span class="pre">len</span></em>, <span class="pre">int</span> <em><span class="pre">flags</span></em><span class="sig-paren">)</span><span class="pre">;</span><a class="headerlink" href="#c.send" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>The <code class="docutils literal notranslate"><span class="pre">send()</span></code> call may be used only when the socket is |
| in a connected state (so that the intended recipient is known). The only |
| difference between <code class="docutils literal notranslate"><span class="pre">send()</span></code> and <code class="docutils literal notranslate"><span class="pre">write()</span></code> is the presence of |
| <code class="docutils literal notranslate"><span class="pre">flags</span></code>. With <code class="docutils literal notranslate"><span class="pre">zero</span></code> flags parameter, <code class="docutils literal notranslate"><span class="pre">send()</span></code> is equivalent to |
| <code class="docutils literal notranslate"><span class="pre">write()</span></code>. Also, <code class="docutils literal notranslate"><span class="pre">send(s,buf,len,flags)</span></code> is equivalent to |
| <code class="docutils literal notranslate"><span class="pre">sendto(s,buf,len,flags,NULL,0)</span></code>.</p> |
| <p><strong>Input Parameters:</strong></p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">sockfd</span></code>: Socket descriptor of socket</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">buf</span></code>: Data to send</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">len</span></code>: Length of data to send</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">flags</span></code>: Send flags</p></li> |
| </ul> |
| <p><strong>Returned Value:</strong> See <code class="docutils literal notranslate"><span class="pre">`sendto()</span></code> <#sendto>`__.</p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.sendto"> |
| <span class="pre">ssize_t</span> <code class="sig-name descname"><span class="pre">sendto</span></code><span class="sig-paren">(</span><span class="pre">int</span> <em><span class="pre">sockfd</span></em>, <em class="property"><span class="pre">const</span></em> <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">buf</span></em>, <a class="reference internal" href="structures.html#c.size_t" title="size_t"><span class="pre">size_t</span></a> <em><span class="pre">len</span></em>, <span class="pre">int</span> <em><span class="pre">flags</span></em>, <em class="property"><span class="pre">const</span></em> <em class="property"><span class="pre">struct</span></em> <span class="pre">sockaddr</span> <span class="pre">*</span><em><span class="pre">to</span></em>, <span class="pre">socklen_t</span> <em><span class="pre">tolen</span></em><span class="sig-paren">)</span><span class="pre">;</span><a class="headerlink" href="#c.sendto" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>If <code class="docutils literal notranslate"><span class="pre">sendto()</span></code> is used on a connection-mode |
| (SOCK_STREAM, SOCK_SEQPACKET) socket, the parameters to and tolen are |
| ignored (and the error EISCONN may be returned when they are not NULL |
| and 0), and the error ENOTCONN is returned when the socket was not |
| actually connected.</p> |
| <p><strong>Input Parameters:</strong></p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">sockfd</span></code>: Socket descriptor of socket</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">buf</span></code>: Data to send</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">len</span></code>: Length of data to send</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">flags</span></code>: Send flags</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">to</span></code>: Address of recipient</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">tolen</span></code>: The length of the address structure</p></li> |
| </ul> |
| <p><strong>Returned Value:</strong> On success, returns the number of characters sent. |
| On error, -1 is returned, and <code class="docutils literal notranslate"><span class="pre">`errno</span></code> <#ErrnoAccess>`__ is set |
| appropriately:</p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EAGAIN</span></code> or <code class="docutils literal notranslate"><span class="pre">EWOULDBLOCK</span></code>. The socket is marked non-blocking and |
| the requested operation would block.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EBADF</span></code>. An invalid descriptor was specified.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ECONNRESET</span></code>. Connection reset by peer.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EDESTADDRREQ</span></code>. The socket is not connection-mode, and no peer |
| address is set.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EFAULT</span></code>. An invalid user space address was specified for a |
| parameter.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EINTR</span></code>. A signal occurred before any data was transmitted.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EINVAL</span></code>. Invalid argument passed.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EISCONN</span></code>. The connection-mode socket was connected already but a |
| recipient was specified. (Now either this error is returned, or the |
| recipient specification is ignored.)</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EMSGSIZE</span></code>. The socket type requires that message be sent |
| atomically, and the size of the message to be sent made this |
| impossible.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENOBUFS</span></code>. The output queue for a network interface was full. This |
| generally indicates that the interface has stopped sending, but may |
| be caused by transient congestion.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENOMEM</span></code>. No memory available.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENOTCONN</span></code>. The socket is not connected, and no target has been |
| given.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENOTSOCK</span></code>. The argument s is not a socket.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EOPNOTSUPP</span></code>. Some bit in the flags argument is inappropriate for |
| the socket type.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EPIPE</span></code>. The local end has been shut down on a connection oriented |
| socket. In this case the process will also receive a SIGPIPE unless |
| MSG_NOSIGNAL is set.</p></li> |
| </ul> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.recv"> |
| <span class="pre">ssize_t</span> <code class="sig-name descname"><span class="pre">recv</span></code><span class="sig-paren">(</span><span class="pre">int</span> <em><span class="pre">sockfd</span></em>, <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">buf</span></em>, <a class="reference internal" href="structures.html#c.size_t" title="size_t"><span class="pre">size_t</span></a> <em><span class="pre">len</span></em>, <span class="pre">int</span> <em><span class="pre">flags</span></em><span class="sig-paren">)</span><span class="pre">;</span><a class="headerlink" href="#c.recv" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p>The <code class="docutils literal notranslate"><span class="pre">recv()</span></code> call is identical to |
| <code class="docutils literal notranslate"><span class="pre">`recvfrom()</span></code> <#recvfrom>`__ with a NULL <code class="docutils literal notranslate"><span class="pre">from</span></code> parameter.</p> |
| <p><strong>Input Parameters:</strong></p> |
| <ul class="simple"> |
| <li><p>sockfd: Socket descriptor of socket</p></li> |
| <li><p>buf: Buffer to receive data</p></li> |
| <li><p>len: Length of buffer</p></li> |
| <li><p>flags: Receive flags</p></li> |
| </ul> |
| <p><strong>Returned Value:</strong> See <code class="docutils literal notranslate"><span class="pre">`recvfrom()</span></code> <#recvfrom>`__.</p> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.recvfrom"> |
| <span class="pre">ssize_t</span> <code class="sig-name descname"><span class="pre">recvfrom</span></code><span class="sig-paren">(</span><span class="pre">int</span> <em><span class="pre">sockfd</span></em>, <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">buf</span></em>, <a class="reference internal" href="structures.html#c.size_t" title="size_t"><span class="pre">size_t</span></a> <em><span class="pre">len</span></em>, <span class="pre">int</span> <em><span class="pre">flags</span></em>, <em class="property"><span class="pre">struct</span></em> <span class="pre">sockaddr</span> <span class="pre">*</span><em><span class="pre">from</span></em>, <span class="pre">socklen_t</span> <span class="pre">*</span><em><span class="pre">fromlen</span></em><span class="sig-paren">)</span><span class="pre">;</span><a class="headerlink" href="#c.recvfrom" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p><code class="docutils literal notranslate"><span class="pre">recvfrom()</span></code> receives messages from a socket, and may |
| be used to receive data on a socket whether or not it is |
| connection-oriented.</p> |
| <p>If <code class="docutils literal notranslate"><span class="pre">from</span></code> is not NULL, and the underlying protocol provides the source |
| address, this source address is filled in. The argument <code class="docutils literal notranslate"><span class="pre">fromlen</span></code> |
| initialized to the size of the buffer associated with <code class="docutils literal notranslate"><span class="pre">from</span></code>, and |
| modified on return to indicate the actual size of the address stored |
| there.</p> |
| <p><strong>Input Parameters:</strong></p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">sockfd</span></code>: Socket descriptor of socket.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">buf</span></code>: Buffer to receive data.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">len</span></code>: Length of buffer.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">flags</span></code>: Receive flags.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">from</span></code>: Address of source.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">fromlen</span></code>: The length of the address structure.</p></li> |
| </ul> |
| <p><strong>Returned Value:</strong> On success, returns the number of characters sent. |
| If no data is available to be received and the peer has performed an |
| orderly shutdown, recv() will return 0. Otherwise, on errors, -1 is |
| returned, and <code class="docutils literal notranslate"><span class="pre">`errno</span></code> <#ErrnoAccess>`__ is set appropriately:</p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EAGAIN</span></code>. The socket is marked non-blocking and the receive |
| operation would block, or a receive timeout had been set and the |
| timeout expired before data was received.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EBADF</span></code>. The argument <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> is an invalid descriptor.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ECONNREFUSED</span></code>. A remote host refused to allow the network |
| connection (typically because it is not running the requested |
| service).</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EFAULT</span></code>. The receive buffer pointer(s) point outside the process’s |
| address space.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EINTR</span></code>. The receive was interrupted by delivery of a signal before |
| any data were available.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">EINVAL</span></code>. Invalid argument passed.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENOMEM</span></code>. Could not allocate memory.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENOTCONN</span></code>. The socket is associated with a connection-oriented |
| protocol and has not been connected.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ENOTSOCK</span></code>. The argument <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> does not refer to a socket.</p></li> |
| </ul> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.setsockopt"> |
| <span class="pre">int</span> <code class="sig-name descname"><span class="pre">setsockopt</span></code><span class="sig-paren">(</span><span class="pre">int</span> <em><span class="pre">sockfd</span></em>, <span class="pre">int</span> <em><span class="pre">level</span></em>, <span class="pre">int</span> <em><span class="pre">option</span></em>, <em class="property"><span class="pre">const</span></em> <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">value</span></em>, <span class="pre">socklen_t</span> <em><span class="pre">value_len</span></em><span class="sig-paren">)</span><span class="pre">;</span><a class="headerlink" href="#c.setsockopt" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p><code class="docutils literal notranslate"><span class="pre">setsockopt()</span></code> sets the option specified by the |
| <code class="docutils literal notranslate"><span class="pre">option</span></code> argument, at the protocol level specified by the <code class="docutils literal notranslate"><span class="pre">level</span></code> |
| argument, to the value pointed to by the <code class="docutils literal notranslate"><span class="pre">value</span></code> argument for the |
| socket associated with the file descriptor specified by the <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> |
| argument.</p> |
| <p>The <code class="docutils literal notranslate"><span class="pre">level</span></code> argument specifies the protocol level of the option. To |
| set options at the socket level, specify the level argument as |
| SOL_SOCKET.</p> |
| <p>See <code class="docutils literal notranslate"><span class="pre">sys/socket.h</span></code> for a complete list of values for the <code class="docutils literal notranslate"><span class="pre">option</span></code> |
| argument.</p> |
| <p><strong>Input Parameters:</strong></p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">sockfd</span></code>: Socket descriptor of socket</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">level</span></code>: Protocol level to set the option</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">option</span></code>: identifies the option to set</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">value</span></code>: Points to the argument value</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">value_len</span></code>: The length of the argument value</p></li> |
| </ul> |
| <p><strong>Returned Value:</strong> On success, returns the number of characters sent. |
| On error, -1 is returned, and <code class="docutils literal notranslate"><span class="pre">`errno</span></code> <#ErrnoAccess>`__ is set |
| appropriately:</p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">BADF</span></code>. The <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> argument is not a valid socket descriptor.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">DOM</span></code>. The send and receive timeout values are too big to fit into |
| the timeout fields in the socket structure.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">INVAL</span></code>. The specified option is invalid at the specified socket |
| <code class="docutils literal notranslate"><span class="pre">level</span></code> or the socket has been shut down.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">ISCONN</span></code>. The socket is already connected, and a specified option |
| cannot be set while the socket is connected.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">NOPROTOOPT</span></code>. The <code class="docutils literal notranslate"><span class="pre">option</span></code> is not supported by the protocol.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">NOTSOCK</span></code>. The <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> argument does not refer to a socket.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">NOMEM</span></code>. There was insufficient memory available for the operation |
| to complete.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">NOBUFS</span></code>. Insufficient resources are available in the system to |
| complete the call.</p></li> |
| </ul> |
| </dd></dl> |
| |
| <dl class="c function"> |
| <dt id="c.getsockopt"> |
| <span class="pre">int</span> <code class="sig-name descname"><span class="pre">getsockopt</span></code><span class="sig-paren">(</span><span class="pre">int</span> <em><span class="pre">sockfd</span></em>, <span class="pre">int</span> <em><span class="pre">level</span></em>, <span class="pre">int</span> <em><span class="pre">option</span></em>, <span class="pre">void</span> <span class="pre">*</span><em><span class="pre">value</span></em>, <span class="pre">socklen_t</span> <span class="pre">*</span><em><span class="pre">value_len</span></em><span class="sig-paren">)</span><span class="pre">;</span><a class="headerlink" href="#c.getsockopt" title="Permalink to this definition">¶</a><br /></dt> |
| <dd><p><code class="docutils literal notranslate"><span class="pre">getsockopt()</span></code> retrieve those value for the option |
| specified by the <code class="docutils literal notranslate"><span class="pre">option</span></code> argument for the socket specified by the |
| <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> argument. If the size of the option value is greater than |
| <code class="docutils literal notranslate"><span class="pre">value_len</span></code>, the value stored in the object pointed to by the |
| <code class="docutils literal notranslate"><span class="pre">value</span></code> argument will be silently truncated. Otherwise, the length |
| pointed to by the <code class="docutils literal notranslate"><span class="pre">value_len</span></code> argument will be modified to indicate |
| the actual length of the <code class="docutils literal notranslate"><span class="pre">value</span></code>.</p> |
| <p>The <code class="docutils literal notranslate"><span class="pre">level</span></code> argument specifies the protocol level of the option. To |
| retrieve options at the socket level, specify the level argument as |
| SOL_SOCKET.</p> |
| <p>See <code class="docutils literal notranslate"><span class="pre">sys/socket.h</span></code> for a complete list of values for the <code class="docutils literal notranslate"><span class="pre">option</span></code> |
| argument.</p> |
| <p><strong>Input Parameters:</strong></p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">sockfd</span></code>: Socket descriptor of socket</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">level</span></code>: Protocol level to set the option</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">option</span></code>: Identifies the option to get</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">value</span></code>: Points to the argument value</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">value_len</span></code>: The length of the argument value</p></li> |
| </ul> |
| <p><strong>Returned Value:</strong> On success, returns the number of characters sent. |
| On error, -1 is returned, and <code class="docutils literal notranslate"><span class="pre">`errno</span></code> <#ErrnoAccess>`__ is set |
| appropriately:</p> |
| <ul class="simple"> |
| <li><p><code class="docutils literal notranslate"><span class="pre">BADF</span></code>. The <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> argument is not a valid socket descriptor.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">INVAL</span></code>. The specified option is invalid at the specified socket |
| <code class="docutils literal notranslate"><span class="pre">level</span></code> or the socket has been shutdown.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">NOPROTOOPT</span></code>. The <code class="docutils literal notranslate"><span class="pre">option</span></code> is not supported by the protocol.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">NOTSOCK</span></code>. The <code class="docutils literal notranslate"><span class="pre">sockfd</span></code> argument does not refer to a socket.</p></li> |
| <li><p><code class="docutils literal notranslate"><span class="pre">NOBUFS</span></code>. Insufficient resources are available in the system to |
| complete the call.</p></li> |
| </ul> |
| </dd></dl> |
| |
| </div> |
| |
| |
| </div> |
| |
| </div> |
| <footer> |
| <div class="rst-footer-buttons" role="navigation" aria-label="footer navigation"> |
| <a href="12_shared_memory.html" class="btn btn-neutral float-right" title="Shared Memory Interfaces" accesskey="n" rel="next">Next <span class="fa fa-arrow-circle-right" aria-hidden="true"></span></a> |
| <a href="10_filesystem.html" class="btn btn-neutral float-left" title="File System Interfaces" accesskey="p" rel="prev"><span class="fa fa-arrow-circle-left" aria-hidden="true"></span> Previous</a> |
| </div> |
| |
| <hr/> |
| |
| <div role="contentinfo"> |
| <p> |
| © Copyright 2020, The Apache Software Foundation. |
| |
| </p> |
| </div> |
| |
| </footer> |
| </div> |
| </div> |
| |
| </section> |
| |
| </div> |
| |
| |
| <script type="text/javascript"> |
| jQuery(function () { |
| SphinxRtdTheme.Navigation.enable(true); |
| }); |
| </script> |
| |
| |
| |
| |
| |
| |
| </body> |
| </html> |