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

Routines that access netconfig directly

Five functions access the network configuration database file, /etc/netconfig. They have the following syntax:

#include <netconfig.h>

struct netconfig * getnetconfigent(netid) char * netid;

int freenetconfigent(netconfigp) struct netconfig * netconfigp;

A call to setnetconfig initializes the database routines. It returns a database pointer to be used when traversing the database with getnetconfig. This database pointer is also called a handle. Each call to getnetconfig returns the next entry in netconfig associated with the handle returned by setnetconfig.

When first called, getnetconfig returns a pointer to the first entry in the netconfig database, formatted as a struct netconfig. On each subsequent call, getnetconfig returns a pointer to the next entry in the database; it can thus be used to search the entire netconfig file. getnetconfig returns NULL to the calling routine at end of file.

endnetconfig may be called to free the database pointer when processing is complete. endnetconfig may not be called before setnetconfig. endnetconfig returns 0 on success and -1 on failure (for example, if setnetconfig was not called previously).

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

Sample Code Using setnetconfig, getnetconfig, and endnetconfig

#include <netconfig.h>

struct netconfig * getnetconfigent(netid) char * netid;

int freenetconfigent(netconfigp) struct netconfig * netconfigp;

Sample Code Using getnetconfigent and freenetconfigent

getnetconfigent returns a pointer to the struct netconfig structure corresponding to netid. It returns NULL if netid is invalid (that is, does not name an entry in the netconfig database).

freenetconfigent frees the structure returned by getnetconfigent.


NOTE: setnetconfig need not be called before getnetconfigent.

/* * assume starlan is a netid on this machine */

struct netconfig * netcfp; if ((netcfp = getnetconfigent("starlan")) == NULL){ nc_error("no information about starlan"); exit(1); }

process_transport(netcfp);

freenetconfigent(netcfp);

Sample Code Using getnetconfigent and freenetconfigent


© 2005 The SCO Group, Inc. All rights reserved.
SCO OpenServer Release 6.0.0 -- 02 June 2005