Network Programming

Homework 3
Frequently Asked Questions

Question:  Can you tell me how these project will be graded?
Answer:  The general formula is:
  • 25% for code quality (comments, readability, structure,...)
  • 50% for basic functionality. Does the program work properly when everything goes well?
  • 25% for an assortment of tests - ability to handle unexpected situations (error checking, handling bad inputs, invalid responses, etc).

The exact tests we will run on your program will not be listed ahead of time, you should expect your client to be abused in all possible ways! Since your program is a client, it's safe to simply print out a message and quit whenever something goes wrong (if you can't recover). This is much harder to handle when your program is a server...

Note: We shouldn't be able to crash your program! By "crash", I mean a SEGV or BUS ERROR, etc. Your program should quit on it's own when something goes wrong.


Question:  What is a bit? a byte? a character? a pointer?
Answer:   Dave has very little hair left as it is... please don't ask questions that can be answered by any CS1 student.
Question:  I'm using x = ( * ((short int *) buff+x)); to extract a short int from a buffer, and I keep getting a BUS ERROR. What's up with that?
Answer:  

On a Sun, You can't access a short int at an odd address. Since DNS messages include variable length fields (domain names), you can end up with short ints on odd addresses.

Use memcpy!

Question:   Is it possible that a single domain name in a resource record can involve following more than one pointer (compression)?
Answer:   Yes.

Question:   How do I handle CNAME replys.
Answer:   Handle them any way you like, we won't test your code on any hostnames that are not the real name. As a student pointed out - if you don't handle CNAME responses right, it can lead to the situation where you keep getting bounced back and forth between 2 servers. This project does not require you to handle CNAMES responses, as we will not test your code on any host aliases (we will always use the real name).

Question:  

Can you give me a hint on how I could declare a dns message structure? I know the sizes of the fields, and how to do bit masking and all that, but I don't know how to define a message in terms of ints, chars, longs, etc.. I am assuming it would be all ints, but I am not sure.

Answer:  

For a message structure like the one used by DNS, it's not really possible to build one C structure definition that can be sent/received as a DNS message. The variable length fields are a problem, but there is also a problem with having short ints aligned on odd addresses (this is not supported on many architectures, include Sparc).

I suggest you define whatever structures you want for your own use, and write a function that can convert this structure to/from a DNS message as a bunch of bytes (char). So the actual address you give to sendto() is just a char *:

	
char buf[512]; // UDP DNS messages are 512 bytes max! 

// build a DNS query in buf. Assume you have variables/structures/whatever
// that are set to the values you want to put in the DNS message

// assumes id is a short int with a valid DNS message
//  identifier in network byte order

memcpy(buf,&id,2);

// assumes flags is a short int that is set to the right value to 
// represent the flag settings for this query

memcpy(buf+2,&flags,2);

// set the rest of the message in buf.
 ...

// now we can call sendto

res = sendto(sock,buf,len,0,serveraddr,sockaddrlen);

// and check for errors, etc. here 


Question:  

Can you provide a sample query and response? I'm not sure what I should be getting back.

Answer:  

Below is the output of a client that first prints out the fields in the query it is sending, then prints out the response received and all the resource records in it. This specific query asked the name server running on 128.213.1.1 for the address of "www.rpi.edu" without requesting recursion.:

Request size is 29
-------REQUEST-------
ID: -4370
QR: 0
OPCODE: 0
AA: 0
TRUNC: 0
RD: 0
RA: 0
RCODE: 0
# Questions: 1
# Answers: 0
# Authority: 0
# Additional: 0
------QUESTION-------
DNAME: www.rpi.edu.
TYPE: 1
CLASS: 1
SENDING==================



Received a response: 269 bytes

-------RESPONSE-------
ID: -4370
QR: 1
OPCODE: 0
AA: 0
TRUNC: 0
RD: 0
RA: 1
RCODE: 0
# Questions: 1
# Answers: 2
# Authority: 5
# Additional: 5
------QUESTION-------
DNAME: www.rpi.edu.
TYPE: 1
CLASS: 1
---------RESOURCE RECORD------------
DNAME:  PTR(12) : 3www3rpi3edu [www.rpi.edu.]
TYPE: 1 (A)
CLASS: 1
TTL: 4223
RDLEN: 4
---------RESOURCE RECORD------------
DNAME:  PTR(12) : 3www3rpi3edu [www.rpi.edu.]
TYPE: 1 (A)
CLASS: 1
TTL: 4223
RDLEN: 4
---------RESOURCE RECORD------------
DNAME: 3rpi3edu [rpi.edu.]
TYPE: 2 (NS)
CLASS: 1
TTL: 79338
RDLEN: 15
---------RESOURCE RECORD------------
DNAME:  PTR(61) : 3rpi3edu [rpi.edu.]
TYPE: 2 (NS)
CLASS: 1
TTL: 79338
RDLEN: 11
---------RESOURCE RECORD------------
DNAME:  PTR(61) : 3rpi3edu [rpi.edu.]
TYPE: 2 (NS)
CLASS: 1
TTL: 79338
RDLEN: 23
---------RESOURCE RECORD------------
DNAME:  PTR(61) : 3rpi3edu [rpi.edu.]
TYPE: 2 (NS)
CLASS: 1
TTL: 79338
RDLEN: 6
---------RESOURCE RECORD------------
DNAME:  PTR(61) : 3rpi3edu [rpi.edu.]
TYPE: 2 (NS)
CLASS: 1
TTL: 79338
RDLEN: 6
---------RESOURCE RECORD------------
DNAME:  PTR(80) : 8netserv13its PTR(61) : 3rpi3edu [netserv1.its.rpi.edu.]
TYPE: 1 (A)
CLASS: 1
TTL: 15630
RDLEN: 4
---------RESOURCE RECORD------------
DNAME:  PTR(107) : 8netserv2 PTR(89) : 3its PTR(61) : 3rpi3edu [netserv2.its.rp
i.edu.]
TYPE: 1 (A)
CLASS: 1
TTL: 12361
RDLEN: 4
---------RESOURCE RECORD------------
DNAME:  PTR(130) : 3ns313appliedtheory3com [ns3.appliedtheory.com.]
TYPE: 1 (A)
CLASS: 1
TTL: 165331
RDLEN: 4
---------RESOURCE RECORD------------
DNAME:  PTR(165) : 3ns2 PTR(134) : 13appliedtheory3com [ns2.appliedtheory.com.]
TYPE: 1 (A)
CLASS: 1
TTL: 196
RDLEN: 4
---------RESOURCE RECORD------------
DNAME:  PTR(183) : 3ns1 PTR(134) : 13appliedtheory3com [ns1.appliedtheory.com.]
TYPE: 1 (A)
CLASS: 1
TTL: 175
RDLEN: 4