in.h.html
来自「posix标准英文,html格式」· HTML 代码 · 共 385 行
HTML
385 行
<!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-2004 IEEE and The Open Group, All Rights Reserved --><title><netinet/in.h></title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../../jscript/dotcode.js"></script><basefont size="3"> <a name="<netinet/in.h>"></a> <a name="tag_13_32"></a><!-- <netinet/in.h> --> <!--header start--><center><font size="2">The Open Group Base Specifications Issue 6<br>IEEE Std 1003.1, 2004 Edition<br>Copyright © 2001-2004 The IEEE and The Open Group, All Rights reserved.</font></center><!--header end--><hr size="2" noshade><h4><a name="tag_13_32_01"></a>NAME</h4><blockquote>netinet/in.h - Internet address family</blockquote><h4><a name="tag_13_32_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><tt>#include <netinet/in.h></tt></p></blockquote><h4><a name="tag_13_32_03"></a>DESCRIPTION</h4><blockquote><p>The <i><netinet/in.h></i> header shall define the following types:</p><dl compact><dt><b>in_port_t</b></dt><dd>Equivalent to the type <b>uint16_t</b> as defined in <a href="../inttypes.h.html#tag_13_20"><i><inttypes.h></i></a>.</dd><dt><b>in_addr_t</b></dt><dd>Equivalent to the type <b>uint32_t</b> as defined in <a href="../inttypes.h.html#tag_13_20"><i><inttypes.h></i></a>.</dd></dl><p>The <b>sa_family_t</b> type shall be defined as described in <a href="../sys/socket.h.html#tag_13_61"><i><sys/socket.h></i></a>.</p><p>The <b>uint8_t</b> and <b>uint32_t</b> type shall be defined as described in <a href="../../basedefs/inttypes.h.html"><i><inttypes.h></i></a>. Inclusion of the <i><netinet/in.h></i> header may also makevisible all symbols from <a href="../../basedefs/inttypes.h.html"><i><inttypes.h></i></a> and <a href="../../basedefs/sys/socket.h.html"><i><sys/socket.h></i></a>.</p><p>The <i><netinet/in.h></i> header shall define the <b>in_addr</b> structure that includes at least the followingmember:</p><pre><tt>in_addr_t s_addr</tt></pre><p>The <i><netinet/in.h></i> header shall define the <b>sockaddr_in</b> structure that includes at least the followingmembers:</p><pre><tt>sa_family_t sin_family </tt> AF_INET. <tt>in_port_t sin_port </tt> Port number. <tt>struct in_addr sin_addr </tt> IP address. <tt></tt></pre><p>The <i>sin_port</i> and <i>sin_addr</i> members shall be in network byte order.</p><p>The <b>sockaddr_in</b> structure is used to store addresses for the Internet address family. Values of this type shall be castby applications to <b>struct sockaddr</b> for use with socket functions.</p><p><sup>[<a href="javascript:open_code('IP6')">IP6</a>]</sup> <img src="../../images/opt-start.gif" alt="[Option Start]" border="0"> The <i><netinet/in.h></i> header shall define the <b>in6_addr</b> structure that contains at least the followingmember:</p><pre><tt>uint8_t s6_addr[16]</tt></pre><p>This array is used to contain a 128-bit IPv6 address, stored in network byte order.</p><p>The <i><netinet/in.h></i> header shall define the <b>sockaddr_in6</b> structure that includes at least the followingmembers:</p><pre><tt>sa_family_t sin6_family </tt> AF_INET6. <tt>in_port_t sin6_port </tt> Port number. <tt>uint32_t sin6_flowinfo </tt> IPv6 traffic class and flow information. <tt>struct in6_addr sin6_addr </tt> IPv6 address. <tt>uint32_t sin6_scope_id </tt> Set of interfaces for a scope. <tt></tt></pre><p>The <i>sin6_port</i> and <i>sin6_addr</i> members shall be in network byte order.</p><p>The <b>sockaddr_in6</b> structure shall be set to zero by an application prior to using it, since implementations are free tohave additional, implementation-defined fields in <b>sockaddr_in6</b>.</p><p>The <i>sin6_scope_id</i> field is a 32-bit integer that identifies a set of interfaces as appropriate for the scope of theaddress carried in the <i>sin6_addr</i> field. For a link scope <i>sin6_addr</i>, the application shall ensure that<i>sin6_scope_id</i> is a link index. For a site scope <i>sin6_addr</i>, the application shall ensure that <i>sin6_scope_id</i> isa site index. The mapping of <i>sin6_scope_id</i> to an interface or set of interfaces is implementation-defined.</p><p>The <i><netinet/in.h></i> header shall declare the following external variable:</p><pre><tt>const struct in6_addr in6addr_any</tt></pre><p>This variable is initialized by the system to contain the wildcard IPv6 address. The <i><netinet/in.h></i> header alsodefines the IN6ADDR_ANY_INIT macro. This macro must be constant at compile time and can be used to initialize a variable of type<b>struct in6_addr</b> to the IPv6 wildcard address.</p><p>The <i><netinet/in.h></i> header shall declare the following external variable:</p><pre><tt>const struct in6_addr in6addr_loopback</tt></pre><p>This variable is initialized by the system to contain the loopback IPv6 address. The <i><netinet/in.h></i> header alsodefines the IN6ADDR_LOOPBACK_INIT macro. This macro must be constant at compile time and can be used to initialize a variable oftype <b>struct in6_addr</b> to the IPv6 loopback address.</p><p>The <i><netinet/in.h></i> header shall define the <b>ipv6_mreq</b> structure that includes at least the followingmembers:</p><pre><tt>struct in6_addr ipv6mr_multiaddr </tt> IPv6 multicast address. <tt>unsigned ipv6mr_interface </tt> Interface index. <tt></tt></pre><img src="../../images/opt-end.gif" alt="[Option End]" border="0"> <p>The <i><netinet/in.h></i> header shall define the following macros for use as values of the <i>level</i> argument of <ahref="../../functions/getsockopt.html"><i>getsockopt</i>()</a> and <a href="../../functions/setsockopt.html"><i>setsockopt</i>()</a>:</p><dl compact><dt>IPPROTO_IP</dt><dd>Internet protocol.</dd><dt>IPPROTO_IPV6</dt><dd><sup>[<a href="javascript:open_code('IP6')">IP6</a>]</sup> <img src="../../images/opt-start.gif" alt="[Option Start]" border="0"> Internet Protocol Version 6. <img src="../../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>IPPROTO_ICMP</dt><dd>Control message protocol.</dd><dt>IPPROTO_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 IP Packets Protocol. <img src="../../images/opt-end.gif" alt="[Option End]" border="0"></dd><dt>IPPROTO_TCP</dt><dd>Transmission control protocol.</dd><dt>IPPROTO_UDP</dt><dd>User datagram protocol.</dd></dl><p>The <i><netinet/in.h></i> header shall define the following macros for use as destination addresses for <a href="../../functions/connect.html"><i>connect</i>()</a>, <a href="../../functions/sendmsg.html"><i>sendmsg</i>()</a>, and <a href="../../functions/sendto.html"><i>sendto</i>()</a>:</p><dl compact><dt>INADDR_ANY</dt><dd>IPv4 local host address.</dd><dt>INADDR_BROADCAST</dt><dd>IPv4 broadcast address.</dd></dl><p>The <i><netinet/in.h></i> header shall define the following macro to help applications declare buffers of the proper sizeto store IPv4 addresses in string form:</p><dl compact><dt>INET_ADDRSTRLEN</dt><dd>16. Length of the string form for IP.</dd></dl><p>The <a href="../../functions/htonl.html"><i>htonl</i>()</a>, <a href="../../functions/htons.html"><i>htons</i>()</a>, <a href="../../functions/ntohl.html"><i>ntohl</i>()</a>, and <a href="../../functions/ntohs.html"><i>ntohs</i>()</a> functions shall beavailable as defined in <a href="../arpa/inet.h.html#tag_13_03"><i><arpa/inet.h></i></a>. Inclusion of the<i><netinet/in.h></i> header may also make visible all symbols from <a href="../arpa/inet.h.html#tag_13_03"><i><arpa/inet.h></i></a>.</p><p><sup>[<a href="javascript:open_code('IP6')">IP6</a>]</sup> <img src="../../images/opt-start.gif" alt="[Option Start]" border="0"> The <i><netinet/in.h></i> header shall define the following macro to help applications declare buffers of the propersize to store IPv6 addresses in string form:</p><dl compact><dt>INET6_ADDRSTRLEN</dt><dd>46. Length of the string form for IPv6.</dd></dl><p>The <i><netinet/in.h></i> header shall define the following macros, with distinct integer values, for use in the<i>option_name</i> argument in the <a href="../../functions/getsockopt.html"><i>getsockopt</i>()</a> or <a href="../../functions/setsockopt.html"><i>setsockopt</i>()</a> functions at protocol level IPPROTO_IPV6:</p><dl compact><dt>IPV6_JOIN_GROUP</dt><dd>Join a multicast group.</dd><dt>IPV6_LEAVE_GROUP</dt><dd>Quit a multicast group.</dd><dt>IPV6_MULTICAST_HOPS</dt><dd><br>Multicast hop limit.</dd><dt>IPV6_MULTICAST_IF</dt><dd>Interface to use for outgoing multicast packets.</dd><dt>IPV6_MULTICAST_LOOP</dt><dd><br>Multicast packets are delivered back to the local application.</dd><dt>IPV6_UNICAST_HOPS</dt><dd>Unicast hop limit.</dd><dt>IPV6_V6ONLY</dt><dd>Restrict AF_INET6 socket to IPv6 communications only.</dd></dl><p>The <i><netinet/in.h></i> header shall define the following macros that test for special IPv6 addresses. Each macro is oftype <b>int</b> and takes a single argument of type <b>const struct in6_addr *</b>:</p><dl compact><dt>IN6_IS_ADDR_UNSPECIFIED</dt><dd><br>Unspecified address.</dd><dt>IN6_IS_ADDR_LOOPBACK</dt><dd><br>Loopback address.</dd><dt>IN6_IS_ADDR_MULTICAST</dt><dd><br>Multicast address.</dd><dt>IN6_IS_ADDR_LINKLOCAL</dt><dd><br>Unicast link-local address.</dd><dt>IN6_IS_ADDR_SITELOCAL</dt><dd><br>Unicast site-local address.</dd><dt>IN6_IS_ADDR_V4MAPPED</dt><dd><br>IPv4 mapped address.</dd><dt>IN6_IS_ADDR_V4COMPAT</dt><dd><br>IPv4-compatible address.</dd><dt>IN6_IS_ADDR_MC_NODELOCAL</dt><dd><br>Multicast node-local address.</dd><dt>IN6_IS_ADDR_MC_LINKLOCAL</dt><dd><br>Multicast link-local address.</dd><dt>IN6_IS_ADDR_MC_SITELOCAL</dt><dd><br>Multicast site-local address.</dd><dt>IN6_IS_ADDR_MC_ORGLOCAL</dt><dd><br>Multicast organization-local address.</dd><dt>IN6_IS_ADDR_MC_GLOBAL</dt><dd><br>Multicast global address. <img src="../../images/opt-end.gif" alt="[Option End]" border="0"></dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_13_32_04"></a>APPLICATION USAGE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_13_32_05"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_13_32_06"></a>FUTURE DIRECTIONS</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_13_32_07"></a>SEE ALSO</h4><blockquote><p><a href="../xbd_chap04.html#tag_04_08"><i>Host and Network Byte Orders</i></a>, <a href="../arpa/inet.h.html#tag_13_03"><i><arpa/inet.h></i></a>, <a href="../inttypes.h.html#tag_13_20"><i><inttypes.h></i></a>, <a href="../sys/socket.h.html#tag_13_61"><i><sys/socket.h></i></a>, the System Interfaces volume of IEEE Std 1003.1-2001,<a href="../../functions/connect.html"><i>connect</i>()</a>, <a href="../../functions/getsockopt.html"><i>getsockopt</i>()</a>, <ahref="../../functions/htonl.html"><i>htonl</i>()</a>, <a href="../../functions/htons.html"><i>htons</i>()</a>, <a href="../../functions/ntohl.html"><i>ntohl</i>()</a>, <a href="../../functions/ntohs.html"><i>ntohs</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></p></blockquote><h4><a name="tag_13_32_08"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 6. Derived from the XNS, Issue 5.2 specification.</p><p>The <i>sin_zero</i> member was removed from the <b>sockaddr_in</b> structure as per The Open Group Base Resolutionbwg2001-004.</p><p>IEEE Std 1003.1-2001/Cor 1-2002, item XBD/TC1/D6/12 is applied, adding <b>const</b> qualifiers to the<i>in6addr_any</i> and <i>in6addr_loopback</i> external variables.</p><p>IEEE Std 1003.1-2001/Cor 2-2004, item XBD/TC2/D6/22 is applied, making it clear which structure members are innetwork byte order.</p></blockquote><div class="box"><em>End of informative text.</em></div><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 + =
减小字号Ctrl + -
显示快捷键?