taddr2uaddr()--Translate a Local Address


  Syntax

 #include <netdir.h>

 char *taddr2uaddr(struct netconfig *nconf,
                   struct netbuf *addr);

  Service Program Name: QZNFTRPC

  Default Public Authority: *USE

  Threadsafe: No

The taddr2uaddr() function translates a transport-specific (local) address to a transport-independent (universal) address.


Parameters

nconf  (Input) 
The transport for which the address is valid.

addr  (Input) 
The address to be translated to the universal representation.

Authorities

No authorization is required.


Return Value

universal address A string that contains the universal address is returned if the function taddr2uaddr() was successful.
NULL A NULL pointer is returned if the function taddr2uaddr() was not successful. The nd_errno global variable (defined in <netdir.h>) is set to indicate the error.


Error Conditions

If the function taddr2uaddr() is not successful, nd_errno usually indicates the following error:

[ND_BADARG] Bad argument passed.
[ND_SYSTEM] A damaged object was encountered. The damaged object cannot be used.


Error Messages

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


Usage Notes

taddr2uaddr() translates the address pointed to by addr and returns a transport independent character representation of the address (universal address).

The caller is responsible to free the returned universal address when done.


Example

The following example shows how taddr2uaddr() is used.

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

#include <netconfig.h>
#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 */
  struct netbuf *netbufp;              /* The address of the service */
  int i;                                  /* The number of addresses */
  char *uaddr;                          /* Service universal address */

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

   /* Get the address for service specified in nd_hostserv.h_serv
    * on the host specified in nd_hostserv.h_host over the
    * transport provider specified in the netconfig structure
    * Note: nd_hostserv.h_host and nd_hostserv.h_serv need to be
    * set up prior to the call to netdir_getbyname().
    */
   if (netdir_getbyname(nconf, &nd_hostserv, &nd_addrlistp)
       != ND_OK)
   {
      printf("Cannot determine address for service\n");
      /* Release the netconfig handle allocated by setnetconfig() */
      endnetconfig(handlep);
      exit(1);
   }

   /* Convert the transport-specific address into universal address
    * notation and print it.
    */
   netbufp = nd_addrlistp->n_addrs;
   uaddr = taddr2uaddr(nconf, netbufp);
   if (uaddr != NULL)
   {
      printf("The address of the service %s on host %s is %s\n",
              nd_hostserv.h_serv, nd_hostserv.h_host, uaddr);
      free(uaddr);
   }

   /* Free the netdir structure allocated by netdir_getbyname() */
   netdir_free(nd_addrlistp, ND_HOSTSERVLIST);

  /* Release the netconfig handle allocated by setnetconfig() */
  endnetconfig(handlep);
}



API introduced: V4R2

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