#include <netdb.h>
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 */
}
#define h_addr h_addr_list[0] /* for backward compatibility */
除了服务器的ip地址外,这个结构体还包含了更多服务器的信息,有:
123
char *h_name
This is the “official” name of the host.
123
char **h_aliases
These are alternative names for the host, represented as a null-terminated vector of strings.
主机的可选名字,以NULL作为结束标记。
123
int h_addrtype
This is the host address type; in practice, its value is always either AF_INET or AF_INET6, with the latter being used for IPv6 hosts. In principle other kinds of addresses could be represented in the database as well as Internet addresses; if this were done, you might find a value in this field other than AF_INET or AF_INET6. See Socket Addresses.
123
int h_length
This is the length, in bytes, of each address.
ip地址的长度,ipv4对应4个字节。
123
char **h_addr_list
This is the vector of addresses for the host. (Recall that the host might be connected to multiple networks and have different addresses on each one.) The vector is terminated by a null pointer.