CSCI 342: Networks

Semester: Spring 2013
Room: Kng 227
Class Time: Mon/Wed/Fri 2:30pm-3:20pm
Office Hours: Monday,  3:30-4:30pm
Thursday, 4:30-5:30pm
or by appointment
Professor: Cynthia Taylor
email: ctaylor AT oberlin edu
Please include "cs342" in the subject.
Office: King 229
Phone: x58424

Homework 3 - DNS


In this homework, we talk to the global domain name system to resolve domain names into IP addresses. Some good domain names to try, which you definitely will be tested on. Additional domains may be added if we find something interesting in the week.

To get started, check out the hw3 template. This code already does most of the DNS querying and parsing for you. Your responsibility is to modify the hw3 to work as follows:

The file root-servers.txt contains a list of DNS root servers. Your application must use this file to find a working root server to use. You can assume it will always be called root-servers.txt, and exist in the current working directory. If a server does not respond, it must move on to the next server. Its parameters and output are illustrated below. Try to match the output as closely as possible: there should not be lots of extra lines of debug output etc. in the final version.

You are obviously not allowed to use gethostbyname or getaddrinfo for this homework, nor are you allowed to run any executables such as `host' or `nslookup' from inside your program.

Hints

To time out on a recv() call (in case you get no answer), use setsockopt() with the SO_RECVTIMEO option: http://linux.die.net/man/7/socket

Alternatively, you can use alarm(), and set up a handler for SIGALRM. "man alarm()" and "man signal" will help you set that up. Or try the newer sigitimer().

Either way, look for errno==EINTR (for alarm) or errno=EAGAIN (for timeout) when recv() returns -1 when using these techniques to see if you actually timed out. If you want to jump off the deep end of the pool, use a select() call (which takes a timeout parameter) instead of the blocking recv().

You can try out the template version like this:

./hw3 -d -n nameserver -i domain

to find your local DNS server, check your network settings, or run "cat /etc/resolv.conf" on a non-windows machine.

MASSIVE HINT: RECURSION IS YOUR FRIEND.

Example use sessions

Program usage and example runs are given below. Implementation of command line option handling is given in the template. Usage: hw3 [-d] -n nameserver -i domain/ip_address -d: debug

./hw3 -i a.root-servers.net
a.root-servers.net resolves to 198.41.0.4

./hw3 -i kermit.cs.oberlin.edu
kermit.cs.oberlin.edu resolves to 132.162.201.150

./hw3 -d -n 132.162.1.31 -i www.cs.oberlin.edu
How about nameserver 132.162.1.31?

Resolving www.cs.oberlin.edu using server 132.162.1.31 out of 1
Got 2+3+3=8 resource records total.
The name www.cs.oberlin.edu is also known as occs.cs.oberlin.edu.
How about nameserver 192.5.5.241?

Resolving occs.cs.oberlin.edu using server 192.5.5.241 out of 20
Got 0+6+7=13 resource records total.
The name edu can be resolved by NS: f.edu-servers.net
The name edu can be resolved by NS: a.edu-servers.net
The name edu can be resolved by NS: g.edu-servers.net
The name edu can be resolved by NS: l.edu-servers.net
The name edu can be resolved by NS: c.edu-servers.net
The name edu can be resolved by NS: d.edu-servers.net
The name a.edu-servers.net resolves to IP addr: 192.5.6.30
The name c.edu-servers.net resolves to IP addr: 192.26.92.30
The name d.edu-servers.net resolves to IP addr: 192.31.80.30
The name f.edu-servers.net resolves to IP addr: 192.35.51.30
The name g.edu-servers.net resolves to IP addr: 192.42.93.30
The name l.edu-servers.net resolves to IP addr: 192.41.162.30
Ignoring IPv6 record
How about nameserver 192.41.162.30?

Resolving occs.cs.oberlin.edu using server 192.41.162.30 out of 6
Got 0+3+3=6 resource records total.
The name oberlin.edu can be resolved by NS: ns1.oar.net
The name oberlin.edu can be resolved by NS: ocdns1.cc.oberlin.edu
The name oberlin.edu can be resolved by NS: ocdns2.cc.oberlin.edu
The name ns1.oar.net resolves to IP addr: 192.88.193.144
The name ocdns1.cc.oberlin.edu resolves to IP addr: 132.162.1.31
The name ocdns2.cc.oberlin.edu resolves to IP addr: 132.162.1.32
How about nameserver 132.162.1.32?

Resolving occs.cs.oberlin.edu using server 132.162.1.32 out of 3
Got 1+3+3=7 resource records total.
The name occs.cs.oberlin.edu resolves to IP addr: 132.162.201.24
www.cs.oberlin.edu resolves to 132.162.201.24

./hw3 -i www.yahoo.com.tw
www.yahoo.com.tw resolves to 98.139.102.145

./hw3 -i 128.30.76.78
128.30.76.78 resolves to golf.csail.mit.edu

Testing

You can use this script to test your program. The results of this script ARE NOT your final grade. This script checks for only domains and it will check the last word of the last line of your program output as the final result. I will also be checking your debug output, and making sure your program works with unresponsive root-servers.

Handin

We will be using Handin to turn in all assignments. Turn this in for class 342, assignment 3.