#include <netdir.h> char *taddr2uaddr(struct netconfig *nconf, struct netbuf *addr);
The taddr2uaddr() function translates a transport-specific (local) address to a transport-independent (universal) address.
No authorization is required.
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. |
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. |
Message ID | Error Message Text |
---|---|
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
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.
See Code disclaimer information for information pertaining to code examples.
The following example shows how taddr2uaddr() is used:
#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); }
Top | Remote Procedure Call (RPC) APIs | APIs by category |