📄 lab1.c
字号:
#include <stdio.h>#include <stdlib.h>#include <netdb.h>#include <sys/socket.h>#include <arpa/inet.h>#include <sys/socket.h>int main(int argc,char *argv[]){char **pptr;char str[32];struct hostent *hptr;struct in_addr hipaddr;int n;n=inet_aton(argv[1],&hipaddr);printf("%d %s",n,argv[1]);if(n==0){ if((hptr=gethostbyname(argv[1]))==NULL) printf("gethostbuname error for host: %s\n",argv[1]); printf("offical hostname: %s\n",hptr->h_name); for(pptr=hptr->h_aliases;*pptr!=NULL;pptr++) printf("alias:%s\n",*pptr);switch(hptr->h_addrtype){case AF_INET:case AF_INET6:pptr=hptr->h_addr_list;for(;*pptr!=NULL;pptr++)printf("address:%s\n",inet_ntop(hptr->h_addrtype,*pptr,str,sizeof(str)));break;}}if(n==1){ if((hptr=gethostbyaddr((char *)&hipaddr,4,AF_INET))==NULL) { printf("error\n"); return 1; } printf("offical hostname:%s\n",hptr->h_name); for(pptr=hptr->h_aliases;*pptr!=NULL;pptr++) printf("alias: %s\n",*pptr); switch(hptr->h_addrtype) { case AF_INET: case AF_INET6: pptr=hptr->h_addr_list; for(;*pptr!=NULL;pptr++) printf("address:%s\n",inet_ntoa((struct in_addr)(hipaddr))); break; }}exit(0);}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -