nslookup takes a fully qualified
domain name for a host as a command-line argument and returns, among
other things, the IP address of the host in dotted quad
format. For example:
bash$ nslookup www.nrl.navy.mil
Server: 131.122.88.2
Address: 131.122.88.2#53
Non-authoritative answer:
Name: www.nrl.navy.mil
Address: 132.250.119.6 ← IP Address for www.nrl.navy.mil
nslookup to find (and write down!)
the IP address
of www.xkcd.com as a dotted quad:
inet_ntoa has the following
prototype:
char *inet_ntoa(const struct in_addr in);where
struct in_addr includes
the following member:
in_addr_t s_addr;So, given the following definitions and prototypes:
uint32_t htonl(uint32_t hostlong); uint32_t ntohl(uint32_t netlong); uint32_t A; struct in_addr B; char C; char *D; in_addr_t *E;Give the type of each of the following expressions (write invalid for invalid expressions):
a. &A b. *D c. htonl(A) d. B.s_addr e. &B.s_addr f. E->s_addr g. *E... and circle the valid statement calling
inet_ntoa:
C = inet_ntoa(B); C = inet_ntoa(&B); D = inet_ntoa(B); D = inet_ntoa(&B);
in_addr_t a = inet_addr(argv[1]);
printf("%u\n",a);
correctly prints out an IP address for the dotted quad given
in argv[1] on some machines, but not on others.