COMPSCI 356: Computer Network ArchitectureFall 2016 |
Home | Syllabus | Assignments | Exams | Piazza |
./dnsclient @<server:port> <name>
Your code should always use a query ID of 1337. After sending the request, your client should wait for a reply for 5 seconds. If no reply is heard within this time window, you should exit indicating that a timeout occurred, by printing out the NORESPONSE message.
To help us compare with the reference solution, your code must print out the packet to standard output using the provided dump_packet function. For example, if you have your packet in buf and it is size bytes, long, you should call dump_packet(buf, size) right before you call sendto(). You should see output like:
[0000] 05 39 01 00 00 01 00 00 00 00 00 00 03 77 77 77 .9...... .....www [0010] 06 67 6F 6F 67 6C 65 03 63 6F 6D 00 00 01 00 01 .google. com.....Your client must then wait for a response from the server, and print the result to standard output using the following format:
IPIf an response to a query contains multiple answers (such as multiple IP addresses or aliases), your client must print an IP or CNAME line for each one of these. If the requested name does not exist, your client must print a NOTFOUND line. If no response is ever received from the server (i.e., you've waited 5 seconds and not received anything), your client must print a NORESPONSE line. Finally, if any other error occurs, your client should print an ERROR line containing a description of the error.CNAME NOTFOUND NORESPONSE ERROR
In this project, you will likely need to use bit masking to access certain bits of data you receive. For example, at one point, you will need to check whether the first bit of a char a is a 1. To check this, you can use the C bitwise AND (\&) and bitwise OR (|):
unsigned char a = ...; if (a & 0x80) { ... }
You can also use masking to set bits. For example, if you wanted to set the least significant bit of a to 0, you can do
a &= 0xfe;
You should develop your client program on the class VM, as these have the necessary compiler and library support. You are welcome to use your own Linux/OS X machines, but you are responsible for getting your code working, and your code must work when graded on the class VM. Your code must be -Wall clean on gcctt>. Do not ask the TA for help on (or post to the forum) code that is not -Wall clean unless getting rid of the warning is what the problem is in the first place.
We have set up several test DNS servers which you should use while developing your code: 152.3.144.151 and 152.3.144.152. You should not send queries directly to any other DNS server (e.g., Duke's DNS servers) until your code is reliably working when sending to our test machine. Otherwise, the server operators may view your packets as a security attack, with undesirable consequences for all involved. If these servers are down, please contact Prof Benson and I will reboot the server.
You can use the wireshark utility in order to diagnose problems with packets that you send out (these will likely be malformatted at the beginning). Wireshark will capture packets that you send and will let you view/explore the various fields. It will warn you about fields that are incorrect or missing, and can guide debugging your packets.
You can use the dig utility in order to help diagnose problems with interpreting responses from the DNS server that you query. To use it, see the man page, and an example of the output is shown below:
bash$ dig www.cnn.com ; <<>> DiG 9.7.3-P3 <<>> www.cnn.com ;; global options: +cmd ;; Got answer: ;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 43304 ;; flags: qr rd ra; QUERY: 1, ANSWER: 4, AUTHORITY: 0, ADDITIONAL: 0 ;; QUESTION SECTION: ;www.cnn.com. IN A ;; ANSWER SECTION: www.cnn.com. 116 IN A 157.166.226.25 www.cnn.com. 116 IN A 157.166.226.26 www.cnn.com. 116 IN A 157.166.255.18 www.cnn.com. 116 IN A 157.166.255.19 ;; Query time: 170 msec ;; SERVER: 192.168.100.1#53(192.168.100.1) ;; WHEN: Mon Mar 12 08:55:51 2012 ;; MSG SIZE rcvd: 93
You will note that the output includes a number of the DNS header fields, as well as the full contents of the question and answer sections (you can also see the output of the authority and additional sections via command-line arguments).
Additionally, we have included a basic test script to check the output of your code against our reference solution and check your code's
compatibility with the grading script. If your code fails in the test script we provide, you can be assured that it will fare poorly when run
under the grading script.
Note:i Verify that 'test' is executable.
To run the test script, simply type
bash$ make test
This will compile your code and then test your DNS client on a number of inputs, comparing the results against the reference solution. If any errors are detected, the test will print out the expected and actual output. For example, you might see something like
bash$ make test ./test Trying with script 'www.cnn.com' [FAIL] Diff in expected output: < www.cnn.com 157.166.226.25 > blah bash$
This indicates that the test with input ./dnsclient was expected to print out the line preceded by < , but instead returned blah (the output is simply a diff between the output of your shell and the reference shell). We include a few sample tests, but these are by no means exhaustive. We expect that you will create additional test to ensure that your programs behave as expected.