gethostbyname、gethostbyaddr

使用 主机名、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


在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_36750623/article/details/91840491
今日推荐