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:

struct hostent {
     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:

 1. The official name of the machine
 2. All alias names
 3. The IP addresses of the machine
 

Example:

 $ getaddr cims.nyu.edu

 Official name: cims.nyu.edu
 Aliases:
     cims
     www.cims.nyu.edu
     ftp.cims.nyu.edu
     gopher.cims.nyu.edu
     courant.nyu.edu
     courant
     timehost
 Addresses:
     128.122.80.107

What you must turn in:

1. The C code that implements your application.
 

Due date: Monday, February 7

Students with last names that start with A through F will send their programs to Chris Dillon (cjd217@cs), students with last names that start with G through N will send their programs to Yu Qiu (yq205@cs), and students with last names that start with O through Z to Yen-Yu Chen (yyc211@cs)