DOC HOME SITE MAP MAN PAGES GNU INFO SEARCH PRINT BOOK
 
Network services

Using the name-to-address mapping routines

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()

netdir_getbyname

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.

netdir_getbyaddr

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).

netdir_free

The netdir_free routine frees the structures allocated by the name-to-address translation routines. The parameters can take the following values:


ND_HOSTSERVLIST
pointer to nd_hostservlist structure allocated by netdir_getbyaddr

ND_ADDRLIST
pointer to nd_addrlist structure allocated by netdir_getbyname

taddr2uaddr

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.

uaddr2taddr

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.

netdir_options

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:


ND_SET_BROADCAST
This option sets the transport provider up to allow for broadcast (if the transport provider supports broadcast). fd is a file descriptor into the transport provider (for example, the result of a t_open on /dev/udp). pointer_to_args is not used. If successful, broadcast operations may be done on fd.

ND_SET_RESERVEDPORT
Allows the application to bind to a reserved port, if allowed by the transport provider specified. fd is a file descriptor into the transport (it must not be bound to an address). If pointer_to_args is NULL, fd will be bound to a reserved port. If pointer_to_args is a pointer to a netbuf structure, an attempt will be made to bind to a reserved port on the specified address.

ND_CHECK_RESERVEDPORT
If the concept of a reserved port exists for a transport provider, ND_CHECK_RESERVEDPORT is used to verify that an address corresponds to a reserved port. fd is not used. pointer_to_args is a pointer to a netbuf structure that contains an address. This option returns 0 only if the address specified in pointer_to_args is reserved.

ND_MERGEADDR
Used to transform a locally meaningful address into an address that client machines can connect to. For example, the Transmission Control Protocol (TCP) has the concept of 0.0.0.0 as a locally meaningful address. ND_MERGEADDR can be used to translate the 0.0.0.0 address into an address that is understood by client machines. fd is not used with this option. pointer_to_args is a pointer to a nd_mergearg structure, which has the following form:
struct nd_mergearg {
	char *s_uaddr;  /* server's universal address */
	char *c_uaddr;  /* client's universal address */
	char *m_uaddr;  /* the result */
}

netdir_perror

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.

netdir_sperror

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.


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 27 April 2004