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

Code examples

The following code examples are taken from the larger program found in ``Using the name-to-address mapping routines''. They show several ways in which the network selection facility may be used.

Looping through all visible netconfig entries

In the examples that follow, the setnetpath call initializes the network selection routines and returns a database pointer.

The getnetpath call returns each visible entry in the /etc/netconfig file (that is, each entry that contains a v flag). Entries are returned in the order in which they appear in the file.

void *handlep;

if ((handlep = setnetpath()) == NULL) { nc_perror(argv[0]); exit(1); }

while ((netconfigp = getnetpath(handlep)) != NULL) { /* * netconfigp now describes a transport provider */ }

endnetpath(handlep);

Looping through user-defined netconfig entries

Users can also manipulate the loop by setting the NETPATH environment variable to a colon-separated list of transport provider names (transport provider names are given in the first field of the /etc/netconfig file). If the value of NETPATH is set as follows:

   NETPATH=tcp:starlan
then the loop will first return the entry corresponding to tcp, and then the entry corresponding to starlan. If NETPATH is not set in the environment, the above loop will return all visible entries in the netconfig file in the order in which they appear there.

The NETPATH environment variable allows users to define the order in which client-side applications attempt to make connections to a service. It also allows the administrator of the server machine to restrict the transport providers to which a service will loop through and bind.

Looping through all netconfig entries

An application can ignore the NETPATH variable and loop through all entries in the netconfig file -- even those without a v flag:

void * handlep;
struct netconfig * netcfp;
if ((handlep = setnetconfig()) == NULL){
	nc_perror(argv[0]);
	exit(1);
}

/* * transport provider information is described in netcfp. * process_transport is a user-supplied routine that * tries to connect to a server over transport netcfp. */

while ((netcfp = getnetconfig(handlep)) != NULL){ if (process_transport(netcfp) == SUCCESS){ break; } }

endnetconfig(handlep);

Specifying a single transport provider

The following call will obtain information about a single, named transport provider:

   netconfigp = getnetconfigent(name);

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