1: /* lookup.c:
2: *
3: * Example of gethostbyname(3):
4: */
5: #include <stdio.h>
6: #include <unistd.h>
7: #include <stdlib.h>
8: #include <string.h>
9: #include <errno.h>
10: #include <sys/socket.h>
11: #include <netinet/in.h>
12: #include <arpa/inet.h>
13: #include <netdb.h>
14:
15: extern int h_errno;
16:
17: int
18: main(int argc,char **argv) {
19: int x, x2;
20: struct hostent *hp;
Linux Socket Programming by Example - Warren W. Gay 215
21:
22: for ( x=1; x<argc; ++x ) {
23: /*
24: * Look up the hostname:
25: */
26: hp = gethostbyname(argv[x]);
27: if ( !hp ) {
28: /* Report lookup failure */
29: fprintf(stderr,
30: \"%s: host \'%s\'\\n\",
31: hstrerror(h_errno),
32: argv[x]);
33: continue;
34: }
35:
36: /*
37: * Report the findings:
38: */
39: printf(\"Host %s :\\n\",argv[x]);
40: printf(\" Officially:\\t%s\\n\",
41: hp->h_name);
42: fputs(\" Aliases:\\t\",stdout);
43: for ( x2=0; hp->h_aliases[x2]; ++x2 ) {
44: if ( x2 )
45: fputs(\", \",stdout);
46: fputs(hp->h_aliases[x2],stdout);
47: }
48: fputc(\'\\n\',stdout);
49: printf(\" Type:\\t\\t%s\\n\",
50: hp->h_addrtype == AF_INET
51: ? \"AF_INET\"
52: : \"AF_INET6\");
53: if ( hp->h_addrtype == AF_INET ) {
54: for ( x2=0; hp->h_addr_list[x2]; ++x2 )
55: printf(\" Address:\\t%s\\n\",
56: inet_ntoa( *(struct in_addr *)
57: hp->h_addr_list[x2]));
58: }
59: putchar(\'\\n\');
60: }
61:
62: return 0;
63: }
프로그래밍 고수횽들 좀 알려주세영~
43 ~ 47번째줄이랑 53 ~ 58번째줄 자세히 설명좀 해주세여ㅠㅠ 모르겠어여 ㅠㅠ 엉엉
댓글 0