NETPATHAccess to netconfig Data
Three routines access the network configuration database indirectly through the
NETPATH environment variable. The variable specifies the transport or transports an application is to use and the order to try them.
NETPATH components are read from left to right. The functions have the following interfaces:
A call to setnetpath() initializes the search of
NETPATH. It returns a pointer to a database that contains the entries specified in a
NETPATH variable. The pointer, called a handle, is used to traverse this database with getnetpath(). setnetpath() must be called before the first call to getnetpath().
When first called, getnetpath() returns a pointer to the netconfig file entry that corresponds to the first component of the
NETPATH variable. On each subsequent call, getnetpath() returns a pointer to the netconfig entry that corresponds to the next component of the
NETPATH variable; getnetpath() returns NULL if there are no more components in
NETPATH. A call to getnetpath() without an initial call to setnetpath() causes an error; getnetpath() requires the pointer returned by setnetpath() as an argument.
getnetpath() silently ignores invalid
NETPATH components. A
NETPATH component is invalid if there is no corresponding entry in the netconfig database.
NETPATH variable is unset, getnetpath() behaves as if
NETPATH were set to the sequence of default or visible transports in the netconfig database, in the order in which they are listed.
endnetpath() is called to release the database pointer to elements in the
NETPATH variable when processing is complete. endnetpath() fails if setnetpath() was not called previously. Example 4-3 shows the setnetpath(), getnetpath(), and endnetpath() routines.
The netconfig structures obtained through getnetpath() become invalid after the execution of endnetpath(). To preserve the data in the structure, use getnetconfigent(nconf->nc_netid) to copy them into a new data structure.