
2017-07-27

编译:$gcc -o dns dns。c运行:$。/dns www。avnads。cn$。/dns 192。168。0。8(我的内网IP)程序:#include#include#include#include#include#include#include#includeint main(int argc ,char *argv[]){struct sockaddr_in addr;struct hostent *host;char **alias;if(argc!=2){fprintf(stderr,"Usage:%s hostname|ip。 。...全部

#include

注释: gethostbyaddr()返回对应于给定地址的包括主机名字跟地址信息的hostent结构指针参见: accept(), bind(), connect(), getsockname(), getsockopt(), setsockopt(), listen(), recv(), recvfrom(), select(), send(), sendto(), shutdown(), ioctlsocket().4.2 例程5.2 函数5.2.1 gethostbyaddr()简述: 返回对应于给定地址的主机信息if (inet_aton(argv[1], (struct in_addr*)&dest.sin_addr.s_addr) == 0)

sin_addr),4,AF_INET);printf("Address information of Ip %s\n",argv[1]);}else{/* 否则用户需要输入的是域名,通过域名找主机信息*/host=gethostbyname(argv[1]);printf("Address information of host %s\n",argv[1]);}if(host==NULL){/* 都不是,算了不找了*/printf("No Information found");exit(1);}/*打印主机正式名称*/printf("Official host name:\n%s\n\n",host->h_name);/*打印主机其它名称*/printf("Name aliases:\n");for(alias=host->h_aliases;*alias!=NULL;alias++)printf("%s\n",*alias);/*打印主机系列IP*/printf("\nIp address:\n");for(alias=host->h_addr_list;*alias!=NULL;alias++)printf("%s\n",inet_ntoa(*(struct in_addr *)(*alias)));}。
收起
本文来自电脑杂谈,转载请注明本文网址:
https://www.pc-fly.com/a/ruanjian/article-131984-1.html
炒白菜
好帅