📄 socket.h.html
字号:
<dd>Reuse of local addresses is supported.</dd><dt>SO_SNDBUF</dt><dd>Send buffer size.</dd><dt>SO_SNDLOWAT</dt><dd>Send ``low water mark''.</dd><dt>SO_SNDTIMEO</dt><dd>Send timeout.</dd><dt>SO_TYPE</dt><dd>Socket type.</dd></dl><p>The <i><sys/socket.h></i> header shall define the following macro as the maximum <i>backlog</i> queue length which may bespecified by the <i>backlog</i> field of the <a href="../../functions/listen.html"><i>listen</i>()</a> function:</p><dl compact><dt>SOMAXCONN</dt><dd>The maximum <i>backlog</i> queue length.</dd></dl><p>The <i><sys/socket.h></i> header shall define the following macros, with distinct integer values, for use as the validvalues for the <i>msg_flags</i> field in the <b>msghdr</b> structure, or the <i>flags</i> parameter in <a href="../../functions/recvfrom.html"><i>recvfrom</i>()</a>, <a href="../../functions/recvmsg.html"><i>recvmsg</i>()</a>, <a href="../../functions/sendmsg.html"><i>sendmsg</i>()</a>, or <a href="../../functions/sendto.html"><i>sendto</i>()</a> calls:</p><dl compact><dt>MSG_CTRUNC</dt><dd>Control data truncated.</dd><dt>MSG_DONTROUTE</dt><dd>Send without using routing tables.</dd><dt>MSG_EOR</dt><dd>Terminates a record (if supported by the protocol).</dd><dt>MSG_OOB</dt><dd>Out-of-band data.</dd><dt>MSG_PEEK</dt><dd>Leave received data in queue.</dd><dt>MSG_TRUNC</dt><dd>Normal data truncated.</dd><dt>MSG_WAITALL</dt><dd>Attempt to fill the read buffer.</dd></dl><p>The <i><sys/socket.h></i> header shall define the following macros, with distinct integer values:</p><dl compact><dt>AF_INET</dt><dd>Internet domain sockets for use with IPv4 addresses.</dd><dt>AF_INET6</dt><dd><sup>[<a href="javascript:open_code('IP6')">IP6</a>]</sup> <img src="../../images/opt-start.gif" alt="[Option Start]" border="0"> Internet domain sockets for use with IPv6 addresses. <img src="../../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>AF_UNIX</dt><dd>UNIX domain sockets.</dd><dt>AF_UNSPEC</dt><dd>Unspecified.</dd></dl><p>The <i><sys/socket.h></i> header shall define the following macros, with distinct integer values:</p><dl compact><dt>SHUT_RD</dt><dd>Disables further receive operations.</dd><dt>SHUT_RDWR</dt><dd>Disables further send and receive operations.</dd><dt>SHUT_WR</dt><dd>Disables further send operations.</dd></dl><p>The following shall be declared as functions and may also be defined as macros. Function prototypes shall be provided.</p><pre><tt>int accept(int, struct sockaddr *restrict, socklen_t *restrict);int bind(int, const struct sockaddr *, socklen_t);int connect(int, const struct sockaddr *, socklen_t);int getpeername(int, struct sockaddr *restrict, socklen_t *restrict);int getsockname(int, struct sockaddr *restrict, socklen_t *restrict);int getsockopt(int, int, int, void *restrict, socklen_t *restrict);int listen(int, int);ssize_t recv(int, void *, size_t, int);ssize_t recvfrom(int, void *restrict, size_t, int, struct sockaddr *restrict, socklen_t *restrict);ssize_t recvmsg(int, struct msghdr *, int);ssize_t send(int, const void *, size_t, int);ssize_t sendmsg(int, const struct msghdr *, int);ssize_t sendto(int, const void *, size_t, int, const struct sockaddr *, socklen_t);int setsockopt(int, int, int, const void *, socklen_t);int shutdown(int, int);int socket(int, int, int);int sockatmark(int);int socketpair(int, int, int, int[2]);</tt></pre><p>Inclusion of <i><sys/socket.h></i> may also make visible all symbols from <a href="../../basedefs/sys/uio.h.html"><i><sys/uio.h></i></a>.</p></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_13_61_04"></a>APPLICATION USAGE</h4><blockquote><p>To forestall portability problems, it is recommended that applications not use values larger than 2<sup><small>31</small></sup>-1 for the <b>socklen_t</b> type.</p><p>The <b>sockaddr_storage</b> structure solves the problem of declaring storage for automatic variables which is both large enoughand aligned enough for storing the socket address data structure of any family. For example, code with a file descriptor andwithout the context of the address family can pass a pointer to a variable of this type, where a pointer to a socket addressstructure is expected in calls such as <a href="../../functions/getpeername.html"><i>getpeername</i>()</a>, and determine theaddress family by accessing the received content after the call.</p><p>The example below illustrates a data structure which aligns on a 64-bit boundary. An implementation-defined field<i>_ss_align</i> following <i>_ss_pad1</i> is used to force a 64-bit alignment which covers proper alignment good enough for needsof at least <b>sockaddr_in6</b> (IPv6) and <b>sockaddr_in</b> (IPv4) address data structures. The size of padding field<i>_ss_pad1</i> depends on the chosen alignment boundary. The size of padding field <i>_ss_pad2</i> depends on the value of overallsize chosen for the total size of the structure. This size and alignment are represented in the above example byimplementation-defined (not required) constants _SS_MAXSIZE (chosen value 128) and _SS_ALIGNMENT (with chosen value 8). Constants_SS_PAD1SIZE (derived value 6) and _SS_PAD2SIZE (derived value 112) are also for illustration and not required. Theimplementation-defined definitions and structure field names above start with an underscore to denote implementation private namespace. Portable code is not expected to access or reference those fields or constants.</p><pre><tt>/* * Desired design of maximum size and alignment. */#define _SS_MAXSIZE 128 /* Implementation-defined maximum size. */#define _SS_ALIGNSIZE (sizeof(int64_t)) /* Implementation-defined desired alignment. */<br>/* * Definitions used for sockaddr_storage structure paddings design. */#define _SS_PAD1SIZE (_SS_ALIGNSIZE - sizeof(sa_family_t))#define _SS_PAD2SIZE (_SS_MAXSIZE - (sizeof(sa_family_t)+ \ _SS_PAD1SIZE + _SS_ALIGNSIZE))struct sockaddr_storage { sa_family_t ss_family; /* Address family. *//* * Following fields are implementation-defined. */ char _ss_pad1[_SS_PAD1SIZE]; /* 6-byte pad; this is to make implementation-defined pad up to alignment field that follows explicit in the data structure. */ int64_t _ss_align; /* Field to force desired structure storage alignment. */ char _ss_pad2[_SS_PAD2SIZE]; /* 112-byte pad to achieve desired size, _SS_MAXSIZE value minus size of ss_family __ss_pad1, __ss_align fields is 112. */};</tt></pre></blockquote><h4><a name="tag_13_61_05"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_13_61_06"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_13_61_07"></a>SEE ALSO</h4><blockquote><p><a href="../sys/uio.h.html#tag_13_68"><i><sys/uio.h></i></a> , the System Interfaces volume ofIEEE Std 1003.1-2001, <a href="../../functions/accept.html"><i>accept</i>()</a>, <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/getsockopt.html"><i>getsockopt</i>()</a>, <a href="../../functions/listen.html"><i>listen</i>()</a>, <ahref="../../functions/recv.html"><i>recv</i>()</a>, <a href="../../functions/recvfrom.html"><i>recvfrom</i>()</a>, <a href="../../functions/recvmsg.html"><i>recvmsg</i>()</a>, <a href="../../functions/send.html"><i>send</i>()</a>, <a href="../../functions/sendmsg.html"><i>sendmsg</i>()</a>, <a href="../../functions/sendto.html"><i>sendto</i>()</a>, <a href="../../functions/setsockopt.html"><i>setsockopt</i>()</a>, <a href="../../functions/shutdown.html"><i>shutdown</i>()</a>, <a href="../../functions/socket.html"><i>socket</i>()</a>, <a href="../../functions/socketpair.html"><i>socketpair</i>()</a></p></blockquote><h4><a name="tag_13_61_08"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 6. Derived from the XNS, Issue 5.2 specification.</p><p>The <b>restrict</b> keyword is added to the prototypes for <a href="../../functions/accept.html"><i>accept</i>()</a>, <a href="../../functions/getpeername.html"><i>getpeername</i>()</a>, <a href="../../functions/getsockname.html"><i>getsockname</i>()</a>,<a href="../../functions/getsockopt.html"><i>getsockopt</i>()</a>, and <a href="../../functions/recvfrom.html"><i>recvfrom</i>()</a>.</p></blockquote><div class="box"><em>End of informative text.</em></div><hr><hr size="2" noshade><center><font size="2"><!--footer start-->UNIX ® is a registered Trademark of The Open Group.<br>POSIX ® is a registered Trademark of The IEEE.<br>[ <a href="../../mindex.html">Main Index</a> | <a href="../../basedefs/contents.html">XBD</a> | <a href="../../utilities/contents.html">XCU</a> | <a href="../../functions/contents.html">XSH</a> | <a href="../../xrat/contents.html">XRAT</a> ]</font></center><!--footer end--><hr size="2" noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -