CSE 342 - Lab 2: DNS

Purpose: Gain experience with manipulating IP addresses and with translation between IP addresses and DNS names.

Every host (actually, every network interface) on the Internet has an internet protocol (IP) address. Most hosts also have human-readable names. Some names correspond to multiple addresses; some addresses correspond to multiple names. The domain name service (DNS) is the distributed database that stores this information. In this lab, we will write code to translate between the two kinds of identifiers by calling library functions that interact with DNS for us.

This lab is a little less well-defined than what you may be accustomed -- you are expected to figure more out yourself (primarily by finding and carefully reading man pages).

Exercises:

  1. Write a program that:
    1. Accepts a character string input containing a DNS name.
    2. Looks up the host name database entry for the input DNS name using gethostbyname().
    3. Prints the official name, the list of aliases (if any) and all the Internet addresses for the input host. (Note that these addresses are in a binary form***, so they can't be printed directly.) Print the Internet addresses as character strings.
  2. Write a second (similar) program that:
    1. Accepts a character string input containing an IP address.
    2. Looks up the host name database entry for the input DNS name using gethostbyaddr().
    3. Prints the official name, the list of aliases (if any) and all the Internet addresses for the input host. Print the Internet addresses as character strings.

To verify your programs, try resolving a name for one of the suns (such as ariel.cse.lehigh.edu), www.yahoo.com, and sunlab.cse.lehigh.edu. Compare the results you get with the host(1) utility.

Bonus Exercise:

  1. Write versions of your programs that are IPv6 compatible. You can use getipnodebyname(3SOCKET).


Note: *** Recall that information can be represented in many ways. For example, the number 109 can be stored in one byte (using the char data type, and equivalent to 'm'), or across two bytes (using the short int type), or as three bytes (as the array of characters '1', '0', '9' or their ASCII value equivalents), or across four bytes (using the long int type). The converse is also true. If, in a particular memory location, when you read the byte, it could be read as the letter 'm' or as the value 109.


Last revised 28 August 2008, Prof. Davison.