NAME
getnetent
,
getnetent_r
, getnetbyaddr
,
getnetbyaddr_r
,
getnetbyname
,
getnetbyname_r
, setnetent
,
endnetent
—
get network entry
LIBRARY
library “libc”
SYNOPSIS
#include
<netdb.h>
struct netent *
getnetent
(void);
int
getnetent_r
(struct
netent *ne, char
*buffer, size_t
buflen, struct netent
**result, int
*h_errnop);
struct netent *
getnetbyname
(const
char *name);
int
getnetbyname_r
(const
char *name, struct netent
*ne, char *buffer,
size_t buflen,
struct netent **result,
int *h_errnop);
struct netent *
getnetbyaddr
(uint32_t
net, int type);
int
getnetbyaddr_r
(uint32_t
addr, int af,
struct netent *ne,
char *buffer,
size_t buflen,
struct netent **result,
int *h_errnop);
void
setnetent
(int
stayopen);
void
endnetent
(void);
DESCRIPTION
Thegetnetent
(),
getnetbyname
(), and
getnetbyaddr
() functions each return a pointer to an
object with the following structure describing an internet network. This
structure contains either the information obtained from the nameserver,
named(8), broken-out fields of a line in the network data base
/etc/networks, or entries supplied by the
yp(8) system. The order of the lookups is controlled by the `networks'
entry in
nsswitch.conf(5).
struct netent { char *n_name; /* official name of net */ char **n_aliases; /* alias list */ int n_addrtype; /* net number type */ uint32_t n_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; currently only AF_INET.
- n_net
- The network number. Network numbers are returned in machine byte order.
The
getnetent
()
function reads the next line of the file, opening the file if necessary.
The
setnetent
()
function opens and rewinds the file. If the stayopen
flag is non-zero, the net data base will not be closed after each call to
getnetbyname
() or
getnetbyaddr
().
The
endnetent
()
function closes the file.
The
getnetbyname
()
function and
getnetbyaddr
()
sequentially search from the beginning of the file until a matching net name
or net address and type is found, or until EOF
is
encountered. The type argument must be
AF_INET
. Network numbers are supplied in host
order.
The
getnetent_r
(),
getnetbyaddr_r
(),
and
getnetbyname_r
()
functions are reentrant versions of the above functions that take a pointer
to a netent structure which is used to store state
information. The structure must be zero-filled before it is used and should
be considered opaque for the sake of portability. These functions also take
a pointer to another netent structure which is used to
store the results of the database lookup.
RETURN VALUES
The getnetent
(),
getnetbyaddr
(), and
getnetbyname
() functions return a pointer to a
netent structure on success or a null pointer if
end-of-file is reached or an error occurs.
The getnetent_r
(),
getnetbyaddr_r
(), and
getnetbyname_r
() functions return 0 on success or -1
if end-of-file is reached or an error occurs.
FILES
- /etc/networks
- /etc/nsswitch.conf
- /etc/resolv.conf
SEE ALSO
RFC 1101
STANDARDS
The getnetent
(),
getnetbyaddr
(),
getnetbyname
(), setnetent
(),
and endnetent
() functions conform to
IEEE Std 1003.1-2004 (“POSIX.1”).
The getnetent_r
(),
getnetbyaddr_r
(), and
getnetbyname_r
() functions are not currently
standardized.
HISTORY
The getnetent
(),
getnetbyaddr
(),
getnetbyname
(), setnetent
(),
and endnetent
() functions appeared in
4.2BSD.
The getnetent_r
(),
getnetbyaddr_r
(), and
getnetbyname_r
() functions appeared in
DragonFly 2.1.
BUGS
The data space used by these functions is thread-specific; if future use requires the data, it should be copied before any subsequent calls to these functions overwrite it. Only Internet network numbers are currently understood. Expecting network numbers to fit in no more than 32 bits is probably naive.