?? lookup.c
字號:
/* lookup.c: * * Example of gethostbyname(3) : */#include <stdio.h>#include <unistd.h>#include <stdlib.h>#include <string.h>#include <errno.h>#include <sys/socket.h>#include <netinet/in.h>#include <arpa/inet.h>#include <netdb.h>extern int h_errno;intmain(int argc,char **argv) { int x, x2; struct hostent *hp; for ( x=1; x<argc; ++x ) { /* * Look up the host name : */ hp = gethostbyname(argv[x]); if ( !hp ) { /* Report lookup failure */ fprintf(stderr, "%s: host '%s'\n", hstrerror(h_errno), argv[x]); continue; } /* * Report the findings : */ printf("Host %s :\n",argv[x]); printf(" Officially:\t%s\n", hp->h_name); fputs(" Aliases:\t",stdout); for ( x2=0; hp->h_aliases[x2]; ++x2 ) { if ( x2 ) fputs(", ",stdout); fputs(hp->h_aliases[x2],stdout); } fputc('\n',stdout); printf(" Type:\t\t%s\n", hp->h_addrtype == AF_INET ? "AF_INET" : "AF_INET6"); if ( hp->h_addrtype == AF_INET ) { for ( x2=0; hp->h_addr_list[x2]; ++x2 ) printf(" Address:\t%s\n", inet_ntoa( *(struct in_addr *) hp->h_addr_list[x2])); } putchar('\n'); } return 0;}
?? 快捷鍵說明
復制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -