现在的位置: 首页 > 综合 > 正文

《UNIX网络编程01》 第十一章 高级名字与地址转换 gethostbyname_r、gethostbyaddr_r

2018年10月07日 ⁄ 综合 ⁄ 共 359字 ⁄ 字号 评论关闭

gethostbyname_r、gethostbyaddr_r

#include<unistd.h>
#include<netdb.h>

int main()
{
	struct hostent hostbuf,*res = NULL;
	char buf[8192] = {0};
	int err = 0;
	//gethostbyname_r("www.baidu.com",&hostbuf,buf,sizeof(buf),&res,&err);

	in_addr_t addr = inet_addr("127.0.0.1");
	gethostbyaddr_r((char*)&addr,4,AF_INET,&hostbuf,buf,sizeof(buf),&res,&err);

	printf("h_name:%s\n",res->h_name);

	return 0;
}

抱歉!评论已关闭.