getnetent(3N)


endnetent, getnetent, getnetbyaddr, getnetbyname, setnetent -- get network entry

Synopsis

cc . . . -lsocket -lnsl
#include <netdb.h>

struct netent *getnetent(void);

struct netent *getnetbyname (const char *name);

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

void setnetent(int stayopen);

void endnetent(void);

Description

getnetent, getnetbyname, and getnetbyaddr each returns a pointer to an object with the following structure containing the broken-out fields of a line in the network data base, /etc/networks.

   struct netent {
           char        *n_name;      /* official name of net */
           char        **n_aliases;  /* alias list */
           int         n_addrtype;   /* net number type */
           in_addr_t   n_net;        /* net number */
   };

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; currently only AF_INET.

n_net
The network number. Network numbers are returned in machine byte order.
getnetent reads the next line of the file, opening the file if necessary. The getnetent subroutine keeps a pointer in the database, allowing subsequent calls to be used to search the file.

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

endnetent closes the file.

getnetbyname and getnetbyaddr sequentially search from the beginning of the file until a matching net name or net address is found, or until EOF is encountered. Network numbers are supplied in machine byte order. The only type currently supported is AF_INET.

A call to setnetent must be made before a while loop using getnetent in order to perform initialization. endnetent must be used after the loop. Both getnetbyname and getnetbyaddr make calls to setnetent and endnetent.

Files

/etc/networks

Diagnostics

Null pointer (0) returned on EOF or error, except by endnetent and setnetent.

References

networks(4tcp)

Notices

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.

It is probably not possible to expect network numbers to fit in no more than 32 bits.

Standards compliance

getnetent, getnetbyaddr, and getnetbyname are conformant with:

RFC 1101


© 2004 The SCO Group, Inc. All rights reserved.
UnixWare 7 Release 7.1.4 - 25 April 2004