Museum

Home

Lab Overview

Retrotechnology Articles

Online Manuals

⇒ getnetbyaddr_r(3N) — HP-UX 10.20

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

ypserv(1M)

networks(4)

ypfiles(4)

getnetent(3N)

NAME

getnetent(), getnetent_r(), getnetbyaddr(), getnetbyaddr_r(), getnetbyname(), getnetbyname_r(), setnetent(), setnetent_r(), endnetent(),endnetent_r() − get network entry

SYNOPSIS

#include <sys/socket.h>
#include <netdb.h>

struct netent *getnetent(void);

int getnetent_r(struct netent *result, struct netent_data *buffer);

struct netent *getnetbyname(const char *name);

int getnetbyname_r(

const char *name,
struct netent *result,
struct netent_data *buffer);

struct netent *getnetbyaddr(int net, int type);

_XOPEN_SOURCE_EXTENDED only
struct netent *getnetbyaddr(in_addr_t net, int type);

int getnetbyaddr_r(

int net,
int type,
struct netent *result,
struct netent_data *buffer);

int setnetent(int stayopen);

int setnetent_r(int stayopen, struct netent_data *buffer);

int endnetent(void);

int endnetent_r(struct netent_data *buffer);

_XOPEN_SOURCE_EXTENDED only
void setnetent(int stayopen);
void endnetent(void);

DESCRIPTION

getnetent(), getnetbyname(), and getnetbyaddr() each return a pointer to a structure of type netent containing the broken-out fields of a line in the network data base, /etc/networks. 

The members of this structure are:

n_name The official name of the network. 

n_aliases A null-terminated list of alternate names for the network. 

n_addrtype The type of the network number returned; always AF_INET. 

n_net The network number. 

Functions behave as follows:

getnetent() Reads the next line of the file, opening the file if necessary. 

setnetent() opens and rewinds the file.  If the stayopen flag is non-zero, the network data base is not closed after each call to getnetent() (either directly or indirectly through one of the other getnet* calls). 

endnetent() Closes the file. 

getnetbyname() Sequentially searches from the beginning of the file until a network name (among either the official names or the aliases) matching its parameter name is found, or until EOF is encountered. 

getnetbyaddr() Sequentially searches from the beginning of the file until a network number matching its parameter net is found, or until EOF is encountered.  The parameter net must be in network order.  The parameter type must be the constant AF_INET.  Network numbers are supplied in host order (see byteorder(3N)).

If the system is running Network Information Service (NFS), getnetbyname() and getnetbyaddr() obtain their network information from the NIS server (see ypserv(1M) and ypfiles(4)).

Reentrant Interfaces

getnetent_r(), getnetbyname_r() and getnetbyaddr_r() expect to be passed the address of a struct netent and will store the result at the supplied location.  An additional parameter, a pointer to a struct netent_data, must also be supplied.  This structure is used to store data, to which fields in the struct netent will point, as well as state information such as open file descriptors.  The struct netent_data is defined in the file <netdb.h>. 

setnetent_r() and endnetent_r() are to be used only in conjunction with getnetent_r() and take the same pointer to a struct netent_data as a parameter.  If the Network Information Service is being used, setnetent_r() initializes an internal database key.  If the /etc/networks file is being used, setnetent_r() opens or rewinds the file.  endnetent_r() should always be called to ensure that files are closed and internally allocated data structures are released. 

The stayopen parameter to setnetent_r() currently has no effect. However, setnetent() can still be used to keep the /etc/networks file open when making calls to getnetbyaddr_r() and getnetbyname_r(). 

The net_fp field in the struct netent_data must be initialized to NULL before it is passed to either getnetent_r() or setnetent_r() for the first time.  Thereafter it should not be modified in any way.  This is the only netent_data field that should ever be explicitly accessed. 

Name Service Switch-Based Operation

The library routines, getnetbyname(), getnetbyaddr(), getnetent(), and their reentrant counterparts, internally call the name service switch to access the "networks" database lookup policy configured in the /etc/nsswitch.conf file (see switch(4)).  The lookup policy defines the order and the criteria of the supported name services used to resolve network names and addresses. 

RETURN VALUE

getnetent(), getnetbyname(), and getnetbyaddr() return a null pointer (0) on EOF or when they are unable to open /etc/networks.  getnetbyaddr() also returns a null pointer if its type parameter is invalid. 

getnetent_r(), getnetbyname_r(), getnetbyaddr_r(), setnetent_r(), and endnetent_r() return a -1 if the operation is unsuccessful or, in the case of getnetent_r(), if the end of the networks list has been reached.  A 0 is returned otherwise. 

EXAMPLE

The following code excerpt counts the number of network entries:

int count = 0;
struct netent netbuf;
struct netent_data ndbuf;
 ndbuf.net_fp = NULL;
(void) setnetent_r(0, &ndbuf);
while (getnetent_r(&netbuf, &ndbuf) != -1)
    count++;
(void) endnetent_r(&ndbuf);

WARNINGS

In the non-reentrant versions of these routines, all information is contained in a static area so it must be copied if it is to be saved. 

getnetent(), getnetbyaddr(), getnetbyname(), setnetent(), and endnetent() are unsafe in multi-thread applications.  getnetent_r(), getnetbyaddr_r(), getnetbyname_r(), setnetent_r(), and endnetent_r() are MT-Safe and should be used instead. 

AUTHOR

getnetent() was developed by the University of California, Berkeley. 

FILES

/etc/networks

SEE ALSO

ypserv(1M), networks(4), ypfiles(4). 

STANDARDS CONFORMANCE

getnetent(): XPG4

Hewlett-Packard Company  —  HP-UX Release 10.20:  July 1996

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026