getnetbyname(3N)
NAME
getnetbyname, getnetbyaddr, setnetent, getnetent, endnetent − get network entry
SYNOPSIS
cc [ flag ... ] file ... −lsocket -lnsl [ library ... ]
#include <netdb.h>
struct netent ∗getnetbyname(const char ∗name);
struct netent ∗getnetbyaddr(const long net);
int setnetent(const int stayopen);
struct netent ∗getnetent(void);
DESCRIPTION
getnetent(), getnetbyname(), and getnetbyaddr() each return a network entry.
The entry may come from one of the following sources: the networks file (see networks(4)), the NIS maps “network.byname” and “network.byaddr”, and the NIS+ table “network”. The sources and their lookup order are specified in the /etc/nsswitch.conf file (see nsswitch.conf(4) for details).
getnetbyname() searches for a network entry with the given network name.
getnetbyaddr() searches for a network entry with the given network number.
setnetent() “rewinds” to the beginning of the enumeration of network entries. If the stayopen flag is non-zero, resources such as open file descriptors are not deallocated after each call to getnetbyaddr() and getnetbyname(). Calls to getnetbyname() and getnetbyaddr() may leave the enumeration in an indeterminate state, so setnetent() should be called before the first getnetent().
getnetent() enumerates network entries: successive calls to getnetent() will return either successive network entries or NULL. Enumeration may not be supported by some sources. setnetent() should be called before the first getnetent().
endnetent() may be called to indicate that network processing is complete; the system may then close any open networks file, deallocate storage, and so forth. It is legitimate, but possibly less efficient, to call more network routines after endnetent().
The representation of a network entry is a netent structure defined in the header <netdb.h> with the following entries:
char∗n_name;
char∗∗n_aliases;
intn_addrtype;
longn_net;
RETURN VALUES
getnetbyname() and getnetbyaddr() return a pointer to a struct netent if they successfully locate the requested entry; otherwise they return NULL.
getnetent() returns a pointer to a struct netent if it successfully enumerates an entry; otherwise it returns NULL, indicating the end of the enumeration.
FILES
/etc/networks
/etc/nsswitch.conf
SEE ALSO
NOTES
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.
Use of getnetent() is deprecated; enumeration is well-defined for the networks file and is supported (albeit inefficiently) for NIS and NIS+, but in general may not be well-defined. The semantics of enumeration are discussed in nsswitch.conf(4).
BUGS
Programs that call getnetbyname() or getnetbyaddr() routines cannot be linked statically since the implementation of these routines requires dynamic linker functionality to access shared objects at run time.
SunOS 5.1/x86 — Last change: 24 Feb 1992