📄 gethostbyname.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-2004 IEEE and The Open Group, All Rights Reserved --><title>gethostbyaddr</title></head><body bgcolor="white"><script type="text/javascript" language="JavaScript" src="../jscript/codes.js"></script><basefont size="3"> <a name="gethostbyaddr"></a> <a name="tag_03_225"></a><!-- gethostbyaddr --> <!--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_03_225_01"></a>NAME</h4><blockquote>gethostbyaddr, gethostbyname - network host database functions</blockquote><h4><a name="tag_03_225_02"></a>SYNOPSIS</h4><blockquote class="synopsis"><p><code><tt>#include <<a href="../basedefs/netdb.h.html">netdb.h</a>><br><br></tt></code></p><div class="box"><code><tt><sup>[<a href="javascript:open_code('OB')">OB</a>]</sup> <img src="../images/opt-start.gif" alt="[Option Start]" border="0"> struct hostent *gethostbyaddr(const void *</tt><i>addr</i><tt>, socklen_t</tt> <i>len</i><tt>,<br> int</tt> <i>type</i><tt>);<br> struct hostent *gethostbyname(const char *</tt><i>name</i><tt>); <img src="../images/opt-end.gif" alt="[Option End]" border="0"></tt></code></div><tt><br></tt></blockquote><h4><a name="tag_03_225_03"></a>DESCRIPTION</h4><blockquote><p>These functions shall retrieve information about hosts. This information is considered to be stored in a database that can beaccessed sequentially or randomly. Implementation of this database is unspecified. <basefont size="2"></p><dl><dt><b>Note:</b></dt><dd>In many cases it is implemented by the Domain Name System, as documented in RFC 1034, RFC 1035, andRFC 1886.</dd></dl><basefont size="3"> <p>Entries shall be returned in <b>hostent</b> structures.</p><p>The <i>gethostbyaddr</i>() function shall return an entry containing addresses of address family <i>type</i> for the host withaddress <i>addr</i>. The <i>len</i> argument contains the length of the address pointed to by <i>addr</i>. The<i>gethostbyaddr</i>() function need not be reentrant. A function that is not required to be reentrant is not required to bethread-safe.</p><p>The <i>gethostbyname</i>() function shall return an entry containing addresses of address family AF_INET for the host with name<i>name</i>. The <i>gethostbyname</i>() function need not be reentrant. A function that is not required to be reentrant is notrequired to be thread-safe.</p><p>The <i>addr</i> argument of <i>gethostbyaddr</i>() shall be an <b>in_addr</b> structure when <i>type</i> is AF_INET. It containsa binary format (that is, not null-terminated) address in network byte order. The <i>gethostbyaddr</i>() function is not guaranteedto return addresses of address families other than AF_INET, even when such addresses exist in the database.</p><p>If <i>gethostbyaddr</i>() returns successfully, then the <i>h_addrtype</i> field in the result shall be the same as the<i>type</i> argument that was passed to the function, and the <i>h_addr_list</i> field shall list a single address that is a copyof the <i>addr</i> argument that was passed to the function.</p><p>The <i>name</i> argument of <i>gethostbyname</i>() shall be a node name; the behavior of <i>gethostbyname</i>() when passed anumeric address string is unspecified. For IPv4, a numeric address string shall be in the dotted-decimal notation described in <ahref="inet_addr.html"><i>inet_addr</i>()</a>.</p><p>If <i>name</i> is not a numeric address string and is an alias for a valid host name, then <i>gethostbyname</i>() shall returninformation about the host name to which the alias refers, and <i>name</i> shall be included in the list of aliases returned.</p></blockquote><h4><a name="tag_03_225_04"></a>RETURN VALUE</h4><blockquote><p>Upon successful completion, these functions shall return a pointer to a <b>hostent</b> structure if the requested entry wasfound, and a null pointer if the end of the database was reached or the requested entry was not found.</p><p>Upon unsuccessful completion, <i>gethostbyaddr</i>() and <i>gethostbyname</i>() shall set <i>h_errno</i> to indicate theerror.</p></blockquote><h4><a name="tag_03_225_05"></a>ERRORS</h4><blockquote><p>These functions shall fail in the following cases. The <i>gethostbyaddr</i>() and <i>gethostbyname</i>() functions shall set<i>h_errno</i> to the value shown in the list below. Any changes to <i>errno</i> are unspecified.</p><dl compact><dt>[HOST_NOT_FOUND]</dt><dd>No such host is known.</dd><dt>[NO_DATA]</dt><dd>The server recognized the request and the name, but no address is available. Another type of request to the name server for thedomain might return an answer.</dd><dt>[NO_RECOVERY]</dt><dd>An unexpected server failure occurred which cannot be recovered.</dd><dt>[TRY_AGAIN]</dt><dd>A temporary and possibly transient error occurred, such as a failure of a server to respond.</dd></dl></blockquote><hr><div class="box"><em>The following sections are informative.</em></div><h4><a name="tag_03_225_06"></a>EXAMPLES</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_225_07"></a>APPLICATION USAGE</h4><blockquote><p>The <i>gethostbyaddr</i>() and <i>gethostbyname</i>() functions may return pointers to static data, which may be overwritten bysubsequent calls to any of these functions.</p><p>The <a href="../functions/getaddrinfo.html"><i>getaddrinfo</i>()</a> and <a href="../functions/getnameinfo.html"><i>getnameinfo</i>()</a> functions are preferred over the <i>gethostbyaddr</i>() and<i>gethostbyname</i>() functions.</p></blockquote><h4><a name="tag_03_225_08"></a>RATIONALE</h4><blockquote><p>None.</p></blockquote><h4><a name="tag_03_225_09"></a>FUTURE DIRECTIONS</h4><blockquote><p>The <i>gethostbyaddr</i>() and <i>gethostbyname</i>() functions may be withdrawn in a future version.</p></blockquote><h4><a name="tag_03_225_10"></a>SEE ALSO</h4><blockquote><p><a href="endhostent.html"><i>endhostent</i>()</a>, <a href="endservent.html"><i>endservent</i>()</a>, <a href="gai_strerror.html"><i>gai_strerror</i>()</a>, <a href="getaddrinfo.html"><i>getaddrinfo</i>()</a>, <a href="h_errno.html"><i>h_errno</i>()</a>, <a href="inet_addr.html"><i>inet_addr</i>()</a>, the Base Definitions volume ofIEEE Std 1003.1-2001, <a href="../basedefs/netdb.h.html"><i><netdb.h></i></a></p></blockquote><h4><a name="tag_03_225_11"></a>CHANGE HISTORY</h4><blockquote><p>First released in Issue 6. Derived from the XNS, Issue 5.2 specification.</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 + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -