The connect function blocks until either the

Info iconThis preview shows page 1. Sign up to view the full content.

View Full Document Right Arrow Icon
This is the end of the preview. Sign up to access the rest of the document.

Unformatted text preview: > ./hostinfo cs.mit.edu official hostname: EECS.MIT.EDU alias: cs.mit.edu address: 18.62.1.6 In the most general case, multiple domain names can be mapped to multiple IP addresses: unix> ./hostinfo www.aol.com 12.3. THE GLOBAL IP INTERNET 617 code/net/hostinfo.c 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 #include "csapp.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) hostp = Gethostbyaddr((const char *)&addr, sizeof(addr), AF_INET); else hostp = Gethostbyname(argv[1]); printf("official hostname: %s\n", hostp->h_name); 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 = *((unsigned int *)*pp); printf("address: %s\n", inet_ntoa(addr)); } exit(0); } code/net/hostinfo.c Fig...
View Full Document

Ask a homework question - tutors are online