主机条目结构
2016-01-28 22:00
726 查看
#include<stdio.h> #include<errno.h> #include<netdb.h> int main(int argc,char *argv[]) { char **pp; struct in_addr addr; struct hostent *hostp; if(argc != 2) { fprintf(stderr,"usage:%s <domain name or dotted-decimal>\n",argv[0]); exit(0); } if(inet_aton(argv[1],&addr) != 0) {//通过ip来获取主机名 hostp = gethostbyaddr((const char *)&addr, sizeof addr,AF_INET); } else {//通过域名获取主机名 hostp = gethostbyname(argv[1]); } printf("hostname=%s line=%d\n",hostp->h_name,__LINE__); for(pp = hostp->h_aliases; *pp != NULL;pp++) { printf("alias: %s\n",*pp); } for(pp = hostp->h_addr_list;*pp != NULL;pp++) { addr.s_addr = ((struct in_addr *)*pp)->s_addr; printf("address:%s\n",inet_ntoa(addr)); } return 0; }
host entry structure
相关文章推荐
- Linux socket 初步
- Linux Kernel 4.0 RC5 发布!
- linux lsof详解
- linux 文件权限
- Linux 执行数学运算
- 10 篇对初学者和专家都有用的 Linux 命令教程
- Unix 即将迎来 50 岁
- Linux 与 Windows 对UNICODE 的处理方式
- Ubuntu12.04下QQ完美走起啊!走起啊!有木有啊!
- 解決Linux下Android开发真机调试设备不被识别问题
- 运维入门
- 运维提升
- Linux 自检和 SystemTap
- Ubuntu Linux使用体验
- c语言实现hashmap(转载)
- Linux 信号signal处理机制
- linux下mysql添加用户
- Scientific Linux 5.5 图形安装教程