|
|
int netdir_getbyname(netconfig, nd_hostserv, nd_addrlist) struct netconfig *netconfig; struct nd_hostserv *nd_hostserv; struct nd_addrlist **nd_addrlist;int netdir_getbyaddr(netconfig, nd_hostservlist, netbuf) struct netconfig *netconfig; struct nd_hostservlist **nd_hostservlist; struct netbuf *netbuf;
void netdir_free(ptr, type) char *ptr; int type;
char * taddr2uaddr(netconfig, addr) struct netconfig *netconfig; struct netbuf *addr;
struct netbuf * uaddr2taddr(netconfig, addr) struct netconfig *netconfig; char *addr;
int netdir_options(netconfig, option, fd, pointer_to_args) struct netconfig *netconfig; int option; int fd; char *pointer_to_args;
void netdir_perror(s) char *s;
char * netdir_sperror()
The netdir_getbyname routine maps the machine and service name specified in the nd_hostserv structure to a collection of addresses of the type understood by the transport identified in the netconfig structure. The nd_addrlist parameter returns a pointer to the addresses. To find all addresses of a machine and service (on all available transports), repeatedly call the netdir_getbyname routine with each netconfig structure returned by the getnetpath call.
The netdir_getbyaddr routine maps addresses into machine and service names. Given an address in the netbuf parameter, this routine returns a list of machine name and service name pairs that would yield that address (a pointer to the list of machine and service name pairs is returned in the nd_hostservlist parameter).
The netdir_free routine frees the structures allocated by the name-to-address translation routines. The parameters can take the following values:
The taddr2uaddr routine translates the address given in the netbuf structure (which is an address for the transport provider given in the netconfig structure) and returns a universal address representation of the address. A universal address is a machine, architecture-independent, character representation of the address.
The uaddr2taddr routine takes a universal address and translates it back into a netbuf structure. The netconfig parameter specifies which transport provider the address is valid for.
The netdir_options routine provides an interface to transport specific capabilities (for example, applications can take advantage of the broadcast address and reserved port facilities provided by the User Datagram Protocol (UDP)).
The netconfig structure specifies a transport provider. The option argument specifies the transport-specific action to take. The third argument is a file descriptor (which may or may not be used depending upon option). The fourth argument is a pointer to operation-specific data.
The following values may be used for option:
struct nd_mergearg { char *s_uaddr; /* server's universal address */ char *c_uaddr; /* client's universal address */ char *m_uaddr; /* the result */ }
The netdir_perror routine prints onto standard output the error message stating why one of the name-to-address mapping routines failed. The error message is preceded by the string given as an argument.
The netdir_sperror routine returns a string containing the error message stating why one of the name-to-address mapping routines failed.
#include <netconfig.h> #include <netdir.h> #include <tiuser.h>/*** The following is a segment of a procedure. ***/
struct nd_hostserv nd_hostserv; /* contains host and service information */ struct netconfig *netconfigp; /* contains information about each network */ struct nd_addrlist *nd_addrlistp; /* list of addresses for the service */ struct netbuf *netbufp; /* the address of the service */ int i; /* counts the number of addresses */ void *handlep; /* a handle into network selection */
/* * Set the host structure to reference the "date" service on machine "gandalf" */
nd_hostserv.h_host = "gandalf"; nd_hostserv.h_serv = "date";
/* * Initialize the network selection mechanism. */
if ((handlep = setnetpath()) == NULL) { nc_perror(argv[0]); exit(1); } /* * Loop through the transport providers. */
while ((netconfigp = getnetpath(handlep)) != NULL) { /* * Print out the information associated with the transport * provider described in the "netconfig" structure. */
printf("Transport provider name: %s\n", netconfigp->nc_netid); printf("Transport protocol family: %s\n", netconfigp->nc_protofmly); printf("The transport device file: %s\n", netconfigp->nc_device); printf("Transport provider semantics: "); switch (netconfigp->nc_semantics) { case NC_TPI_COTS: printf("virtual circuit\n"); break; case NC_TPI_COTS_ORD: printf("virtual circuit with orderly release\n"); break; case NC_TPI_CLTS: printf("datagram\n"); }
/* * Get the addresses for service "date" on machine "gandalf" * over the transport provider specified in the netconfig structure. */ if (netdir_getbyname(netconfigp, &nd_hostserv, &nd_addrlistp) != 0) { printf("Cannot determine the address for the service\n"); netdir_perror(argv[0]); continue; }
printf("There are <%d> addresses for the date service on gandalf:\n", nd_addrlistp->n_cnt);
/* * Print out all addresses for service "date" on machine "gandalf" * on the current transport provider. */ netbufp = nd_addrlistp->n_addrs; for (i = 0; i < nd_addrlistp->n_cnt; i++) { printf("%s\n", taddr2uaddr(netconfigp, netbufp)); netbufp++; } } endnetconfig(handlep);
Code Example: Using network selection and name-to-address mapping.