nslookup on the Unix lab machine you
usually use, what is:
a. it's name as you entered it b. it's canonical name c. it's IP address
/etc/resolv.conf. You see
the IP addresses of several name servers --- these are the
nameservers your machine will contact to
answer nslookup queries. Use
nslookup to get
the names for each of these IP addresses, and list each IP
address / name pair.
gethostbyname is considered poor form
now. Instead, getipnodebyname should be
used. Show how in the code for sym2ip shown
below would be modified to use
getipnodebyname in place of the call
H = gethostbyname(argv[1]);.
struct hostent {
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* host address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses from name server */ ← the raw addresses, not dotted quads!
Just to muddy things up a bit:
although h_addr_list has type char**,
they really mean void**, in that
an entry h_addr_list[0], for
instance, could point to any kind of
object. In fact, for IPv4, it's
really pointing to an 'unsigned int'.
So ... you must cast that pointer to
an (unsigned int*) to use it right.
};
Suppose we have the following deifnitions:
struct hostent *p, A;What are the types of the following expressions:
p*p&pA*A&Ap->h_nameA.h_aliases[0](unsigned int*)p->h_addr_list[0](*p).h_lengthp.h_length&A.h_addrtype