#include <netdir.h> int netdir_getbyname(struct netconfig *nconf, struct nd_hostserv *service, struct nd_addrlist **addrs);
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.
No authorization is required.
0 | netdir_getbyname() was successful. |
-1 | netdir_getbyname() was not successful. The nd_errno (defined in <netdir.h>) is set to indicate the error. |
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. |
Message ID | Error Message Text |
---|---|
CPF9872 E | Program or service program &1 in library &2 ended. Reason code &3. |
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.
See Code disclaimer information for information pertaining to code examples.
The following example shows how netdir_getbyname() is used:
#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); }
Top | Remote Procedure Call (RPC) APIs | APIs by category |