gethostent() — Get the next host entry

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 hostent *gethostent(void);
Berkeley sockets:
#define _OE_SOCKETS
#include <netdb.h>

struct hostent *gethostent(void);

General description

The gethostent() call reads the next line of the local host tables.

The gethostent() call returns a pointer to the next entry in the local host tables. gethostent() uses the local host tables to get aliases.

You can use the X_SITE environment to specify different local host tables and override those supplied by the z/OS resolver during initialization.
Note: For more information on these local host tables or the environment variables, see z/OS V2R1.0 Communications Server: IP Configuration Guide .

gethostent(), gethostbyaddr(), and gethostbyname() all use the same static area to return the hostent structure. This static area is only valid until the next one of these functions is called on the same thread.

The netdb.h include file defines the hostent structure and contains the following elements:
Element
Description
h_addrtype
The type of address returned; currently, it is always set to AF_INET.
h_addr
A pointer to the network address of the host.
h_aliases
A zero-terminated array of alternative names for host.
h_length
The length of the address in bytes.
h_name
The official name of the host.

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, gethostent() returns a pointer to a hostent structure. The return value points to data that is overwritten by subsequent calls returning the same data structure.

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

Related information