⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 socket.h.html

📁 IEEE 1003.1-2003, Single Unix Specification v3
💻 HTML
📖 第 1 页 / 共 2 页
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"><html><head><meta name="generator" content="HTML Tidy, see www.w3.org"><meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"><link type="text/css" rel="stylesheet" href="style.css"><!-- Generated by The Open Group's rhtm tool v1.2.1 --><!-- Copyright (c) 2001-2003 The Open Group, All Rights Reserved --><title>&lt;sys/socket.h&gt;</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../../jscript/dotcode.js"></script><basefont size="3"> <a name="&lt;sys/socket.h&gt;"></a> <a name="tag_13_61"></a><!-- &lt;sys/socket.h&gt; --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2003 Edition<br>Copyright &copy; 2001-2003 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_13_61_01"></a>NAME</h4><blockquote>sys/socket.h - main sockets header</blockquote><h4><a name="tag_13_61_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><tt>#include &lt;sys/socket.h&gt;</tt></p></blockquote><h4><a name="tag_13_61_03"></a>DESCRIPTION</h4><blockquote><p>The <i>&lt;sys/socket.h&gt;</i> header shall define the type <b>socklen_t</b>, which is an integer type of width of at least 32bits; see APPLICATION USAGE.</p><p>The <i>&lt;sys/socket.h&gt;</i> header shall define the unsigned integer type <b>sa_family_t</b>.</p><p>The <i>&lt;sys/socket.h&gt;</i> header shall define the <b>sockaddr</b> structure that includes at least the followingmembers:</p><pre><tt>sa_family_t  sa_family </tt> Address family. <tt>char         sa_data[] </tt> Socket address (variable-length data). <tt></tt></pre><p>The <b>sockaddr</b> structure is used to define a socket address which is used in the <a href="../../functions/bind.html"><i>bind</i>()</a>, <a href="../../functions/connect.html"><i>connect</i>()</a>, <a href="../../functions/getpeername.html"><i>getpeername</i>()</a>, <a href="../../functions/getsockname.html"><i>getsockname</i>()</a>,<a href="../../functions/recvfrom.html"><i>recvfrom</i>()</a>, and <a href="../../functions/sendto.html"><i>sendto</i>()</a>functions.</p><p>The <i>&lt;sys/socket.h&gt;</i> header shall define the <b>sockaddr_storage</b> structure. This structure shall be:</p><ul><li><p>Large enough to accommodate all supported protocol-specific address structures</p></li><li><p>Aligned at an appropriate boundary so that pointers to it can be cast as pointers to protocol-specific address structures andused to access the fields of those structures without alignment problems</p></li></ul><p>The <b>sockaddr_storage</b> structure shall contain at least the following members:</p><pre><tt>sa_family_t   ss_family</tt></pre><p>When a <b>sockaddr_storage</b> structure is cast as a <b>sockaddr</b> structure, the <i>ss_family</i> field of the<b>sockaddr_storage</b> structure shall map onto the <i>sa_family</i> field of the <b>sockaddr</b> structure. When a<b>sockaddr_storage</b> structure is cast as a protocol-specific address structure, the <i>ss_family</i> field shall map onto afield of that structure that is of type <b>sa_family_t</b> and that identifies the protocol's address family.</p><p>The <i>&lt;sys/socket.h&gt;</i> header shall define the <b>msghdr</b> structure that includes at least the followingmembers:</p><pre><tt>void          *msg_name       </tt> Optional address. <tt>socklen_t      msg_namelen    </tt> Size of address. <tt>struct iovec  *msg_iov        </tt> Scatter/gather array. <tt>int            msg_iovlen     </tt> Members in <i>msg_iov</i>. <tt>void          *msg_control    </tt> Ancillary data; see below. <tt>socklen_t      msg_controllen </tt> Ancillary data buffer <i>len</i>. <tt>int            msg_flags      </tt> Flags on received message. <tt></tt></pre><p>The <b>msghdr</b> structure is used to minimize the number of directly supplied parameters to the <a href="../../functions/recvmsg.html"><i>recvmsg</i>()</a> and <a href="../../functions/sendmsg.html"><i>sendmsg</i>()</a> functions. Thisstructure is used as a <i>value</i>- <i>result</i> parameter in the <a href="../../functions/recvmsg.html"><i>recvmsg</i>()</a>function and <i>value</i> only for the <a href="../../functions/sendmsg.html"><i>sendmsg</i>()</a> function.</p><p>The <b>iovec</b> structure shall be defined as described in <a href="../sys/uio.h.html#tag_13_68"><i>&lt;sys/uio.h&gt;</i></a>.</p><p>The <i>&lt;sys/socket.h&gt;</i> header shall define the <b>cmsghdr</b> structure that includes at least the followingmembers:</p><pre><tt>socklen_t  cmsg_len   </tt> Data byte count, including the <b>cmsghdr</b>. <tt>int        cmsg_level </tt> Originating protocol. <tt>int        cmsg_type  </tt> Protocol-specific type. <tt></tt></pre><p>The <b>cmsghdr</b> structure is used for storage of ancillary data object information.</p><p>Ancillary data consists of a sequence of pairs, each consisting of a <b>cmsghdr</b> structure followed by a data array. The dataarray contains the ancillary data message, and the <b>cmsghdr</b> structure contains descriptive information that allows anapplication to correctly parse the data.</p><p>The values for <i>cmsg_level</i> shall be legal values for the <i>level</i> argument to the <a href="../../functions/getsockopt.html"><i>getsockopt</i>()</a> and <a href="../../functions/setsockopt.html"><i>setsockopt</i>()</a>functions. The system documentation shall specify the <i>cmsg_type</i> definitions for the supported protocols.</p><p>Ancillary data is also possible at the socket level. The <i>&lt;sys/socket.h&gt;</i> header defines the following macro for useas the <i>cmsg_type</i> value when <i>cmsg_level</i> is SOL_SOCKET:</p><dl compact><dt>SCM_RIGHTS</dt><dd>Indicates that the data array contains the access rights to be sent or received.</dd></dl><p>The <i>&lt;sys/socket.h&gt;</i> header defines the following macros to gain access to the data arrays in the ancillary dataassociated with a message header:</p><dl compact><dt>CMSG_DATA(<i>cmsg</i>)</dt><dd><br>If the argument is a pointer to a <b>cmsghdr</b> structure, this macro shall return an unsigned character pointer to the data arrayassociated with the <b>cmsghdr</b> structure.</dd><dt>CMSG_NXTHDR(<i>mhdr,cmsg</i>)</dt><dd><br>If the first argument is a pointer to a <b>msghdr</b> structure and the second argument is a pointer to a <b>cmsghdr</b> structurein the ancillary data pointed to by the <i>msg_control</i> field of that <b>msghdr</b> structure, this macro shall return a pointerto the next <b>cmsghdr</b> structure, or a null pointer if this structure is the last <b>cmsghdr</b> in the ancillary data.</dd><dt>CMSG_FIRSTHDR(<i>mhdr</i>)</dt><dd><br>If the argument is a pointer to a <b>msghdr</b> structure, this macro shall return a pointer to the first <b>cmsghdr</b> structurein the ancillary data associated with this <b>msghdr</b> structure, or a null pointer if there is no ancillary data associated withthe <b>msghdr</b> structure.</dd></dl><p>The <i>&lt;sys/socket.h&gt;</i> header shall define the <b>linger</b> structure that includes at least the followingmembers:</p><pre><tt>int  l_onoff  </tt> Indicates whether linger option is enabled. <tt>int  l_linger </tt> Linger time, in seconds. <tt></tt></pre><p>The <i>&lt;sys/socket.h&gt;</i> header shall define the following macros, with distinct integer values:</p><dl compact><dt>SOCK_DGRAM</dt><dd>Datagram socket.</dd><dt>SOCK_RAW</dt><dd><sup>[<a href="javascript:open_code('RS')">RS</a>]</sup> <img src="../../images/opt-start.gif" alt="[Option Start]" border="0">Raw Protocol Interface. <img src="../../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>SOCK_SEQPACKET</dt><dd>Sequenced-packet socket.</dd><dt>SOCK_STREAM</dt><dd>Byte-stream socket.</dd></dl><p>The <i>&lt;sys/socket.h&gt;</i> header shall define the following macro for use as the <i>level</i> argument of <a href="../../functions/setsockopt.html"><i>setsockopt</i>()</a> and <a href="../../functions/getsockopt.html"><i>getsockopt</i>()</a>.</p><dl compact><dt>SOL_SOCKET</dt><dd>Options to be accessed at socket level, not protocol level.</dd></dl><p>The <i>&lt;sys/socket.h&gt;</i> header shall define the following macros, with distinct integer values, for use as the<i>option_name</i> argument in <a href="../../functions/getsockopt.html"><i>getsockopt</i>()</a> or <a href="../../functions/setsockopt.html"><i>setsockopt</i>()</a> calls:</p><dl compact><dt>SO_ACCEPTCONN</dt><dd>Socket is accepting connections.</dd><dt>SO_BROADCAST</dt><dd>Transmission of broadcast messages is supported.</dd><dt>SO_DEBUG</dt><dd>Debugging information is being recorded.</dd><dt>SO_DONTROUTE</dt><dd>Bypass normal routing.</dd><dt>SO_ERROR</dt><dd>Socket error status.</dd><dt>SO_KEEPALIVE</dt><dd>Connections are kept alive with periodic messages.</dd><dt>SO_LINGER</dt><dd>Socket lingers on close.</dd><dt>SO_OOBINLINE</dt><dd>Out-of-band data is transmitted in line.</dd><dt>SO_RCVBUF</dt><dd>Receive buffer size.</dd><dt>SO_RCVLOWAT</dt><dd>Receive ``low water mark''.</dd><dt>SO_RCVTIMEO</dt><dd>Receive timeout.</dd><dt>SO_REUSEADDR</dt>

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -