gethost.c
资源名称:NetProg03.rar [点击查看]
上传用户:gzxinfenfa
上传日期:2015-02-06
资源大小:279k
文件大小:1k
源码类别:
ICQ弱点检测代码
开发平台:
Visual C++
- #include <stdio.h>
- #include <unistd.h>
- #include <string.h>
- #include <netdb.h>
- #include <sys/types.h>
- #include <sys/stat.h>
- #include <fcntl.h>
- int main(int argc,char **argv)
- {
- struct hostent *host;
- int i=0;
- int fd;
- char buf[256];
- if(argc<2)
- {
- printf("Usage:%s host_namen",argv[0]);
- return 1;
- }
- host = gethostbyname(argv[1]);
- if(host == NULL)
- {
- printf("gethostbyname error:%sn", hstrerror(h_errno));
- }
- else
- {
- printf( "h_name:%sn",host->h_name );
- printf( "h_length:%dn",host->h_length );
- printf( "h_addrtype:%dn",host->h_addrtype);
- for(i=0; host->h_aliases[i]!=NULL;i++)
- {
- printf("h_alias%d:%sn",i+1,host->h_aliases[i]);
- }
- for(i=0;host->h_addr_list[i]!=NULL;i++)
- {
- printf("ip%d:%sn",i+1,inet_ntoa(*(struct in_addr *)host->h_addr_list[i]));
- }
- }
- struct in_addr addr;
- inet_aton("202.117.112.3",&addr);
- host = gethostbyaddr((char *)&addr,4,AF_INET);
- if(host!=NULL){
- printf("h_name:%sn",host->h_name);
- }
- else
- printf("gethostbyname error:%sn",hstrerror(h_errno));
- return 0;
- }