ibm-information-center/dist/eclipse/plugins/i5OS.ic.apis_5.4.0.1/netdir_getbyname.htm

285 lines
7.5 KiB
HTML
Raw Permalink Normal View History

2024-04-02 14:02:31 +00:00
<!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>netdir_getbyname()--Translate a Given Host-Service Pair</title>
<!-- Begin Header Records -->
<!-- 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. -->
<!-- Change History: -->
<!-- YYMMDD USERID Change description -->
<!-- RPCMST SCRIPT A converted by B2H R4.1 (346) (CMS) by PMHALL at -->
<!-- RCHVMW2 on 7 Oct 1998 at 23:43:14 -->
<!-- End Header Records -->
<!-- Edited by Kersten Feb 02 -->
<link rel="stylesheet" type="text/css" href="../rzahg/ic.css">
</head>
<body>
<!--Java sync-link-->
<script language="Javascript" src="../rzahg/synch.js" type="text/javascript">
</script>
<a name="Top_Of_Page"></a>
<h2>netdir_getbyname()--Translate a Given Host-Service Pair</h2>
<div class="box" style="width: 60%;">
<br>
&nbsp;&nbsp;Syntax<br>
<!-- iddvc RMBR -->
<br>
<pre>
#include &lt;netdir.h&gt;
int netdir_getbyname(struct netconfig *nconf,
struct nd_hostserv *service,
struct nd_addrlist **addrs);
</pre>
<br>
&nbsp;&nbsp;Service Program Name: QZNFTRPC<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Default Public Authority: *USE<br>
<!-- iddvc RMBR -->
<br>
&nbsp;&nbsp;Threadsafe: No<br>
<!-- iddvc RMBR -->
<br>
</div>
<p>The <strong>netdir_getbyname()</strong> function maps the host name and
service name that are specified in the <em>service</em> parameter to a set of
addresses that are consistent with the transport identified in the
<em>netconfig</em> structure.</p>
<br>
<h3>Parameters</h3>
<dl>
<dt><strong>nconf</strong> &nbsp;(Input)&nbsp;</dt>
<dd>A pointer to a netconfig structure that is returned by either
<strong>getnetconfig()</strong> or <strong>getnetconfigent()</strong>.<br>
<br>
</dd>
<dt><strong>service</strong> &nbsp;(Input)&nbsp;</dt>
<dd>A pointer to a service name.<br>
<br>
</dd>
<dt><strong>addrs</strong> &nbsp;(Output)&nbsp;</dt>
<dd>A pointer to the addresses being returned.</dd>
</dl>
<br>
<h3>Authorities</h3>
<p>No authorization is required.</p>
<br>
<h3>Return Value</h3>
<table cellpadding="5">
<!-- cols="5 95" -->
<tr>
<td align="left" valign="top"><em>0</em></td>
<td align="left" valign="top"><strong>netdir_getbyname()</strong> was successful.</td>
</tr>
<tr>
<td align="left" valign="top"><em>-1</em></td>
<td align="left" valign="top"><strong>netdir_getbyname()</strong> was not successful. The
<em>nd_errno</em> (defined in <strong>&lt;netdir.h&gt;</strong>) is set to
indicate the error.</td>
</tr>
</table>
<br>
<br>
<h3>Error Conditions</h3>
<p>If <strong>netdir_getbyname()</strong> is not successful, <em>nd_errno</em>
usually indicates one of the following errors:</p>
<table cellpadding="5">
<!-- cols="25 75" -->
<tr>
<td align="left" valign="top"><em>[ND_BADARG]</em></td>
<td align="left" valign="top">Bad argument passed.</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ND_NOHOST]</em></td>
<td align="left" valign="top">The host that was specified by the host name was not
found.</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ND_NOMEM]</em></td>
<td align="left" valign="top">Not enough memory left.</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ND_NO_RECOVERY]</em></td>
<td align="left" valign="top">An unrecoverable error has occurred.</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ND_NOSERV]</em></td>
<td align="left" valign="top">Service name is unknown.</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ND_SYSTEM]</em></td>
<td align="left" valign="top">A damaged object was encountered. The damaged object cannot be
used.</td>
</tr>
<tr>
<td align="left" valign="top"><em>[ND_TRY_AGAIN]</em></td>
<td align="left" valign="top">The local server did not receive a response from an
authoritative server. An attempt at a later time may succeed.</td>
</tr>
</table>
<br>
<br>
<h3>Error Messages</h3>
<table width="100%" cellpadding="5">
<!-- cols="15 85" -->
<tr>
<th align="left" valign="top">Message ID</th>
<th align="left" valign="top">Error Message Text</th>
</tr>
<tr>
<td width="15%" valign="top">CPF9872 E</td>
<td width="85%" valign="top">Program or service program &amp;1 in library &amp;2 ended.
Reason code &amp;3.</td>
</tr>
</table>
<br>
<br>
<h3>Usage Notes</h3>
<p><strong>netdir_getbyname()</strong> maps the host and service name to a set
of addresses consistent with the transport specified in <em>netconfig</em>.</p>
<p>The caller is responsible to free the storage allocated by
<strong>netdir_getbyname()</strong> by using the function
<strong>netdir_free()</strong>.</p>
<p><strong>netdir_getbyname()</strong> does not support HOST_ANY or
HOST_BROADCAST for host names specified in the <em>nd_hostserv</em>
structure.</p>
<br>
<h3>Example</h3>
<p>See <a href="../apiref/aboutapis.htm#codedisclaimer">Code disclaimer information</a>
for information pertaining to code examples.</p>
<p>The following example shows how <strong>netdir_getbyname()</strong> is
used:</p>
<pre>
#include &lt;netdir.h&gt;
main()
{
void *handlep; /* A handle into network selection */
struct netconfig *nconf; /* transport information */
struct nd_hostserv nd_hostserv; /* host and service information */
struct nd_addrlist *nd_addrlistp; /* addresses for the service */
/* Initialize the network selection mechanism */
if (handlep = setnetconfig()) == (void *)NULL)
{
exit(1);
}
/* Get the netconfig handle */
if ((nconf = getnetconfig(handlep)) == (struct netconf *)NULL)
{
printf(&quot;Error in getting the netconfig handle.\n&quot;);
exit(1);
}
/* Allocate memory for host and service names */
nd_hostserv.h_host = (char *)malloc(24);
nd_hostserv.h_serv = (char *)malloc(24);
if ((nd_hostserv.h_host == (char *)NULL)
|| (nd_hostserv.h_serv == (char *)NULL))
{
printf(&quot;No memory available. <strong>netdir_getbyname()</strong>
failed.\n&quot;);
exit(1);
}
printf(&quot;Enter the hostname:\n&quot;);
scanf(&quot;%s&quot;, nd_hostserv.h_host);
printf(&quot;Enter the service name:\n&quot;);
scanf(&quot;%s&quot;, nd_hostserv.h_serv);
/* Get the address for the service on the host on the
* transport provider specified in the netconfig structure
*/
if (netdir_getbyname(nconf, &amp;nd_hostserv, &amp;nd_addrlistp)
!= ND_OK)
{
printf(&quot;Cannot determine address for service\n&quot;);
exit(1);
}
printf(&quot;The address of the &lt;%s&gt; service on host
&lt;%s&gt; was found.\n&quot;, nd_hostserv.h_serv,
nd_hostserv.h_host);
/* Free the netdir structure allocated by netdir_getbyname() */
netdir_free(nd_addrlistp, ND_ADDRLIST);
/* Release the netconfig handle allocated by set setnetconfig() */
endnetconfig(handlep);
}
</pre>
<br>
<hr>
API introduced: V4R2
<hr>
<table cellpadding="2" cellspacing="2" align="center">
<tr align="center">
<td valign="middle" align="center"><a href="#Top_Of_Page">Top</a> | <a href=
"rpc1.htm">Remote Procedure Call (RPC) APIs</a> | <a href="aplist.htm">APIs by
category</a></td>
</tr>
</table>
</body>
</html>