📄 xsh_chap02_10.html
字号:
<dl compact><dt>Unicast</dt><dd>Identifies a single interface. <p>A unicast address can be global, link-local (designed for use on a single link), or site-local (designed for systems notconnected to the Internet). Link-local and site-local addresses need not be globally unique.</p></dd><dt>Anycast</dt><dd>Identifies a set of interfaces such that a packet sent to the address can be delivered to any member of the set. <p>An anycast address is similar to a unicast address; the nodes to which an anycast address is assigned must be explicitlyconfigured to know that it is an anycast address.</p></dd><dt>Multicast</dt><dd>Identifies a set of interfaces such that a packet sent to the address should be delivered to every member of the set. <p>An application can send multicast datagrams by simply specifying an IPv6 multicast address in the <i>address</i> argument of <ahref="../functions/sendto.html"><i>sendto</i>()</a>. To receive multicast datagrams, an application must join the multicast group(using <a href="../functions/setsockopt.html"><i>setsockopt</i>()</a> with IPV6_JOIN_GROUP) and must bind to the socket the UDPport on which datagrams will be received. Some applications should also bind the multicast group address to the socket, to preventother datagrams destined to that port from being delivered to the socket.</p><p>A multicast address can be global, node-local, link-local, site-local, or organization-local.</p></dd></dl><p>The following special IPv6 addresses are defined:</p><dl compact><dt>Unspecified</dt><dd>An address that is not assigned to any interface and is used to indicate the absence of an address.</dd><dt>Loopback</dt><dd>A unicast address that is not assigned to any interface and can be used by a node to send packets to itself.</dd></dl><p>Two sets of IPv6 addresses are defined to correspond to IPv4 addresses:</p><dl compact><dt>IPv4-compatible addresses</dt><dd>These are assigned to nodes that support IPv6 and can be used when traffic is "tunneled" through IPv4.</dd><dt>IPv4-mapped addresses</dt><dd>These are used to represent IPv4 addresses in IPv6 address format; see <a href="#tag_02_10_20_02">Compatibility with IPv4</a>.</dd></dl><p>Note that the unspecified address and the loopback address must not be treated as IPv4-compatible addresses.</p><h5><a name="tag_02_10_20_02"></a>Compatibility with IPv4</h5><p>The API provides the ability for IPv6 applications to interoperate with applications using IPv4, by using IPv4-mapped IPv6addresses. These addresses can be generated automatically by the <a href="../functions/getaddrinfo.html"><i>getaddrinfo</i>()</a>function when the specified host has only IPv4 addresses.</p><p>Applications can use AF_INET6 sockets to open TCP connections to IPv4 nodes, or send UDP packets to IPv4 nodes, by simplyencoding the destination's IPv4 address as an IPv4-mapped IPv6 address, and passing that address, within a <b>sockaddr_in6</b>structure, in the <a href="../functions/connect.html"><i>connect</i>()</a>, <a href="../functions/sendto.html"><i>sendto</i>()</a>,or <a href="../functions/sendmsg.html"><i>sendmsg</i>()</a> function. When applications use AF_INET6 sockets to accept TCPconnections from IPv4 nodes, or receive UDP packets from IPv4 nodes, the system shall return the peer's address to the applicationin the <a href="../functions/accept.html"><i>accept</i>()</a>, <a href="../functions/recvfrom.html"><i>recvfrom</i>()</a>, <a href="../functions/recvmsg.html"><i>recvmsg</i>()</a>, or <a href="../functions/getpeername.html"><i>getpeername</i>()</a> functionusing a <b>sockaddr_in6</b> structure encoded this way. If a node has an IPv4 address, then the implementation shall allowapplications to communicate using that address via an AF_INET6 socket. In such a case, the address will be represented at the APIby the corresponding IPv4-mapped IPv6 address. Also, the implementation may allow an AF_INET6 socket bound to <b>in6addr_any</b> toreceive inbound connections and packets destined to one of the node's IPv4 addresses.</p><p>An application can use AF_INET6 sockets to bind to a node's IPv4 address by specifying the address as an IPv4-mapped IPv6address in a <b>sockaddr_in6</b> structure in the <a href="../functions/bind.html"><i>bind</i>()</a> function. For an AF_INET6socket bound to a node's IPv4 address, the system shall return the address in the <a href="../functions/getsockname.html"><i>getsockname</i>()</a> function as an IPv4-mapped IPv6 address in a <b>sockaddr_in6</b>structure.</p><h5><a name="tag_02_10_20_03"></a>Interface Identification</h5><p>Each local interface is assigned a unique positive integer as a numeric index. Indexes start at 1; zero is not used. There maybe gaps so that there is no current interface for a particular positive index. Each interface also has a uniqueimplementation-defined name.</p><h5><a name="tag_02_10_20_04"></a>Options</h5><p>The following options apply at the IPPROTO_IPV6 level:</p><dl compact><dt>IPV6_JOIN_GROUP</dt><dd>When set via <a href="../functions/setsockopt.html"><i>setsockopt</i>()</a>, it joins the application to a multicast group on aninterface (identified by its index) and addressed by a given multicast address, enabling packets sent to that address to be readvia the socket. If the interface index is specified as zero, the system selects the interface (for example, by looking up theaddress in a routing table and using the resulting interface). <p>An attempt to read this option using <a href="../functions/getsockopt.html"><i>getsockopt</i>()</a> shall result in an[EOPNOTSUPP] error.</p><p>The parameter type of this option is a pointer to an <b>ipv6_mreq</b> structure.</p></dd><dt>IPV6_LEAVE_GROUP</dt><dd>When set via <a href="../functions/setsockopt.html"><i>setsockopt</i>()</a>, it removes the application from the multicast group onan interface (identified by its index) and addressed by a given multicast address. <p>An attempt to read this option using <a href="../functions/getsockopt.html"><i>getsockopt</i>()</a> shall result in an[EOPNOTSUPP] error.</p><p>The parameter type of this option is a pointer to an <b>ipv6_mreq</b> structure.</p></dd><dt>IPV6_MULTICAST_HOPS</dt><dd>The value of this option is the hop limit for outgoing multicast IPv6 packets sent via the socket. Its possible values are the sameas those of IPV6_UNICAST_HOPS. If the IPV6_MULTICAST_HOPS option is not set, a value of 1 is assumed. This option can be set via <ahref="../functions/setsockopt.html"><i>setsockopt</i>()</a> and read via <a href="../functions/getsockopt.html"><i>getsockopt</i>()</a>. <p>The parameter type of this option is a pointer to an <b>int</b>. (Default value: 1)</p></dd><dt>IPV6_MULTICAST_IF</dt><dd>The index of the interface to be used for outgoing multicast packets. It can be set via <a href="../functions/setsockopt.html"><i>setsockopt</i>()</a> and read via <a href="../functions/getsockopt.html"><i>getsockopt</i>()</a>.If the interface index is specified as zero, the system selects the interface (for example, by looking up the address in a routingtable and using the resulting interface). <p>The parameter type of this option is a pointer to an <b>unsigned int</b>. (Default value: 0)</p></dd><dt>IPV6_MULTICAST_LOOP</dt><dd>This option controls whether outgoing multicast packets should be delivered back to the local application when the sendinginterface is itself a member of the destination multicast group. If it is set to 1 they are delivered. If it is set to 0 they arenot. Other values result in an [EINVAL] error. This option can be set via <a href="../functions/setsockopt.html"><i>setsockopt</i>()</a> and read via <a href="../functions/getsockopt.html"><i>getsockopt</i>()</a>.<p>The parameter type of this option is a pointer to an <b>unsigned int</b> which is used as a Boolean value. (Default value:1)</p></dd><dt>IPV6_UNICAST_HOPS</dt><dd>The value of this option is the hop limit for outgoing unicast IPv6 packets sent via the socket. If the option is not set, or isset to -1, the system selects a default value. Attempts to set a value less than -1 or greater than 255 shall result in an [EINVAL]error. This option can be set via <a href="../functions/setsockopt.html"><i>setsockopt</i>()</a> and read via <a href="../functions/getsockopt.html"><i>getsockopt</i>()</a>. <p>The parameter type of this option is a pointer to an <b>int</b>. (Default value: Unspecified)</p></dd><dt>IPV6_V6ONLY</dt><dd>This socket option restricts AF_INET6 sockets to IPv6 communications only. AF_INET6 sockets may be used for both IPv4 and IPv6communications. Some applications may want to restrict their use of an AF_INET6 socket to IPv6 communications only. For theseapplications, the IPv6_V6ONLY socket option is defined. When this option is turned on, the socket can be used to send and receiveIPv6 packets only. This is an IPPROTO_IPV6-level option. <p>The parameter type of this option is a pointer to an <b>int</b> which is used as a Boolean value. (Default value: 0)</p></dd></dl><p>An [EOPNOTSUPP] error shall result if IPV6_JOIN_GROUP or IPV6_LEAVE_GROUP is used with <a href="../functions/getsockopt.html"><i>getsockopt</i>()</a>.</p><h5><a name="tag_02_10_20_05"></a>Headers</h5><p>The symbolic constant AF_INET6 is defined in the <a href="../basedefs/sys/socket.h.html"><i><sys/socket.h></i></a> headerto identify the IPv6 Internet address family. See the Base Definitions volume of IEEE 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_in6</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_in6</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_in6</b>structure, the <i>ss_family</i> field maps onto the <i>sin6_family</i> field.</p><p>The <a href="../basedefs/netinet/in.h.html"><i><netinet/in.h></i></a>, <a href="../basedefs/arpa/inet.h.html"><i><arpa/inet.h></i></a>, and <a href="../basedefs/netdb.h.html"><i><netdb.h></i></a>headers contain other definitions used in connection with IPv6 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><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 + -