使用 主机名、IPv4地址 得到 struct hostent 结构体(主机的详细信息),先介绍该结构体:
struct hostent{
char* h_name; 主机名
char** h_aliases; 别名列表
int h_addrtype; 主机地址类型AF_INET
int h_length; 地址长度
char** h_addr_list; IPv4地址列表
}
① 主机名hostname → struct hostent
struct hostent* gethostbyname
(const char* hostname);
② 二进制的IPv4地址 → struct hostent
struct hostent* gethostbyaddr
(const char* addr, socklen_t len, int family);
注意:上面两个函数只支持IPv4