198 lines
8.3 KiB
HTML
198 lines
8.3 KiB
HTML
<!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 The Open Group, All Rights Reserved -->
|
|
<title>inet_ntop</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="inet_ntop"></a> <a name="tag_03_279"></a><!-- inet_ntop -->
|
|
<!--header start-->
|
|
<center><font size="2">The Open Group Base Specifications Issue 6<br>
|
|
IEEE Std 1003.1-2001<br>
|
|
Copyright © 2001 The IEEE and The Open Group, All Rights reserved.</font></center>
|
|
|
|
<!--header end-->
|
|
<hr size="2" noshade>
|
|
<h4><a name="tag_03_279_01"></a>NAME</h4>
|
|
|
|
<blockquote>inet_ntop, inet_pton - convert IPv4 and IPv6 addresses between binary and text form</blockquote>
|
|
|
|
<h4><a name="tag_03_279_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>#include <<a href="../basedefs/arpa/inet.h.html">arpa/inet.h</a>><br>
|
|
<br>
|
|
const char *inet_ntop(int</tt> <i>af</i><tt>, const void *restrict</tt> <i>src</i><tt>,<br>
|
|
char *restrict</tt> <i>dst</i><tt>, socklen_t</tt> <i>size</i><tt>);<br>
|
|
int inet_pton(int</tt> <i>af</i><tt>, const char *restrict</tt> <i>src</i><tt>, void *restrict</tt> <i>dst</i><tt>);<br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_279_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>inet_ntop</i>() function shall convert a numeric address into a text string suitable for presentation. The <i>af</i>
|
|
argument shall specify the family of the address. This can be AF_INET <sup>[<a href="javascript:open_code('IP6')">IP6</a>]</sup>
|
|
<img src="../images/opt-start.gif" alt="[Option Start]" border="0"> or AF_INET6. <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"> The <i>src</i> argument points to a buffer holding an IPv4 address if the <i>af</i> argument is AF_INET,
|
|
<sup>[<a href="javascript:open_code('IP6')">IP6</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
or an IPv6 address if the <i>af</i> argument is AF_INET6. <img src="../images/opt-end.gif" alt="[Option End]" border="0"> The
|
|
<i>dst</i> argument points to a buffer where the function stores the resulting text string; it shall not be NULL. The <i>size</i>
|
|
argument specifies the size of this buffer, which shall be large enough to hold the text string (INET_ADDRSTRLEN characters for
|
|
IPv4, <sup>[<a href="javascript:open_code('IP6')">IP6</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border=
|
|
"0"> INET6_ADDRSTRLEN characters for IPv6). <img src="../images/opt-end.gif" alt="[Option End]" border="0"></p>
|
|
|
|
<p>The <i>inet_pton</i>() function shall convert an address in its standard text presentation form into its numeric binary form.
|
|
The <i>af</i> argument shall specify the family of the address. The AF_INET <sup>[<a href=
|
|
"javascript:open_code('IP6')">IP6</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> and AF_INET6
|
|
<img src="../images/opt-end.gif" alt="[Option End]" border="0"> address families shall be supported. The <i>src</i> argument points
|
|
to the string being passed in. The <i>dst</i> argument points to a buffer into which the function stores the numeric address; this
|
|
shall be large enough to hold the numeric address (32 bits for AF_INET, <sup>[<a href="javascript:open_code('IP6')">IP6</a>]</sup>
|
|
<img src="../images/opt-start.gif" alt="[Option Start]" border="0"> 128 bits for AF_INET6). <img src="../images/opt-end.gif"
|
|
alt="[Option End]" border="0"></p>
|
|
|
|
<p>If the <i>af</i> argument of <i>inet_pton</i>() is AF_INET, the <i>src</i> string shall be in the standard IPv4 dotted-decimal
|
|
form:</p>
|
|
|
|
<pre>
|
|
<tt>ddd.ddd.ddd.ddd
|
|
</tt>
|
|
</pre>
|
|
|
|
<p>where <tt>"ddd"</tt> is a one to three digit decimal number between 0 and 255 (see <a href=
|
|
"inet_addr.html"><i>inet_addr</i>()</a> ). The <i>inet_pton</i>() function does not accept other formats (such as the octal
|
|
numbers, hexadecimal numbers, and fewer than four numbers that <a href="../functions/inet_addr.html"><i>inet_addr</i>()</a>
|
|
accepts).</p>
|
|
|
|
<p><sup>[<a href="javascript:open_code('IP6')">IP6</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0">
|
|
If the <i>af</i> argument of <i>inet_pton</i>() is AF_INET6, the <i>src</i> string shall be in one of the following standard IPv6
|
|
text forms:</p>
|
|
|
|
<ol>
|
|
<li>
|
|
<p>The preferred form is <tt>"x:x:x:x:x:x:x:x"</tt> , where the <tt>'x'</tt> s are the hexadecimal values of the eight 16-bit
|
|
pieces of the address. Leading zeros in individual fields can be omitted, but there shall be at least one numeral in every
|
|
field.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>A string of contiguous zero fields in the preferred form can be shown as <tt>"::"</tt> . The <tt>"::"</tt> can only appear once
|
|
in an address. Unspecified addresses ( <tt>"0:0:0:0:0:0:0:0"</tt> ) may be represented simply as <tt>"::"</tt> .</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>A third form that is sometimes more convenient when dealing with a mixed environment of IPv4 and IPv6 nodes is
|
|
<tt>"x:x:x:x:x:x:d.d.d.d"</tt> , where the <tt>'x'</tt> s are the hexadecimal values of the six high-order 16-bit pieces of the
|
|
address, and the <tt>'d'</tt> s are the decimal values of the four low-order 8-bit pieces of the address (standard IPv4
|
|
representation).</p>
|
|
</li>
|
|
</ol>
|
|
|
|
<basefont size="2">
|
|
|
|
<dl>
|
|
<dt><b>Note:</b></dt>
|
|
|
|
<dd>A more extensive description of the standard representations of IPv6 addresses can be found in RFC 2373.</dd>
|
|
</dl>
|
|
|
|
<basefont size="3"> <img src="../images/opt-end.gif" alt="[Option End]" border="0"></blockquote>
|
|
|
|
<h4><a name="tag_03_279_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>inet_ntop</i>() function shall return a pointer to the buffer containing the text string if the conversion succeeds, and
|
|
NULL otherwise, and set <i>errno</i> to indicate the error.</p>
|
|
|
|
<p>The <i>inet_pton</i>() function shall return 1 if the conversion succeeds, with the address pointed to by <i>dst</i> in network
|
|
byte order. It shall return 0 if the input is not a valid IPv4 dotted-decimal string <sup>[<a href=
|
|
"javascript:open_code('IP6')">IP6</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> or a valid
|
|
IPv6 address string, <img src="../images/opt-end.gif" alt="[Option End]" border="0"> or -1 with <i>errno</i> set to [EAFNOSUPPORT]
|
|
if the <i>af</i> argument is unknown.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_279_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>inet_ntop</i>() and <i>inet_pton</i>() functions shall fail if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EAFNOSUPPORT]</dt>
|
|
|
|
<dd><br>
|
|
The <i>af</i> argument is invalid.</dd>
|
|
|
|
<dt>[ENOSPC]</dt>
|
|
|
|
<dd>The size of the <i>inet_ntop</i>() result buffer is inadequate.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_279_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_279_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_279_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_279_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_279_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p>The Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/arpa/inet.h.html"><i><arpa/inet.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_279_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 6. Derived from the XNS, Issue 5.2 specification.</p>
|
|
|
|
<p>IPv6 extensions are marked.</p>
|
|
|
|
<p>The <b>restrict</b> keyword is added to the <i>inet_ntop</i>() and <i>inet_pton</i>() prototypes for alignment with the
|
|
ISO/IEC 9899:1999 standard.</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>
|
|
|