getnetbyname() — Get a network entry by name

Standards

Standards / Extensions C or C++ Dependencies

XPG4.2
Single UNIX Specification, Version 3

both  

Format

X/Open:
#define _XOPEN_SOURCE_EXTENDED 1
#include <netdb.h>

struct netent *getnetbyname(const char *name);
Berkeley sockets:
#define _OE_SOCKETS
#include <netdb.h>

struct netent *getnetbyname(name);

General description

The getnetbyname() call searches the tcpip.HOSTS.SITEINFO data set for the specified network name.
Parameter
Description
name
The pointer to a network name.
You can use the X_SITE environment variable to specify a data set other than tcpip.HOSTS.SITEINFO.
Note: For more information on these data sets and environment variables, tcpip.HOSTS.LOCAL, tcpip.HOSTS.SITEINFO, and tcpip.HOSTS.SITEINFO, see z/OS V2R1.0 Communications Server: IP Configuration Guide.

The getnetbyname() call returns a pointer to a netent structure for the network name specified on the call. getnetbyaddr(), getnetbyname(), and getnetent() all use the same static area to return the netent structure. This static area is only valid until the next one of these functions is called on the same thread.

The netent structure is defined in the netdb.h include file and contains the following elements:
Element
Description
n_addrtype
The type of network address returned. The call always sets this value to AF_INET.
n_aliases
An array, terminated with a NULL pointer, of alternative names for the network.
n_name
The official name of the network.
n_net
The network number, returned in host byte order.

Special behavior for C++: To use this function with C++, you must use the _XOPEN_SOURCE_EXTENDED 1 feature test macro.

Returned value

If successful, getnetbyname() returns a pointer to a netent structure. The return value points to static data that is overwritten by subsequent calls.

If unsuccessful, getnetbyname() returns a NULL pointer, indicating an error or End Of File (EOF).

Related information