#include <netdir.h>
int netdir_getbyaddr(struct netconfig *nconf,
struct nd_hostservlist
**service,
struct netbuf *netaddr);
The netdir_getbyaddr() function maps addresses into host names and service names.
No authorization is required.
| 0 | netdir_getbyaddr() was successful. A list of host names and service name pairs is returned in service. |
| -1 | netdir_getbyaddr() was not successful. The nd_errno (defined in <netdir.h>) is set to indicate the error. |
If netdir_getbyaddr() is not successful, nd_errno usually indicates one of the following errors:
| [ND_BADARG] | Bad argument passed. |
| [ND_NO_DATA] | The host name is a valid name but there is no corresponding IP address. |
| [ND_NOHOST] | The host name that the user specified by the host address was not found. |
| [ND_NOMEM] | Not enough memory left. |
| [ND_NO_RECOVERY] | An unrecoverable error has occurred. |
| [ND_SYSTEM] | A damaged object was encountered. The damaged object cannot be used. |
| [ND_TRY_AGAIN] | The local server did not receive a response from an authoritative server. An attempt at a later time may succeed. |
| Message ID | Error Message Text |
|---|---|
| CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
netdir_getbyaddr() is called with an address in the netaddr structure.
The caller is responsible to free the storage allocated by netdir_getbyaddr() by using the function netdir_free().
See Code disclaimer information for information pertaining to code examples.
The following example shows how netdir_getbyaddr() is used:
#include <netdir.h>
void findhost(void)
{
void *handlep;
struct netconfig *nconf;
struct nd_hostservlist *nd_hostserv;
struct netbuf nbuf;
char uaddr[16];
/* Initialize the network selection mechanism */
if (handlep = setnetconfig()) == (void *)NULL)
{
exit(1);
}
/* Get the netconfig handle */
if ((nconf = getnetconfig(handlep)) == (struct netconf *)NULL)
{
printf("Error getting the netconfig handle\n");
exit(1);
}
memset(uaddr, NULL, 16);
printf("Enter the host IP address appended by low and high order
port numbers:\n");
scanf("%s", uaddr);
/* Convert universal address notation into transport-specific
* address format.
*/
nbuf = uaddr2taddr(nconf, uaddr);
/* Get the hostname from the address over the transport */
/* provider specified in the netconfig structure */
if (netdir_getbyaddr(nconf, &nd_hostserv, &nbuf)
!= ND_OK)
{
printf("Cannot determine the host\n");
exit(1);
}
printf("The host name is: %s\n",
nd_hostserv->h_hostservs->h_host);
printf("The Service is: %s\n", nd_hostserv->h_hostservs->h_serv);
/* Free the netdir structure allocated by netdir_getbyname() */
netdir_free(nd_hostserv, ND_HOSTSERVLIST);
/* Release the netconfig handle allocated by set setnetconfig() */
endnetconfig(handlep);
}
| Top | Remote Procedure Call (RPC) APIs | APIs by category |