netdir_getbyname()--Translate a Given Host-Service Pair


  Syntax

 #include <netdir.h>

 int netdir_getbyname(struct netconfig *nconf,
                      struct nd_hostserv *service,
                      struct nd_addrlist **addrs);
 

  Service Program Name: QZNFTRPC

  Default Public Authority: *USE

  Threadsafe: No

The netdir_getbyname() function maps the host name and service name that are specified in the service parameter to a set of addresses that are consistent with the transport identified in the netconfig structure.


Parameters

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

service  (Input) 
A pointer to a service name.

addrs  (Output) 
A pointer to the addresses being returned.

Authorities

No authorization is required.


Return Value

0 netdir_getbyname() was successful.
-1 netdir_getbyname() was not successful. The nd_errno (defined in <netdir.h>) is set to indicate the error.


Error Conditions

If netdir_getbyname() is not successful, nd_errno usually indicates one of the following errors:

[ND_BADARG] Bad argument passed.
[ND_NOHOST] The host that was specified by the host name was not found.
[ND_NOMEM] Not enough memory left.
[ND_NO_RECOVERY] An unrecoverable error has occurred.
[ND_NOSERV] Service name is unknown.
[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_getbyname() maps the host and service name to a set of addresses consistent with the transport specified in netconfig.

The caller is responsible to free the storage allocated by netdir_getbyname() by using the function netdir_free().

netdir_getbyname() does not support HOST_ANY or HOST_BROADCAST for host names specified in the nd_hostserv structure.


Example

The following example shows how netdir_getbyname() is used.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#include <netdir.h>

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("Error in getting the netconfig handle.\n");
     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("No memory available.  netdir_getbyname()
     failed.\n");
     exit(1);
   }

   printf("Enter the hostname:\n");
   scanf("%s", nd_hostserv.h_host);
   printf("Enter the service name:\n");
   scanf("%s", 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, &nd_hostserv, &nd_addrlistp)
      != ND_OK)
   {
      printf("Cannot determine address for service\n");
      exit(1);
   }
   printf("The address of the <%s> service on host
          <%s> was found.\n", 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);
}



API introduced: V4R2

[ Back to top | Remote Procedure Call (RPC) APIs | APIs by category ]