V22.0480-002 Special Topics: Networks
Homework 1: Create a C program that uses gethostbyname() to get the IP addresses of a given machine and print them out.
The gethostbyname() routine takes a host name as a argument and returns a hostent structure. The hostent structure is defined as follows:
char *h_name; /* official name of host */
char **h_aliases; /* alias list */
int h_addrtype; /* address type */
int h_length; /* length of address */
char **h_addr_list; /* list of addresses from name server */
See the manual page for gethostbyname() for more details.
In this assignment, you must write a C program that takes a machine name and prints out the following:
official name of the machine
2. All alias names
3. The IP addresses of the machine
$ getaddr cims.nyu.edu
Official name: cims.nyu.edu
$ getaddr www.irs.gov
Official name: www.omega.fedworld.gov
Make sure you print out an appropriate error message is the information cannot be obtained!
Due date: Monday, October 1
Students with last
names that start with A through G will send their programs to Cindy Chung
(cc462@cs), students with last names that start with H through M will send
their programs to Kong Lei (kl384@cs), and students with last names that start
with N through Z to Jie Zhang (email@example.com)