gethostbyname

1
2
3
4
5
6
7
8
9
10
11
12
#include <netdb.h>
 
/*返回:若成功则为非空指针,若出错则为NULL且设置h_errno*/
struct hostent *gethostbyname(const char *hostname);
 
struct hostent {
        char *h_name;           /*official name of host*/
        char **h_aliases;       /*pointer to array of pointers to alias names*/
        int h_addrtype;         /*host address type: AF_INET*/
        int h_length;           /*length of address: 4*/
        char **h_addr_list;     /*ptr to array of ptrs with IPv4 addrs*/
};

当发生错误时,它不设置errno变量,而是将全局变量h_errno设置为在头文件<netdb.h>中定义的下列常值之一:

HOST_NOT_FOUND;

TRY_AGAIN;

NO_RECOVERY;

NO_DATA;

gethostbyname执行的是对A记录的查询,它只能返回IPv4地址。

posted @   东宫得臣  阅读(84)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· 25岁的心里话
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 按钮权限的设计及实现
点击右上角即可分享
微信分享提示