linux 网络编程---域名解析

来源:互联网 发布:python绝技 代码 下载 编辑:程序博客网 时间:2024/06/06 20:40

引入我的代码片:

#include#include#include#include#include#includeint main(int argc,char **argv){struct hostent *host;char **p;char src[32];if(argc<2){printf("Pleasee intput addr:(like www.google.com)\n");return -1;}host=gethostbyname(argv[1]);if(host==NULL){printf("gethostbyname error!\n");return -1;}else{printf("host-->name:%s\n",host->h_name);if(host->h_addrtype==AF_INET){printf("host type:AF_INET\n");}elseprintf("The host type don't know!\n");printf("host length-->length:%d\n",host->h_length);p=host->h_aliases;for(;*p!=NULL;p++){printf("host-->aliases:%s\n",*p);}p=host->h_addr_list;for(;*p!=NULL;p++){//printf("host-->ip:%s\n",*p);printf("host-->ip:%s\n",inet_ntop(AF_INET,*p,src,sizeof(src)));//printf("host-->ip:%s\n",inet_ntop(host->h_addrtype,*p,NULL,32);}}}
运行结果:


0 0
原创粉丝点击