241 lines
8.7 KiB
HTML
241 lines
8.7 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>getnameinfo</title>
|
|
</head>
|
|
<body bgcolor="white">
|
|
<script type="text/javascript" language="JavaScript" src="../jscript/codes.js">
|
|
</script>
|
|
|
|
<basefont size="3"> <a name="getnameinfo"></a> <a name="tag_03_232"></a><!-- getnameinfo -->
|
|
<!--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_232_01"></a>NAME</h4>
|
|
|
|
<blockquote>getnameinfo - get name information</blockquote>
|
|
|
|
<h4><a name="tag_03_232_02"></a>SYNOPSIS</h4>
|
|
|
|
<blockquote class="synopsis">
|
|
<p><code><tt>#include <<a href="../basedefs/sys/socket.h.html">sys/socket.h</a>><br>
|
|
#include <<a href="../basedefs/netdb.h.html">netdb.h</a>><br>
|
|
<br>
|
|
int getnameinfo(const struct sockaddr *restrict</tt> <i>sa</i><tt>, socklen_t</tt> <i>salen</i><tt>,<br>
|
|
char *restrict</tt> <i>node</i><tt>, socklen_t</tt> <i>nodelen</i><tt>, char *restrict</tt>
|
|
<i>service</i><tt>,<br>
|
|
socklen_t</tt> <i>servicelen</i><tt>, unsigned</tt> <i>flags</i><tt>);<br>
|
|
</tt></code></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_232_03"></a>DESCRIPTION</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>getnameinfo</i>() function shall translate a socket address to a node name and service location, all of which are defined
|
|
as in <a href="getaddrinfo.html"><i>getaddrinfo</i>()</a> .</p>
|
|
|
|
<p>The <i>sa</i> argument points to a socket address structure to be translated.</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 socket address structure contains an IPv4-mapped IPv6 address or an IPv4-compatible IPv6 address, the implementation shall
|
|
extract the embedded IPv4 address and lookup the node name for that IPv4 address. <img src="../images/opt-end.gif" alt=
|
|
"[Option End]" border="0"> <basefont size="2"></p>
|
|
|
|
<dl>
|
|
<dt><b>Note:</b></dt>
|
|
|
|
<dd>The IPv6 unspecified address ( <tt>"::"</tt> ) and the IPv6 loopback address ( <tt>"::1"</tt> ) are not IPv4-compatible
|
|
addresses. If the address is the IPv6 unspecified address ( <tt>"::"</tt> ), a lookup is not performed, and the [EAI_NONAME] error
|
|
is returned.</dd>
|
|
</dl>
|
|
|
|
<basefont size="3">
|
|
|
|
<p>If the <i>node</i> argument is non-NULL and the <i>nodelen</i> argument is non-zero, then the <i>node</i> argument points to a
|
|
buffer able to contain up to <i>nodelen</i> characters that receives the node name as a null-terminated string. If the <i>node</i>
|
|
argument is NULL or the <i>nodelen</i> argument is zero, the node name shall not be returned. If the node's name cannot be located,
|
|
the numeric form of the node's address is returned instead of its name.</p>
|
|
|
|
<p>If the <i>service</i> argument is non-NULL and the <i>servicelen</i> argument is non-zero, then the <i>service</i> argument
|
|
points to a buffer able to contain up to <i>servicelen</i> bytes that receives the service name as a null-terminated string. If the
|
|
<i>service</i> argument is NULL or the <i>servicelen</i> argument is zero, the service name shall not be returned. If the service's
|
|
name cannot be located, the numeric form of the service address (for example, its port number) shall be returned instead of its
|
|
name.</p>
|
|
|
|
<p>The <i>flags</i> argument is a flag that changes the default actions of the function. By default the fully-qualified domain name
|
|
(FQDN) for the host shall be returned, but:</p>
|
|
|
|
<ul>
|
|
<li>
|
|
<p>If the flag bit NI_NOFQDN is set, only the node name portion of the FQDN shall be returned for local hosts.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If the flag bit NI_NUMERICHOST is set, the numeric form of the host's address shall be returned instead of its name, under all
|
|
circumstances.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If the flag bit NI_NAMEREQD is set, an error shall be returned if the host's name cannot be located.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If the flag bit NI_NUMERICSERV is set, the numeric form of the service address shall be returned (for example, its port number)
|
|
instead of its name, under all circumstances.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>If the flag bit NI_DGRAM is set, this indicates that the service is a datagram service (SOCK_DGRAM). The default behavior shall
|
|
assume that the service is a stream service (SOCK_STREAM).</p>
|
|
</li>
|
|
</ul>
|
|
|
|
<basefont size="2">
|
|
|
|
<dl>
|
|
<dt><b>Notes:</b></dt>
|
|
|
|
<dd>
|
|
<ol>
|
|
<li>
|
|
<p>The two NI_NUMERICxxx flags are required to support the <b>-n</b> flag that many commands provide.</p>
|
|
</li>
|
|
|
|
<li>
|
|
<p>The NI_DGRAM flag is required for the few AF_INET and AF_INET6 port numbers (for example, [512,514]) that represent different
|
|
services for UDP and TCP.</p>
|
|
</li>
|
|
</ol>
|
|
</dd>
|
|
</dl>
|
|
|
|
<basefont size="3">
|
|
|
|
<p>The <i>getnameinfo</i>() function shall be thread-safe.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_232_04"></a>RETURN VALUE</h4>
|
|
|
|
<blockquote>
|
|
<p>A zero return value for <i>getnameinfo</i>() indicates successful completion; a non-zero return value indicates failure. The
|
|
possible values for the failures are listed in the ERRORS section.</p>
|
|
|
|
<p>Upon successful completion, <i>getnameinfo</i>() shall return the <i>node</i> and <i>service</i> names, if requested, in the
|
|
buffers provided. The returned names are always null-terminated strings.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_232_05"></a>ERRORS</h4>
|
|
|
|
<blockquote>
|
|
<p>The <i>getnameinfo</i>() function shall fail and return the corresponding value if:</p>
|
|
|
|
<dl compact>
|
|
<dt>[EAI_AGAIN]</dt>
|
|
|
|
<dd>The name could not be resolved at this time. Future attempts may succeed.</dd>
|
|
|
|
<dt>[EAI_BADFLAGS]</dt>
|
|
|
|
<dd><br>
|
|
The <i>flags</i> had an invalid value.</dd>
|
|
|
|
<dt>[EAI_FAIL]</dt>
|
|
|
|
<dd>A non-recoverable error occurred.</dd>
|
|
|
|
<dt>[EAI_FAMILY]</dt>
|
|
|
|
<dd>The address family was not recognized or the address length was invalid for the specified family.</dd>
|
|
|
|
<dt>[EAI_MEMORY]</dt>
|
|
|
|
<dd>There was a memory allocation failure.</dd>
|
|
|
|
<dt>[EAI_NONAME]</dt>
|
|
|
|
<dd>The name does not resolve for the supplied parameters.
|
|
|
|
<p>NI_NAMEREQD is set and the host's name cannot be located, or both <i>nodename</i> and <i>servname</i> were null.</p>
|
|
</dd>
|
|
|
|
<dt>[EAI_SYSTEM]</dt>
|
|
|
|
<dd>A system error occurred. The error code can be found in <i>errno</i>.</dd>
|
|
</dl>
|
|
</blockquote>
|
|
|
|
<hr>
|
|
<div class="box"><em>The following sections are informative.</em></div>
|
|
|
|
<h4><a name="tag_03_232_06"></a>EXAMPLES</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_232_07"></a>APPLICATION USAGE</h4>
|
|
|
|
<blockquote>
|
|
<p>If the returned values are to be used as part of any further name resolution (for example, passed to <a href=
|
|
"../functions/getaddrinfo.html"><i>getaddrinfo</i>()</a>), applications should provide buffers large enough to store any result
|
|
possible on the system.</p>
|
|
|
|
<p>Given the IPv4-mapped IPv6 address <tt>"::ffff:1.2.3.4"</tt> , the implementation performs a lookup as if the socket address
|
|
structure contains the IPv4 address <tt>"1.2.3.4"</tt> .</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_232_08"></a>RATIONALE</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_232_09"></a>FUTURE DIRECTIONS</h4>
|
|
|
|
<blockquote>
|
|
<p>None.</p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_232_10"></a>SEE ALSO</h4>
|
|
|
|
<blockquote>
|
|
<p><a href="gai_strerror.html"><i>gai_strerror</i>()</a> , <a href="getaddrinfo.html"><i>getaddrinfo</i>()</a> , <a href=
|
|
"getservbyname.html"><i>getservbyname</i>()</a> , <a href="inet_ntop.html"><i>inet_ntop</i>()</a> , <a href=
|
|
"socket.html"><i>socket</i>()</a> , the Base Definitions volume of IEEE Std 1003.1-2001, <a href=
|
|
"../basedefs/netdb.h.html"><i><netdb.h></i></a>, <a href="../basedefs/sys/socket.h.html"><i><sys/socket.h></i></a></p>
|
|
</blockquote>
|
|
|
|
<h4><a name="tag_03_232_11"></a>CHANGE HISTORY</h4>
|
|
|
|
<blockquote>
|
|
<p>First released in Issue 6. Derived from the XNS, Issue 5.2 specification.</p>
|
|
|
|
<p>The <b>restrict</b> keyword is added to the <i>getnameinfo</i>() prototype 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>
|
|
|