struct hostent代表什么?

时间:2019-05-08 09:30:04

标签: c network-programming coding-style

指向hostent的指针是gethostbyname()返回的结构。

确切的函数签名:struct hostent* gethostbyname(const char*)

我不知道在托管结束时,“ ent”部分在这里意味着什么。

当我试图记住自己不懂的时候,我会很健忘,所以请帮帮我。

1 个答案:

答案 0 :(得分:1)

快速search on GitHub指向basedefs/netdb.h(对网络数据库操作的定义)

  

<netdb.h>标头应定义至少包括以下成员的hostent结构:

char   *h_name       Official name of the host. 
char  **h_aliases    A pointer to an array of pointers to 
                     alternative host names, terminated by a 
                     null pointer. 
int     h_addrtype   Address type. 
int     h_length     The length, in bytes, of the address. 
char  **h_addr_list  A pointer to an array of pointers to network 
                     addresses (in network byte order) for the host, 
                     terminated by a null pointer. 

从那里开始,official documentation for gethostbyaddr()包括:

  

条目应以托管结构返回。

     

gethostbyaddr()函数应返回一个条目,其中包含地址为addr的主机的地址族类型的地址。
  len参数包含addr指向的地址的长度。
  gethostbyaddr()函数不必是可重入的。不需要重入的函数不需要是线程安全的。

     

条目应以宿主结构返回。

     

成功完成后,如果找到请求的 entry ,这些函数应返回指向hostent结构的指针,如果到达数据库的末尾或请求的数据库指针,则返回空指针。找不到条目

所以您可以使用它: ent entry 。不是实体。