|
|
An Internet host name to address mapping is represented by the hostent structure:
struct hostent { char *h_name; /* official name of host */ char **h_aliases; /* alias list */ int h_addrtype; /* host address type (for example, AF_INET) */ int h_length; /* length of address */ char **h_addr_list; /* list of addresses, null terminated */ }; #define h_addr h_addr_list[0] /* first address, network byte order */The routine gethostbyname takes an Internet host name and returns a hostent structure, while the routine gethostbyaddr maps Internet host addresses into a hostent structure. These two routines are described on the gethostent(S) manual page. The routine inet_ntoa maps an Internet host address into an ASCII string for printing by log and error messages. This function is described on the inet(S) manual page.
The official name of the host and its public aliases are returned by these routines, along with the address type (domain) and a null terminated list of variable length addresses. This list of addresses is required because it is possible for a host to have many addresses, all having the same name. The h_addr definition is provided for backward compatibility, and is defined to be the first address in the list of addresses in the hostent structure.