📄 xsh_chap02_10.html
字号:
<p class="tent"><b>int</b></p></td><td align="left"><p class="tent">Non-zero requests reuse of local addresses in <a href="../functions/bind.html"><i>bind</i>()</a>(protocol-specific).</p></td></tr><tr valign="top"><td align="left"><p class="tent">SO_SNDBUF</p></td><td align="left"><p class="tent"><b>int</b></p></td><td align="left"><p class="tent">Size of send buffer (in bytes).</p></td></tr><tr valign="top"><td align="left"><p class="tent">SO_SNDLOWAT</p></td><td align="left"><p class="tent"><b>int</b></p></td><td align="left"><p class="tent">Minimum amount of data to send for output operations (in bytes).</p></td></tr><tr valign="top"><td align="left"><p class="tent">SO_SNDTIMEO</p></td><td align="left"><p class="tent"><b>struct timeval</b></p></td><td align="left"><p class="tent">Timeout value for a socket send operation.</p></td></tr><tr valign="top"><td align="left"><p class="tent">SO_TYPE</p></td><td align="left"><p class="tent"><b>int</b></p></td><td align="left"><p class="tent">Identify socket type ( <a href="../functions/getsockopt.html"><i>getsockopt</i>()</a> only).</p></td></tr></table></center><p>The SO_BROADCAST option requests permission to send broadcast datagrams on the socket. Support for SO_BROADCAST isprotocol-specific. The default for SO_BROADCAST is that the ability to send broadcast datagrams on a socket is disabled.</p><p>The SO_DEBUG option enables debugging in the underlying protocol modules. This can be useful for tracing the behavior of theunderlying protocol modules during normal system operation. The semantics of the debug reports are implementation-defined. Thedefault value for SO_DEBUG is for debugging to be turned off.</p><p>The SO_DONTROUTE option requests that outgoing messages bypass the standard routing facilities. The destination must be on adirectly-connected network, and messages are directed to the appropriate network interface according to the destination address. Itis protocol-specific whether this option has any effect and how the outgoing network interface is chosen. Support for this optionwith each protocol is implementation-defined.</p><p>The SO_ERROR option is used only on <a href="../functions/getsockopt.html"><i>getsockopt</i>()</a>. When this option isspecified, <a href="../functions/getsockopt.html"><i>getsockopt</i>()</a> shall return any pending error on the socket and clearthe error status. It shall return a value of 0 if there is no pending error. SO_ERROR may be used to check for asynchronous errorson connected connectionless-mode sockets or for other types of asynchronous errors. SO_ERROR has no default value.</p><p>The SO_KEEPALIVE option enables the periodic transmission of messages on a connected socket. The behavior of this option isprotocol-specific. The default value for SO_KEEPALIVE is zero, specifying that this capability is turned off.</p><p>The SO_LINGER option controls the action of the interface when unsent messages are queued on a socket and a <a href="../functions/close.html"><i>close</i>()</a> is performed. The details of this option are protocol-specific. The default value forSO_LINGER is zero, or off, for the <i>l_onoff</i> element of the option value and zero seconds for the linger time specified by the<i>l_linger</i> element.</p><p>The SO_OOBINLINE option is valid only on protocols that support out-of-band data. The SO_OOBINLINE option requests thatout-of-band data be placed in the normal data input queue as received; it is then accessible using the <a href="../functions/read.html"><i>read</i>()</a> or <a href="../functions/recv.html"><i>recv</i>()</a> functions without the MSG_OOB flagset. The default for SO_OOBINLINE is off; that is, for out-of-band data not to be placed in the normal data input queue.</p><p>The SO_RCVBUF option requests that the buffer space allocated for receive operations on this socket be set to the value, inbytes, of the option value. Applications may wish to increase buffer size for high volume connections, or may decrease buffer sizeto limit the possible backlog of incoming data. The default value for the SO_RCVBUF option value is implementation-defined, and mayvary by protocol.</p><p>The maximum value for the option for a socket may be obtained by the use of the <a href="../functions/fpathconf.html"><i>fpathconf</i>()</a> function, using the value _PC_SOCK_MAXBUF.</p><p>The SO_RCVLOWAT option sets the minimum number of bytes to process for socket input operations. In general, receive calls blockuntil any (non-zero) amount of data is received, then return the smaller of the amount available or the amount requested. Thedefault value for SO_RCVLOWAT is 1, and does not affect the general case. If SO_RCVLOWAT is set to a larger value, blocking receivecalls normally wait until they have received the smaller of the low water mark value or the requested amount. Receive calls maystill return less than the low water mark if an error occurs, a signal is caught, or the type of data next in the receive queue isdifferent from that returned (for example, out-of-band data). As mentioned previously, the default value for SO_RCVLOWAT is 1 byte.It is implementation-defined whether the SO_RCVLOWAT option can be set.</p><p>The SO_RCVTIMEO option is an option to set a timeout value for input operations. It accepts a <b>timeval</b> structure with thenumber of seconds and microseconds specifying the limit on how long to wait for an input operation to complete. If a receiveoperation has blocked for this much time without receiving additional data, it shall return with a partial count or <i>errno</i>shall be set to [EWOULDBLOCK] if no data were received. The default for this option is the value zero, which indicates that areceive operation will not time out. It is implementation-defined whether the SO_RCVTIMEO option can be set.</p><p>The SO_REUSEADDR option indicates that the rules used in validating addresses supplied in a <a href="../functions/bind.html"><i>bind</i>()</a> should allow reuse of local addresses. Operation of this option is protocol-specific.The default value for SO_REUSEADDR is off; that is, reuse of local addresses is not permitted.</p><p>The SO_SNDBUF option requests that the buffer space allocated for send operations on this socket be set to the value, in bytes,of the option value. The default value for the SO_SNDBUF option value is implementation-defined, and may vary by protocol. Themaximum value for the option for a socket may be obtained by the use of the <a href="../functions/fpathconf.html"><i>fpathconf</i>()</a> function, using the value _PC_SOCK_MAXBUF.</p><p>The SO_SNDLOWAT option sets the minimum number of bytes to process for socket output operations. Most output operations processall of the data supplied by the call, delivering data to the protocol for transmission and blocking as necessary for flow control.Non-blocking output operations process as much data as permitted subject to flow control without blocking, but process no data ifflow control does not allow the smaller of the send low water mark value or the entire request to be processed. A <a href="../functions/select.html"><i>select</i>()</a> operation testing the ability to write to a socket shall return true only if thesend low water mark could be processed. The default value for SO_SNDLOWAT is implementation-defined and protocol-specific. It isimplementation-defined whether the SO_SNDLOWAT option can be set.</p><p>The SO_SNDTIMEO option is an option to set a timeout value for the amount of time that an output function shall block becauseflow control prevents data from being sent. As noted in <a href="#tagtcjh_2">Socket-Level Options</a> , the option value is a<b>timeval</b> structure with the number of seconds and microseconds specifying the limit on how long to wait for an outputoperation to complete. If a send operation has blocked for this much time, it shall return with a partial count or <i>errno</i> setto [EWOULDBLOCK] if no data were sent. The default for this option is the value zero, which indicates that a send operation willnot time out. It is implementation-defined whether the SO_SNDTIMEO option can be set.</p><p>The SO_TYPE option is used only on <a href="../functions/getsockopt.html"><i>getsockopt</i>()</a>. When this option isspecified, <a href="../functions/getsockopt.html"><i>getsockopt</i>()</a> shall return the type of the socket (for example,SOCK_STREAM). This option is useful to servers that inherit sockets on start-up. SO_TYPE has no default value.</p><h4><a name="tag_02_10_17"> 2.10.17 </a>Use of Sockets for Local UNIX Connections</h4><p>Support for UNIX domain sockets is mandatory.</p><p>UNIX domain sockets provide process-to-process communication in a single system.</p><h5><a name="tag_02_10_17_01"></a>Headers</h5><p>The symbolic constant AF_UNIX defined in the <a href="../basedefs/sys/socket.h.html"><i><sys/socket.h></i></a> header isused to identify the UNIX domain address family. The <a href="../basedefs/sys/un.h.html"><i><sys/un.h></i></a> headercontains other definitions used in connection with UNIX domain sockets. See the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap13.html#tag_13">Chapter 13, Headers</a>.</p><p>The <b>sockaddr_storage</b> structure defined in <a href="../basedefs/sys/socket.h.html"><i><sys/socket.h></i></a> shallbe large enough to accommodate a <b>sockaddr_un</b> structure (see the <a href="../basedefs/sys/un.h.html"><i><sys/un.h></i></a> header defined in the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap13.html#tag_13">Chapter 13, Headers</a>) and shall be aligned at anappropriate boundary so that pointers to it can be cast as pointers to <b>sockaddr_un</b> structures and used to access the fieldsof those structures without alignment problems. When a <b>sockaddr_storage</b> structure is cast as a <b>sockaddr_un</b> structure,the <i>ss_family</i> field maps onto the <i>sun_family</i> field.</p><h4><a name="tag_02_10_18"> 2.10.18 </a>Use of Sockets over Internet Protocols</h4><p>When a socket is created in the Internet family with a protocol value of zero, the implementation shall use the protocol listedbelow for the type of socket created.</p><dl compact><dt>SOCK_STREAM</dt><dd>IPPROTO_TCP.</dd><dt>SOCK_DGRAM</dt><dd>IPPROTO_UDP.</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">IPPROTO_RAW. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>SOCK_SEQPACKET</dt><dd>Unspecified.</dd></dl><p><sup>[<a href="javascript:open_code('RS')">RS</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> Araw interface to IP is available by creating an Internet socket of type SOCK_RAW. The default protocol for type SOCK_RAW shall beidentified in the IP header with the value IPPROTO_RAW. Applications should not use the default protocol when creating a socketwith type SOCK_RAW, but should identify a specific protocol by value. The ICMP control protocol is accessible from a raw socket byspecifying a value of IPPROTO_ICMP for protocol. <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p><h4><a name="tag_02_10_19"> 2.10.19 </a>Use of Sockets over Internet Protocols Based on IPv4</h4><p>Support for sockets over Internet protocols based on IPv4 is mandatory.</p><h5><a name="tag_02_10_19_01"></a>Headers</h5><p>The symbolic constant AF_INET defined in the <a href="../basedefs/sys/socket.h.html"><i><sys/socket.h></i></a> header isused to identify the IPv4 Internet address family. The <a href="../basedefs/netinet/in.h.html"><i><netinet/in.h></i></a>header contains other definitions used in connection with IPv4 Internet sockets. See the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap13.html#tag_13">Chapter 13, Headers</a>.</p><p>The <b>sockaddr_storage</b> structure defined in <a href="../basedefs/sys/socket.h.html"><i><sys/socket.h></i></a> shallbe large enough to accommodate a <b>sockaddr_in</b> structure (see the <a href="../basedefs/netinet/in.h.html"><i><netinet/in.h></i></a> header defined in the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/xbd_chap13.html#tag_13">Chapter 13, Headers</a>) and shall be aligned at anappropriate boundary so that pointers to it can be cast as pointers to <b>sockaddr_in</b> structures and used to access the fieldsof those structures without alignment problems. When a <b>sockaddr_storage</b> structure is cast as a <b>sockaddr_in</b> structure,the <i>ss_family</i> field maps onto the <i>sin_family</i> field.</p><h4><a name="tag_02_10_20"> 2.10.20 </a>Use of Sockets over Internet Protocols Based on IPv6</h4><p><sup>[<a href="javascript:open_code('IP6')">IP6</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">This section describes extensions to support sockets over Internet protocols based on IPv6. This functionality is dependent onsupport of the IPV6 option (and the rest of this section is not further marked for this option). <img src="../images/opt-end.gif"alt="[Option End]" border="0"></p><p>To enable smooth transition from IPv4 to IPv6, the features defined in this section may, in certain circumstances, also be usedin connection with IPv4; see <a href="#tag_02_10_20_02">Compatibility with IPv4</a>.</p><h5><a name="tag_02_10_20_01"></a>Addressing</h5><p>IPv6 overcomes the addressing limitations of previous versions by using 128-bit addresses instead of 32-bit addresses. The IPv6address architecture is described in RFC 2373.</p><p>There are three kinds of IPv6 address:</p>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -