Network Interface Guide

Looping Through User-Defined netconfig(4) Entries

Users can control the loop by setting the NETPATH environment variable to a colon-separated list of transport names. If NETPATH is set as follows:


NETPATH=tcp:udp

The loop first returns the tcp entry, then the udp entry. If NETPATH is not defined, the loop returns all visible entries in the netconfig(4) file in the order in which they are stored. The NETPATH environment variable lets users define the order in which client-side applications try to connect to a service. It also lets the server administrator limit transports on which a service can listen.

Use getnetpath(3NSL) and setnetpath(3NSL) to obtain or modify the network path variable. Example 4-6 shows the form and use, which are similar to the getnetconfig(3NSL) and setnetconfig(3NSL) routines.


Example 4-6 Looping Through Visible Transports

void *handlep;
struct netconfig *nconf;

if ((handlep = setnetconfig() == (void *) NULL) {
	   nc_perror("setnetconfig");
   exit(1);
}
while (nconf = getnetconfig(handlep))
	   if (nconf->nc_flag & NC_VISIBLE)
      doit(nconf);
(void) endnetconfig(handlep);