372 lines
11 KiB
HTML
372 lines
11 KiB
HTML
|
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
|
||
|
<html>
|
||
|
<head>
|
||
|
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
|
||
|
<meta name="Copyright" content="Copyright (c) 2006 by IBM Corporation">
|
||
|
<title>gethostbyname_r()--Get Host Information for Host Name</title>
|
||
|
<!-- All rights reserved. Licensed Materials Property of IBM -->
|
||
|
<!-- US Government Users Restricted Rights -->
|
||
|
<!-- Use, duplication or disclosure restricted by -->
|
||
|
<!-- GSA ADP Schedule Contract with IBM Corp. -->
|
||
|
<!-- Begin Header Records ========================================== -->
|
||
|
<!-- Unix8 SCRIPT J converted by B2H R4.1 (346) (CMS) by V2KEA304 -->
|
||
|
<!-- at RCHVMW2 on 17 Feb 1999 at 11:05:09 -->
|
||
|
<!--End Header Records -->
|
||
|
<!-- Edited by Kersten Feb 02 -->
|
||
|
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
|
||
|
</head>
|
||
|
<body>
|
||
|
<a name="Top_Of_Page"></a>
|
||
|
<!-- Java sync-link -->
|
||
|
<script type="text/javascript" language="Javascript" src="../rzahg/synch.js">
|
||
|
</script>
|
||
|
|
||
|
<h2>gethostbyname_r()--Get Host Information for Host Name</h2>
|
||
|
|
||
|
<div class="box" style="width: 65%;">
|
||
|
<br>
|
||
|
BSD 4.3 Syntax<br>
|
||
|
<pre>
|
||
|
#include <netdb.h>
|
||
|
|
||
|
int gethostbyname_r(char *<em>host_name</em>,
|
||
|
struct hostent *<em>hostent_struct_addr</em>,
|
||
|
struct hostent_data *<em>hostent_data_struct_addr</em>)
|
||
|
</pre>
|
||
|
|
||
|
<br>
|
||
|
Service Program Name: QSOSRV2<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Default Public Authority: *USE<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Threadsafe: Yes<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
</div>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<div class="box" style="width: 65%;">
|
||
|
<br>
|
||
|
<a href="_xopen_source.htm">UNIX 98 Compatible Syntax</a><br>
|
||
|
<pre>
|
||
|
#define _XOPEN_SOURCE 520
|
||
|
#include <netdb.h>
|
||
|
|
||
|
int gethostbyname_r(const char *<em>host_name</em>,
|
||
|
struct hostent *<em>hostent_struct_addr</em>,
|
||
|
struct hostent_data *<em>hostent_data_struct_addr</em>)
|
||
|
</pre>
|
||
|
|
||
|
<br>
|
||
|
Service Program Name: QSOSRV2<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Default Public Authority: *USE<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
Threadsafe: Yes<br>
|
||
|
<!-- iddvc RMBR -->
|
||
|
<br>
|
||
|
</div>
|
||
|
|
||
|
<br>
|
||
|
<p>The <em>gethostbyname_r()</em> function is used to retrieve information
|
||
|
about a host.</p>
|
||
|
|
||
|
<p>There are two versions of the API, as shown above. The base i5/OS API uses
|
||
|
BSD 4.3 structures and syntax. The other uses syntax and structures compatible
|
||
|
with the UNIX 98 programming interface specifications. You can select the UNIX
|
||
|
98 compatible interface with the <a href="_xopen_source.htm">_XOPEN_SOURCE</a>
|
||
|
macro.</p>
|
||
|
|
||
|
<br>
|
||
|
<h3>Parameters</h3>
|
||
|
|
||
|
<dl>
|
||
|
<dt><strong>host_name</strong> (input) </dt>
|
||
|
|
||
|
<dd>Specifies the pointer to the character string that contains the name of the
|
||
|
host for which information is to be retrieved.<br>
|
||
|
<br>
|
||
|
</dd>
|
||
|
|
||
|
<dt><strong>hostent_struct_addr</strong> (input/output) </dt>
|
||
|
|
||
|
<dd>Specifies the pointer to a hostent structure where the results will be
|
||
|
placed. All results must be referenced through this structure.<br>
|
||
|
<br>
|
||
|
</dd>
|
||
|
|
||
|
<dt><strong>hostent_data_struct_addr</strong> (input/output) </dt>
|
||
|
|
||
|
<dd>Specifies the pointer to the hostent_data structure, which is used to pass
|
||
|
and preserve results between function calls. The field host_control_blk in the
|
||
|
hostent_data structure must be initialized with hexadecimal zeros before its
|
||
|
initial use. If compatibility with other platforms is required, then the entire
|
||
|
hostent_data structure must be initialized with hexadecimal zeros before
|
||
|
initial use.</dd>
|
||
|
</dl>
|
||
|
|
||
|
<br>
|
||
|
<h3>Authorities:</h3>
|
||
|
|
||
|
<p>Authorization of *R (allow access to the object) to the host aliases file
|
||
|
specified by the <em>hostaliases</em> environment variable.</p>
|
||
|
|
||
|
<p>You also need *X authority to each directory in the path of the host aliases
|
||
|
file.</p>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<h3>Return Value</h3>
|
||
|
|
||
|
<p>The <em>gethostbyname_r()</em> function returns an integer. Possible values
|
||
|
are:</p>
|
||
|
|
||
|
<ul>
|
||
|
<li>-1 (unsuccessful call)</li>
|
||
|
|
||
|
<li>0 (successful call)</li>
|
||
|
</ul>
|
||
|
|
||
|
<p>The <strong>struct hostent</strong> denoted by <strong><em>
|
||
|
hostent_struct_addr</em></strong> and <strong>struct
|
||
|
hostent_data</strong>denoted by <strong><em>
|
||
|
hostent_data_struct_addr</em></strong> are both defined in <strong>
|
||
|
<netdb.h></strong>. The structure <strong>struct hostent</strong>is
|
||
|
defined as:</p>
|
||
|
|
||
|
<pre>
|
||
|
struct hostent [
|
||
|
char *h_name;
|
||
|
char **h_aliases;
|
||
|
int h_addrtype;
|
||
|
int h_length;
|
||
|
char **h_addr_list;
|
||
|
];
|
||
|
|
||
|
#define h_addr h_addr_list[0]
|
||
|
</pre>
|
||
|
|
||
|
<p><em>h_name</em> points to the character string that contains the name of the
|
||
|
host. <em>h_aliases</em> is a pointer to a NULL-terminated list of pointers,
|
||
|
each of which points to a character string that represents an alternative name
|
||
|
for the host. <em>h_addrtype</em> contains the address type of the host (for
|
||
|
example, <samp>af_inet</samp>). <em>h_length</em> contains the size of an
|
||
|
address in octets (for example, the size of an Internet address is 4 octets).
|
||
|
<em>h_addr_list</em> is a pointer to a NULL-terminated list of pointers, each
|
||
|
of which points to a network address (in network byte order) for the host.</p>
|
||
|
|
||
|
<br>
|
||
|
<h3>Error Conditions</h3>
|
||
|
|
||
|
<p>When the <em>gethostbyname_r()</em> function fails, <em>h_errno</em>
|
||
|
(defined in <strong><netdb.h></strong>) can be set to:</p>
|
||
|
|
||
|
<dl>
|
||
|
<dt><em>[HOST_NOT_FOUND]</em></dt>
|
||
|
|
||
|
<dd>
|
||
|
<p>The host name specified by the <em>host_name</em> parameter was not
|
||
|
found.</p>
|
||
|
</dd>
|
||
|
|
||
|
<dt><em>[NO_DATA]</em></dt>
|
||
|
|
||
|
<dd>
|
||
|
<p>The host name is a valid name, but there is no corresponding IP address.</p>
|
||
|
</dd>
|
||
|
|
||
|
<dt><em>[NO_RECOVERY]</em></dt>
|
||
|
|
||
|
<dd>
|
||
|
<p>An unrecoverable error has occurred.</p>
|
||
|
</dd>
|
||
|
|
||
|
<dt><em>[TRY_AGAIN]</em></dt>
|
||
|
|
||
|
<dd>
|
||
|
<p>The local server did not receive a response from an authoritative server. An
|
||
|
attempt at a later time may succeed.</p>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
|
||
|
<p>When the <em>gethostbyname_r()</em> function fails, <em>errno</em> can be
|
||
|
set to:</p>
|
||
|
|
||
|
<dl>
|
||
|
<dt><em>[EACCES]</em></dt>
|
||
|
|
||
|
<dd>
|
||
|
<p>Permission denied. The process does not have the appropriate privileges to
|
||
|
the host aliases file specified by the <em>HOSTALIASES</em> environment
|
||
|
variable.</p>
|
||
|
</dd>
|
||
|
|
||
|
<dt><em>[EINVAL]</em></dt>
|
||
|
|
||
|
<dd>
|
||
|
<p>The hostent_data structure was not initialized with hexadecimal zeros before
|
||
|
initial use. For corrective action, see the description for structure
|
||
|
hostent_data.</p>
|
||
|
</dd>
|
||
|
</dl>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<h3>Usage Notes</h3>
|
||
|
|
||
|
<ol>
|
||
|
<li>The iSeries Navigator or the following CL commands can be used to access
|
||
|
the host database file:<br>
|
||
|
<br>
|
||
|
<ul>
|
||
|
<li>ADDTCPHTE (Add TCP/IP Host Table Entry)</li>
|
||
|
|
||
|
<li>RMVTCPHTE (Remove TCP/IP Host Table Entry)</li>
|
||
|
|
||
|
<li>CHGTCPHTE (Change TCP/IP Host Table Entry)</li>
|
||
|
|
||
|
<li>RNMTCPHTE (Rename TCP/IP Host Table Entry)</li>
|
||
|
|
||
|
<li>MRGTCPHT (Merge TCP/IP Host Tables)</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>There are two sources from which host information can be obtained: the
|
||
|
domain name server and the host database file. The path taken depends on
|
||
|
whether an IP address is configured for a name server using the iSeries
|
||
|
Navigator or option 12, Change TCP/IP domain information, on the <strong>
|
||
|
CFGTCP</strong> menu.
|
||
|
|
||
|
<p><strong>Note:</strong> A person with a UNIX background would expect this
|
||
|
information to exist in a file known as <strong>/etc/resolv.conf</strong>. If
|
||
|
the IP address is found (indicating that the local network is a domain
|
||
|
network), the <em>gethostbyaddr_r()</em> function will attempt to query the
|
||
|
domain name server for information about a host. If the query fails, the
|
||
|
information will be obtained from the host database file. If the name server IP
|
||
|
address is not found (indicating that local network is a flat network), the
|
||
|
host database file is used to obtain the address.</p>
|
||
|
</li>
|
||
|
|
||
|
<li>If the <em>host_name</em> parameter does specify a domain qualified name,
|
||
|
the <em>gethostbyaddr_r()</em> function will append a domain name to the
|
||
|
specified host name, if possible. The domain name that will be appended is
|
||
|
configured using the iSeries Navigator or <strong>CFGTCP</strong> menu option
|
||
|
12, Change TCP/IP domain information.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>When the host information is obtained from the host database file, the file
|
||
|
is opened and the host information is retrieved (if it exists) from the file.
|
||
|
The file is then closed only if a <em>sethostent_r()</em> call with a non-zero
|
||
|
parameter value was not previously done.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>If a <em>sethostent_r()</em> call with a non-zero parameter value was
|
||
|
previously done, the <em>gethostbyname_r()</em> routine, when obtaining host
|
||
|
information from the domain name server, will communicate with the domain name
|
||
|
server over a connection-oriented transport service (for example, TCP).
|
||
|
Otherwise, <em>gethostbyname_r()</em> will use a connectionless transport
|
||
|
service (for example, UDP).<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>A job has a coded character set identifier (CCSID) and a default CCSID. The
|
||
|
default CCSID is the same as the job CCSID unless the job CCSID specifies
|
||
|
65535, which requests that no database translation be performed. In this case,
|
||
|
the default CCSID is set by the system based on the language ID in effect for
|
||
|
the job.
|
||
|
|
||
|
<p>If the host information is retrieved from the domain name server, sockets
|
||
|
converts the host name specified by the <em>host_name</em> parameter to ASCII
|
||
|
before communicating with the domain name server. If the host information is
|
||
|
retrieved from the host database file, no conversion is done on the host name
|
||
|
specified by the <em>host_name</em> parameter unless the CCSID of the job is
|
||
|
something other than 65535. In addition, host names returned in the hostent
|
||
|
will be returned in the default CCSID of the job if they are obtained from the
|
||
|
domain name server. For translation to occur for the host names returned in the
|
||
|
hostent structure when they are obtained from the host database file, you must
|
||
|
use a job CCSID of something other than 65535.</p>
|
||
|
</li>
|
||
|
|
||
|
<li>Address families are defined in <strong><sys/socket.h></strong>, and
|
||
|
the <strong>in_addr</strong> structure is defined in <strong>
|
||
|
<netinet/in.h></strong>.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><em>gethostbyname_r()</em> will resolve local host aliases to a domain name
|
||
|
which are then resolved with a query using DNS. See <a href="reshostalias.htm">
|
||
|
res_hostalias()</a> for more information on aliases.<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li>When you develop in C-based languages and an application is compiled with
|
||
|
the _XOPEN_SOURCE macro defined to the value 520 or greater, the <em>
|
||
|
gethostbyname_r()</em> API is mapped to <em>qso_gethostbyname_r98()</em>.</li>
|
||
|
</ol>
|
||
|
|
||
|
<br>
|
||
|
|
||
|
|
||
|
<h3>Related Information</h3>
|
||
|
|
||
|
<ul>
|
||
|
<li><a href="_xopen_source.htm">_XOPEN_SOURCE</a>--Using _XOPEN_SOURCE for the
|
||
|
UNIX 98 compatible interface<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="hstrerror.htm">hstrerror()</a>--Retrieve Resolver Error
|
||
|
Message<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="reshostalias.htm">res_hostalias()</a>--Retrieve the host alias<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="tsehoste.htm">endhostent_r()</a>--Close Host Database<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="tsghosta.htm">gethostbyaddr_r()</a>--Get Host Information for IP
|
||
|
Address<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="tsghoste.htm">gethostent_r()</a>--Get Next Entry from Host
|
||
|
Database<br>
|
||
|
<br>
|
||
|
</li>
|
||
|
|
||
|
<li><a href="tsshoste.htm">sethostent_r()</a>--Open Host Database</li>
|
||
|
</ul>
|
||
|
|
||
|
<br>
|
||
|
<hr>
|
||
|
API introduced: V3R1
|
||
|
|
||
|
<hr>
|
||
|
<center>
|
||
|
<table cellpadding="2" cellspacing="2">
|
||
|
<tr align="center">
|
||
|
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
|
||
|
"unix.htm">UNIX-Type APIs</a> | <a href="aplist.htm">APIs by category</a></td>
|
||
|
</tr>
|
||
|
</table>
|
||
|
</center>
|
||
|
</body>
|
||
|
</html>
|
||
|
|