📄 syssocket.h.html
字号:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 3.2 Final//EN"><html><head><!-- Copyright 1997 The Open Group, All Rights Reserved --><title><sys/socket.h></title></head><body bgcolor=white><center><font size=2>The Single UNIX ® Specification, Version 2<br>Copyright © 1997 The Open Group</font></center><hr size=2 noshade><h4>NAME</h4><blockquote>sys/socket.h - Internet Protocol family</blockquote><h4>SYNOPSIS</h4><blockquote><pre><code>#include <sys/socket.h></code></pre></blockquote><h4>DESCRIPTION</h4><blockquote><i><sys/socket.h></i>makes available a type, <B>socklen_t</B>,which is an unsigned opaque integral type of length of atleast 32 bits. To forestall portability problems, itis recommended that applications should not use valueslarger than 2<SMALL><SUP>32</SUP></SMALL> - 1.<p>The<i><sys/socket.h></i>header defines the unsigned integral type<B>sa_family_t</B>.<p>The<i><sys/socket.h></i>header defines the<B>sockaddr</B>structure that includes at least the following members:<pre><code>sa_family_t sa_family address familychar sa_data[] socket address (variable-length data)</code></pre>The<i><sys/socket.h></i>header defines the<B>msghdr</B>structure that includes at least the following members:<pre><code>void *msg_name optional addresssocklen_t msg_namelen size of addressstruct iovec *msg_iov scatter/gather arrayint msg_iovlen members in msg_iovvoid *msg_control ancillary data, see belowsocklen_t msg_controllen ancillary data buffer lenint msg_flags flags on received message</code></pre>The<i><sys/socket.h></i>header defines the<B>cmsghdr</B>structure that includes at least the following members:<pre><code>socklen_t cmsg_len data byte count, including the cmsghdrint cmsg_level originating protocolint cmsg_type protocol-specific type</code></pre>Ancillary data consists of a sequence of pairs, each consisting of a<B>cmsghdr</B>structure followed by a data array. The data array contains the ancillarydata message, and the<B>cmsghdr</B>structure contains descriptive information that allows an application tocorrectly parse the data.<p>The values for<B>cmsg_level</B>will be legal values for the level argument to the<i><a href="getsockopt.html">getsockopt()</a></i>and<i><a href="setsockopt.html">setsockopt()</a></i>functions. The system documentation should specify the<B>cmsg_type</B>definitions for the supported protocols.<p>Ancillary data is also possible at the socket level. The<i><sys/socket.h></i>header defines the following macro for use as the<B>cmsg_type</B>value when<B>cmsg_level</B>is SOL_SOCKET:<dl compact><dt>SCM_RIGHTS<dd>Indicates that the data array contains the access rights to be sent orreceived.</dl><p>The<i><sys/socket.h></i>header defines the following macros to gain access to thedata arrays in the ancillary data associated with a message header:<dl compact><dt>CMSG_DATA(<I>cmsg</I>)<dd>If the argument is a pointer to a<B>cmsghdr</B>structure, this macro returns an unsigned character pointer to the data arrayassociated with the<B>cmsghdr</B>structure.<dt>CMSG_NXTHDR(<I>mhdr,cmsg</I>)<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>structure in the ancillary data, pointed toby the<B>msg_control</B>field of that<B>msghdr</B>structure, this macro returns a pointer to the next<B>cmsghdr</B>structure, or a null pointer if this structure is the last<B>cmsghdr</B>in the ancillary data.<dt>CMSG_FIRSTHDR(<I>mhdr</I>)<dd><br>If the argument is a pointer to a<B>msghdr</B>structure, this macro returns a pointer to the first<B>cmsghdr</B>structure in the ancillary data associated with this<B>msghdr</B>structure, or a null pointer if there is no ancillary data associated with the<B>msghdr</B>structure.</dl><p>The<i><sys/socket.h></i>header defines the<B>linger</B>structure that includes at least the following members:<pre><code>int l_onoff indicates whether linger option is enabledint l_linger linger time, in seconds</code></pre>The<i><sys/socket.h></i>header defines the following macros, with distinct integral values:<dl compact><dt>SOCK_DGRAM<dd>Datagram socket<dt>SOCK_STREAM<dd>Byte-stream socket<dt>SOCK_SEQPACKET<dd>Sequenced-packet socket</dl><p>The<i><sys/socket.h></i>header defines the following macro for use as the <I>level</I> argument of<i><a href="setsockopt.html">setsockopt()</a></i>and<i><a href="getsockopt.html">getsockopt()</a></i>.<dl compact><dt>SOL_SOCKET<dd>Options to be accessed at socket level, not protocol level.</dl><p>The<i><sys/socket.h></i>header defines the following macros, with distinct integral values,for use as the<I>option_name</I>argument in<i><a href="getsockopt.html">getsockopt()</a></i>or<i><a href="setsockopt.html">setsockopt()</a></i>calls:<dl compact><dt>SO_ACCEPTCONN<dd>Socket is accepting connections.<dt>SO_BROADCAST<dd>Transmission of broadcast messages is supported.<dt>SO_DEBUG<dd>Debugging information is being recorded.<dt>SO_DONTROUTE<dd>bypass normal routing<dt>SO_ERROR<dd>Socket error status.<dt>SO_KEEPALIVE<dd>Connections are kept alive with periodic messages.<dt>SO_LINGER<dd>Socket lingers on close.<dt>SO_OOBINLINE<dd>Out-of-band data is transmitted in line.<dt>SO_RCVBUF<dd>Receive buffer size.<dt>SO_RCVLOWAT<dd>receive "low water mark"<dt>SO_RCVTIMEO<dd>receive timeout<dt>SO_REUSEADDR<dd>Reuse of local addresses is supported.<dt>SO_SNDBUF<dd>Send buffer size.<dt>SO_SNDLOWAT<dd>send "low water mark"<dt>SO_SNDTIMEO<dd>send timeout<dt>SO_TYPE<dd>Socket type.</dl><p>The<i><sys/socket.h></i>header defines the following macros, with distinct integral values, for use asthe valid values for the<B>msg_flags</B>field in the<B>msghdr</B>structure, or the flags parameter in<i><a href="recvfrom.html">recvfrom()</a></i>,<i><a href="recvmsg.html">recvmsg()</a></i>,<i><a href="sendto.html">sendto()</a></i>or<i><a href="sendmsg.html">sendmsg()</a></i>calls:<dl compact><dt>MSG_CTRUNC<dd>Control data truncated.<dt>MSG_DONTROUTE<dd>Send without using routing tables.<dt>MSG_EOR<dd>Terminates a record (if supported by the protocol).<dt>MSG_OOB<dd>Out-of-band data.<dt>MSG_PEEK<dd>Leave received data in queue.<dt>MSG_TRUNC<dd>Normal data truncated.<dt>MSG_WAITALL<dd>Wait for complete message.</dl><p>The<i><sys/socket.h></i>header defines the following macros, with distinct integral values:<dl compact><dt>AF_UNIX<dd>UNIX domain sockets<dt>AF_UNSPEC<dd>Unspecified <dt>AF_INET<dd>Internet domain sockets</dl><p>The<i><sys/socket.h></i>header defines the following macros, with distinct integral values:<dl compact><dt>SHUT_RD<dd>Disables further receive operations.<dt>SHUT_WR<dd>Disables further send operations.<dt>SHUT_RDWR<dd>Disables further send and receive operations.</dl><p>The following are declared as functions, and may also be defined as macros:<pre><code>int <a href="accept.html">accept</a>(int <I>socket</I>, struct sockaddr *<I>address</I>, socklen_t <I>*address_len</I>);int <a href="bind.html">bind</a>(int <I>socket</I>, const struct sockaddr *<I>address</I>, socklen_t <I>address_len</I>);int <a href="connect.html">connect</a>(int <I>socket</I>, const struct sockaddr *<I>address</I>, socklen_t <I>address_len</I>);int <a href="getpeername.html">getpeername</a>(int <I>socket</I>, struct sockaddr *<I>address</I>, socklen_t *<I>address_len</I>);int <a href="getsockname.html">getsockname</a>(int <I>socket</I>, struct sockaddr *<I>address</I>, socklen_t *<I>address_len</I>);int <a href="getsockopt.html">getsockopt</a>(int <I>socket</I>, int <I>level</I>, int <I>option_name</I>, void *<I>option_value</I>, socklen_t *<I>option_len</I>);int <a href="listen.html">listen</a>(int <I>socket</I>, int <I>backlog</I>);ssize_t <a href="recv.html">recv</a>(int <I>socket</I>, void *<I>buffer</I>, size_t <I>length</I>, int <I>flags</I>);ssize_t <a href="recvfrom.html">recvfrom</a>(int <I>socket</I>, void *<I>buffer</I>, size_t <I>length</I>, int <I>flags</I>, struct sockaddr *<I>address</I>, socklen_t *<I>address_len</I>);ssize_t <a href="recvmsg.html">recvmsg</a>(int <I>socket</I>, struct msghdr *<I>message</I>, int <I>flags</I>);ssize_t <a href="send.html">send</a>(int <I>socket</I>, const void *<I>message</I>, size_t <I>length</I>, int <I>flags</I>);ssize_t <a href="sendmsg.html">sendmsg</a>(int <I>socket</I>, const struct msghdr *<I>message</I>, int <I>flags</I>);ssize_t <a href="sendto.html">sendto</a>(int <I>socket</I>, const void *<I>message</I>, size_t <I>length</I>, int <I>flags</I>, const struct sockaddr *<I>dest_addr</I>, socklen_t <I>dest_len</I>);int <a href="setsockopt.html">setsockopt</a>(int <I>socket</I>, int <I>level</I>, int <I>option_name</I>, const void *<I>option_value</I>, socklen_t <I>option_len</I>);int <a href="shutdown.html">shutdown</a>(int <I>socket</I>, int <I>how</I>);int <a href="socket.html">socket</a>(int <I>domain</I>, int <I>type</I>, int <I>protocol</I>);int <a href="socketpair.html">socketpair</a>(int <I>domain</I>, int <I>type</I>, int <I>protocol</I>, int <I>socket_vector</I>[2]);</code></pre><br></blockquote><h4>SEE ALSO</h4><blockquote><i><a href="accept.html">accept()</a></i>,<i><a href="bind.html">bind()</a></i>,<i><a href="connect.html">connect()</a></i>,<i><a href="getpeername.html">getpeername()</a></i>,<i><a href="getsockname.html">getsockname()</a></i>,<i><a href="getsockopt.html">getsockopt()</a></i>,<i><a href="listen.html">listen()</a></i>,<i><a href="recv.html">recv()</a></i>,<i><a href="recvfrom.html">recvfrom()</a></i>,<i><a href="recvmsg.html">recvmsg()</a></i>,<i><a href="send.html">send()</a></i>,<i><a href="sendmsg.html">sendmsg()</a></i>,<i><a href="sendto.html">sendto()</a></i>,<i><a href="setsockopt.html">setsockopt()</a></i>,<i><a href="shutdown.html">shutdown()</a></i>,<i><a href="socket.html">socket()</a></i>,<i><a href="socketpair.html">socketpair()</a></i>.</blockquote><hr size=2 noshade><center><font size=2>UNIX ® is a registered Trademark of The Open Group.<br>Copyright © 1997 The Open Group<br> [ <a href="../index.html">Main Index</a> | <a href="../xshix.html">XSH</a> | <a href="../xcuix.html">XCU</a> | <a href="../xbdix.html">XBD</a> | <a href="../cursesix.html">XCURSES</a> | <a href="../xnsix.html">XNS</a> ]</font></center><hr size=2 noshade></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -