NAME | SYNOPSIS | DESCRIPTION | RETURN VALUES | ATTRIBUTES | SEE ALSO | RESTRICTIONS
#include <netdb.h>struct hostent * gethostbyname(const char * name);
The gethostbyname() and gethostbyaddr() functions each return a pointer to an object containing the broken-out fields of a line in the network host data base. The object has the following structure:
struct hostent { char* h_name; /* official name of host */ char** h_aliases; /* alias list */ int h_addrtype; /* address type */ int h_length; /* length of address */ char** h_addr_list; /* list of addresses from name server */ #define h_addr h_addr_list[0] /* address, for backward compatiblity */ }; |
The members of this structure are:
Official name of the host.
A zero terminated array of alternate names for the host.
The type of address being returned; currently always AF_INET.
The length, in bytes, of the address.
A pointer to a list of network addresses for the named host. Host addresses are returned in network byte order.
In the case of gethostbyaddr() , addr is a pointer to the binary format address (supplied in network order) of length len (not a character string) and type is the type of the address.
To obtain this information, an Internet Name Server daemon must be running.
A NULL pointer is returned on error.
See attributes(5) for descriptions of the following attributes:
ATTRIBUTE TYPE | ATTRIBUTE VALUE |
---|---|
Interface Stability | Evolving |
All information is contained in a static area so it must be copied if it is to be saved. Only the Internet address format is currently understood.
NAME | SYNOPSIS | DESCRIPTION | RETURN VALUES | ATTRIBUTES | SEE ALSO | RESTRICTIONS