gethostbyname(), gethostbyaddr(), gethostent(), sethostent(), endhostent(), herror() - get network host entry (and h_errno variable)
#include <netdb.h>
extern int h_errno;
struct hostent *gethostbyname (const char *name)
struct hostent *gethostbyaddr (const void *addr, int len, int type)
struct hostent *gethostent (void)
void sethostent (int stayopen)
void endhostent (void)
void herror (char *string)
The gethostbyname(2) and gethostbyaddr(2) functions each return a pointer to an object with the following structure describing an Internet host referenced by name or by address, respectively.
The gethostbyname(2) function searches for information on a host named name, and returns a pointer to a struct hostent.
The gethostbyaddr(2) function searches for information about a host with the host address addr. The address is a string, in the dot-separated Internet Protocol (IP) format. The buffer specified by addr is len bytes in size. The type is the supported network type (always AF_INET in this implementation).
The struct hostent structure contains the information obtained from the Winsock dynamic-link library (DLL) configuration on the local computer (regardless of how your Windows networking system is configured):
struct hostent {
char * h_name; /* official name of host */
char ** h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char ** h_addr_list; /* list of addresses from name server */
};
For backwards compatibility, the address is also defined as:
#define h_addr h_addr_list[0]
The members of this structure are:
The calls gethostent(2), sethostent(2), and endhostent(2) search the hosts
file (
The sethostent(2) function opens or rewinds the hosts file, or does both. If the stayopen argument is non-zero, the file will not be closed after each call to gethostbyname(2) or gethostbyaddr(2).
The endhostent(2) function closes the file.
Error return status from gethostbyname(2) and gethostbyaddr(2) is indicated by return of a null pointer. The external integer h_errno can then be checked to determine whether this is a temporary failure or an invalid or unknown host. The routine herror(3) can be used to print an error message describing the failure. If its argument string is non-NULL, string is printed, followed by a colon and a space. The error message is printed with a trailing newline.
The variable h_errno can have the following values:
The sockets mechanism in Interix is built around the Microsoft Winsock DLL. Configuring the network information for sockets depends upon your Winsock configuration; see the appropriate system documentation.
These functions use static data storage; if the data is needed for future use, it should be copied before any subsequent calls overwrite it. Currently the functions only understand the Internet address format.
hosts(5)
hostname(5)