五湖醉人
andy851899
全部博文(32)
shell bash脚本(1)
语言(6)
Windows(0)
Linux(10)
UNIX环境高级编程(0)
UNIX网络编程 第1(1)
Oracle(0)
MySQL(3)
2009年(32)
分类: 系统运维
2009-03-24 09:26:28
#include <stdio.h>#include <netdb.h>
/*gethostbyname(),structhostent,hstrerror(),h_errno*/#include <stdlib.h> /*exit()*/#include <arpa/inet.h> /*inet_ntop*/intmain(int argc, char **argv){ char *ptr, **pptr; char str[INET_ADDRSTRLEN]; struct hostent *hptr; while(--argc > 0){ ptr = *++argv; if((hptr = gethostbyname(ptr)) == NULL){ printf("gethostbyname error for host %s: %s\n", ptr, hstrerror(h_errno)); continue; } printf("official hostname %s\n", hptr->h_name); for(pptr = hptr->h_aliases; *pptr != NULL; pptr++) printf("\talias: %s\n", *pptr); printf("The length of address is: %d of %s\n", hptr->h_length, hptr->h_name); switch(hptr->h_addrtype){ case AF_INET: pptr = hptr->h_addr_list; for(; *pptr != NULL; pptr++) printf("\taddress: %s\n", inet_ntop(hptr->h_addrtype, *pptr, str, sizeof(str))); break; default: printf("unknown address type\n"); break; } } exit(0);}
上一篇:The Definitive Guide to MySQL 5随笔
下一篇:分析命令行参数--getopt()
登录 注册