Table of Contents

Programming Assignment 1: Mock Name Server (MNS)

Please check the FAQ section for updates on instructions.

Packet Structure

Please use the following packet structure for your programs. You can essentially use the same code to set the fields as you did in PA0. (The figure provided previously in PA0 pdf was incorrect. That is, it did not match the code which we posted in FAQ for setting the Type/R fields. We have updated the figure, which is posted below). For setting/decoding the type field, R bit and other fields, please refer to the FAQ below.

Testing your program

You should use the client you coded in PA0 for testing your server. At beginning, you should test the basic lookup function. Once this is working, you will test the server for redirection functionality. We can use this client executable which can handle the redirection responses for testing purposes.

Send email to the TA (shravan [AT] cs.wisc.edu)[use “CS640:” in subject] if you have any questions regarding the assignment.

Submission Instructions

What to submit:

You will need to submit the source code along with a Makefile, located in a directory called p1/. Compress the directory into a single tar.gz file and name it p1.tar.gz. Do not submit object files, or compiled executables.

The Makefile should have two rules: clean and all.

clean : will delete previous .o files, executables, etc.

all : should produce a single executable called client.

The TA will run the following sequence of operations to execute and test your code:

Please test to make sure that these commands can execute in sequence without any intervention.

How to submit:

First add the following line to your .cshrc.local file (located in your home directory):

set path = ($path /s/handin/bin)

Then run the following command at the shell prompt:

source ~/.cshrc.local

Finally, to handin your files, enter the following command:

handin -c cs640-1 -a PA1 -d <directory>

where <directory> is the path to the directory where your tar.gz file is located. Note: handin will go through the specified directory and hand in all the necessary files, so make sure the directory contains only p1.tar.gz file.

Frequently Asked Questions

(1) The man pages for some of the functions needed for the assignment are retrieving documentation for the perl functions first. To change this, please enter the following command at the command prompt:

setenv MANPATH /usr/share/man

(2) For running the client, make sure that you provide the integer value of the request type for the -r option.

(3) Constructing the packet – There are many ways to create a packet. memcpy is one of the safest and easiest ways. Here is a small example how you can use memcpy.

//2 bytes of protocol
char packet[pktsize]; //You will have to compute the size of the packet beforehand. it will be 8 (i.e. header size) + the size of data field.
unsigned short int n_protocol= htons(640); // make sure that you convert it into network byte order as the server expects
memcpy(&packet[0], (char *) &n_protocol, sizeof(n_protocol)); //see the man page for memcpy
int offset = sizeof(n_protocol); //This should be 2 (i.e., 2 bytes or 16 bits)

(4) When you put the hostname in the packet, you should also count the \0 in the hostname for the size of packet.

The following is two simple examples for what the payload should look like and what the length should be

1. The host name is tom3.cs.wisc.edu
The payload of sending message should look like this:
tom3.cs.wisc.edu_XXX where _ is the '\0' and X is zero padding and the length of the entire packet should be 8 (header) + 20 = 28

2. the host name is foghorn.cs.wisc.edu the payload of sending message should look like this
foghorn.cs.wisc.edu_ where _ is '\0'and length should be 8 + 20 =28

(5) Machine IP address: Use ping to find the server's IP address such as ping emperor28.cs.wisc.edu

(6) Endianness issues: There is no ensured endian for your host. You need to use htons, htonl, ntohs, ntohl to ensure the proper endian for network and local host. For this project, the process should be like this

When local host handles protocol, seq, length, and etc., the orientation of data should be host endian ( big- or small-)

Before you send it through network, you should use hton to transform them to network endian

When receiving it through network, you should use ntoh to transform them back to host endian before you do any further processing

(7) For the reserve bit and operation type, you need to use bit wise operator: