getnetent(3n)
NAME
getnetent, getnetbyaddr, getnetbyname, setnetent, endnetent − get network entry
SYNTAX
#include <netdb.h>
struct netent *getnetent()
struct netent *getnetbyname(name)
char *name;
struct netent *getnetbyaddr(net, type)
long net; int type;
setnetent(stayopen)
int stayopen
endnetent()
DESCRIPTION
The getnetent, getnetbyname, and getnetbyaddr subroutines each return a pointer to an object with the following structure containing the broken-out fields of a line in the network data base, /etc/networks.
structnetent {
char*n_name;/* official name of net */
char**n_aliases;/* alias list */
intn_addrtype;/* net number type */
longn_net;/* net number */
};
The members of this structure are:
n_name The official name of the network.
n_aliases A zero terminated list of alternate names for the network.
n_addrtype The type of the network number returned: AF_INET.
n_net The network number. Network numbers are returned in machine byte order.
The getnetent subroutine reads the next line of the file, opening the file if necessary.
The setnetent subroutine opens and rewinds the file. If the stayopen flag is non-zero, the net data base will not be closed after each call to getnetent (either directly, or indirectly through one of the other “getnet” calls).
The endnetent subroutine closes the file.
The getnetbyname subroutine sequentially searches from the beginning of the file until a matching net name is found, or until EOF is encountered.
The getnetbyaddr subroutine sequentially searches from the beginning of the file until a matching net number is found. The type must be AF_INET.
Network numbers are supplied in host order.
RESTRICTIONS
All information is contained in a static area so it must be copied if it is to be saved. Only Internet network numbers are currently understood.
RETURN VALUE
Null pointer (0) returned on EOF or error.
FILES
/etc/networks