getnetent(3) — Subroutines
NAME
getnetent, getnetent_r − Get a network entry
LIBRARY
Standard C Library (libc.a)
SYNOPSIS
#include <netdb.h>
struct netent ∗getnetent(void);
int getnetent_r(
struct netent ∗net,
struct netent_data ∗net_data);
PARAMETERS
netPoints to the netent structure.
net_dataIs data for the networks database.
DESCRIPTION
The getnetent() function retrieves network information by opening and sequentially reading the /etc/networks file.
The getnetent() function returns a pointer to a netent structure, which contains the equivalent fields for a network description line in the /etc/networks file. The netent structure is defined in the netdb.h header file.
Use the endnetent() function to close the /etc/networks file.
The getnetent_r() function is the reentrant version of the getnetent() function. Upon successful completion, the returned structure is pointed to by net. The netdb.h header file defines the netent and netent_data structures.
The system searches either the local /etc/networks file or the NIS distributed networks file for the requested information. To determine which file or files to search, and in which order, the system uses the switches in the /etc/svc.conf file.
NOTES
The getnetent() return value points to static data, which is overwritten by any subsequently called functions using the same structure.
Before the first access (by either the setnetent_r() or getnetent_r() functions), set to NULL the net_fp field of the netent_data structure.
If the system is configured to access network information through NIS, the getnetent_r() function may not produce correct results if called from multiple threads.
RETURN VALUES
Upon successful completion, the getnetent() function returns a pointer to a netent structure. If an error occurs or EOF is reached, the getnetent() function returns a value of 0 (zero).
Upon successful completion, the getnetent_r() function returns a value of 0 (zero). Otherwise, a value of -1 is returned.
ERRORS
If any of the following conditions occurs, the getnetent_r() function sets errno to the corresponding value:
[EINVAL]The netent or net_data parameter is invalid.
[ESRCH]The search failed (EOF).
FILES
/etc/networks
This file is the DARPA Internet network name database file. Each record in the file occupies a single line and has three fields: the official network name, the network number, and alias.
RELATED INFORMATION
Functions: getnetbyaddr(3), getnetbyname(3), setnetent(3), endnetent(3).