netdir_getbyaddr()--Translate a Netbuf Address to a Host


  Syntax

 #include <netdir.h>

 int netdir_getbyaddr(struct netconfig *nconf,
                      struct nd_hostservlist
                           **service,
                      struct netbuf *netaddr);

  Service Program Name: QZNFTRPC

  Default Public Authority: *USE

  Threadsafe: No

The netdir_getbyaddr() function maps addresses into host names and service names.


Parameters

nconf  (Input) 
A pointer to a netconfig structure that is returned by either getnetconfig() or getnetconfigent().

service  (Output) 
A pointer to a list of service names.

netaddr  (Input) 
A pointer to the address.

Authorities

No authorization is required.


Return Value

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.


Error Conditions

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.


Error Messages

Message ID Error Message Text
CPF9872 E Program or service program &1 in library &2 ended. Reason code &3.


Usage Notes

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().


Example

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);
}



API introduced: V4R2
Top | Remote Procedure Call (RPC) APIs | APIs by category