Your browser is unsupported

We recommend using the latest version of IE11, Edge, Chrome, Firefox or Safari.

Homework 2: DNS resolution

Due date: Feb. 8, 2019 start of class

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.

  • nibbles.cs.uic.edu
  • www.cs.uic.edu
  • www.yahoo.com.tw
  • 128.30.76.78

To get started, check out the hw3 template from https://github.com/bitslab/cs450/tree/master/dns-resolver.

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.

Turn-in instructions

Use this classroom invitation link: https://classroom.github.com/a/63LTq2cG

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 nibbles.cs.uic.edu
nibbles.cs.uic.edu resolves to 131.193.34.150


./hw3 -d -n 192.228.79.201 -i www.cs.uic.edu
Resolving www.cs.uic.edu using server 192.228.79.201
The name edu can be resolved by NS: a.edu-servers.net
The name a.edu-servers.net resolves to IP addr: 192.5.6.30

Resolving www.cs.uic.edu using server 192.5.6.30
The name uic.edu can be resolved by NS: uic-dns2.uic.edu
The name uic-dns2.uic.edu resolves to IP addr: 128.248.7.50

Resolving www.cs.uic.edu using server 128.248.7.50
The name www.cs.uic.edu resolves to IP addr: 131.193.32.29
www.cs.uic.edu resolves to 131.193.32.29


./hw3 -d -i www.yahoo.com.tw
Resolving www.yahoo.com.tw using server 198.41.0.4
The name tw can be resolved by NS: e.dns.tw
The name a.dns.tw resolves to IP addr: 203.73.24.8

Resolving www.yahoo.com.tw using server 203.73.24.8
The name com.tw can be resolved by NS: d.twnic.net.tw
The name a.twnic.net.tw resolves to IP addr: 192.83.166.9

Resolving www.yahoo.com.tw using server 192.83.166.9
The name yahoo.com.tw can be resolved by NS: ns4.yahoo.com

Resolving ns3.yahoo.com using server 198.41.0.4
The name com can be resolved by NS: c.gtld-servers.net
The name a.gtld-servers.net resolves to IP addr: 192.5.6.30

Resolving ns3.yahoo.com using server 192.5.6.30
The name yahoo.com can be resolved by NS: ns1.yahoo.com
The name ns1.yahoo.com resolves to IP addr: 68.180.131.16

Resolving ns3.yahoo.com using server 68.180.131.16
The name ns3.yahoo.com resolves to IP addr: 121.101.152.99

Resolving www.yahoo.com.tw using server 121.101.152.99
The name www.yahoo.com.tw is also known as rc.yahoo.com.

Resolving rc.yahoo.com using server 192.228.79.201
The name com can be resolved by NS: h.gtld-servers.net
The name a.gtld-servers.net resolves to IP addr: 192.5.6.30

Resolving rc.yahoo.com using server 192.5.6.30
The name yahoo.com can be resolved by NS: ns1.yahoo.com
The name ns1.yahoo.com resolves to IP addr: 68.180.131.16

Resolving rc.yahoo.com using server 68.180.131.16
The name rc.yahoo.com is also known as rc.g01.yahoodns.net.

Resolving rc.g01.yahoodns.net using server 198.41.0.4
The name net can be resolved by NS: i.gtld-servers.net
The name a.gtld-servers.net resolves to IP addr: 192.5.6.30

Resolving rc.g01.yahoodns.net using server 192.5.6.30
The name yahoodns.net can be resolved by NS: ns1.yahoo.com
The name ns1.yahoo.com resolves to IP addr: 68.180.131.16

Resolving rc.g01.yahoodns.net using server 68.180.131.16
The name g01.yahoodns.net can be resolved by NS: yf2.yahoo.com
The name yf1.yahoo.com resolves to IP addr: 68.142.254.15

Resolving rc.g01.yahoodns.net using server 68.142.254.15
The name rc.g01.yahoodns.net is also known as any-rc.a01.yahoodns.net.

Resolving any-rc.a01.yahoodns.net using server 128.63.2.53
The name net can be resolved by NS: a.gtld-servers.net
The name a.gtld-servers.net resolves to IP addr: 192.5.6.30

Resolving any-rc.a01.yahoodns.net using server 192.5.6.30
The name yahoodns.net can be resolved by NS: ns1.yahoo.com
The name ns1.yahoo.com resolves to IP addr: 68.180.131.16

Resolving any-rc.a01.yahoodns.net using server 68.180.131.16
The name a01.yahoodns.net can be resolved by NS: yf2.yahoo.com
The name yf1.yahoo.com resolves to IP addr: 68.142.254.15

Resolving any-rc.a01.yahoodns.net using server 68.142.254.15
The name any-rc.a01.yahoodns.net resolves to IP addr: 206.190.60.37
www.yahoo.com.tw resolves to 206.190.60.37


./hw3 -d -i 128.30.76.78
Resolving 128.30.76.78 using server 198.41.0.4
The name in-addr.arpa can be resolved by NS: d.in-addr-servers.arpa
The name a.in-addr-servers.arpa resolves to IP addr: 199.212.0.73

Resolving 128.30.76.78 using server 199.212.0.73
The name 30.128.in-addr.arpa can be resolved by NS: auth-ns1.csail.mit.edu

Resolving auth-ns2.csail.mit.edu using server 192.228.79.201
The name edu can be resolved by NS: l.edu-servers.net
The name a.edu-servers.net resolves to IP addr: 192.5.6.30

Resolving auth-ns2.csail.mit.edu using server 192.5.6.30
The name mit.edu can be resolved by NS: bitsy.mit.edu
The name bitsy.mit.edu resolves to IP addr: 18.72.0.3

Resolving auth-ns2.csail.mit.edu using server 18.72.0.3
The name auth-ns2.csail.mit.edu resolves to IP addr: 128.52.32.80

Resolving 128.30.76.78 using server 128.52.32.80
128.30.76.78 resolves to golf.csail.mit.edu