Network Interface Guide

Accessing netconfig(4)

Three functions access /etc/netconfig and locate netconfig(4) entries. The routines setnetconfig(3NSL), getnetconfigent(3NSL), and endnetconfig(3NSL) have the following interfaces:

#include <netconfig.h>

void *setnetconfig(void);
struct netconfig *getnetconfig(void *);
int endnetconfig(void *);

A call to setnetconfig(3NSL) initializes the record pointer to the first index in the database; setnetconfig(3NSL) must be used before the first use of getnetconfig(3NSL). setnetconfig(3NSL) returns a unique handle (a pointer into the database) to be used by the getnetconfig(3NSL) routine. Each call to getnetconfig(3NSL) returns the pointer to the current record in the netconfig(4) database and increments its pointer to the next record. It can be used to search the entire netconfig(4) database. getnetconfig(3NSL) returns a NULL at the end of file.

You must use endnetconfig(3NSL) to release the database pointer when processing is complete. endnetconfig(3NSL) must not be called before setnetconfig(3NSL).

Example 4-4 setnetconfig(3NSL), getnetconfig(3NSL), and endnetconfig(3NSL) Functions

void *handlep;
struct netconfig *nconf;

if ((handlep = setnetconfig()) == (void *)NULL){
 * transport provider information is described in nconf.
 * process_transport is a user-supplied routine that
 * tries to connect to a server over transport nconf.
while ((nconf = getnetconfig(handlep)) != (struct netconfig *)NULL){
	   if (process_transport(nconf) == SUCCESS)

The last two functions have the following interface:

#include <netconfig.h>
struct netconfig *getnetconfigent(char *);
int freenetconfigent(struct netconfig *);

getnetconfigent(3NSL) returns a pointer to the struct netconfig structure corresponding to netid. It returns NULL if netid is invalid. setnetconfig(3NSL) need not be called before getnetconfigent(3NSL).

freenetconfigent(3NSL) frees the structure returned by getnetconfigent(3NSL). Example 4-5 shows the getnetconfigent(3NSL) and freenetconfigent(3NSL) routines.

Example 4-5 getnetconfigent(3NSL) and freenetconfigent(3NSL) Functions

/* assume udp is a netid on this host */
struct netconfig *nconf;

if ((nconf = getnetconfigent("udp")) == (struct netconfig *)NULL){
   nc_perror("no information about udp");