Please check the FAQ section for updates on instructions.
Once you have coded up a client program that meets all the specifications, you can test your program by sending request packets to one of the servers running at the following ports.
Server IP (common to all servers): 220.127.116.11
The test servers are designed to be running perennially and will not terminate upon received of a client request of type 5.
Please ensure that your client program is complete and adheres to all project specifications before sending test packets to the server.
For testing purposes, the database used by the server to respond to client requests contains the following records:
|Domain name||IP Address|
If you encounter any problems while attempting to connect to a particular server, use one of the other specified ports. If none of the servers are accessible, try connecting again after a few minutes. If the problem persists, send email to the TA (shravan [AT] cs.wisc.edu)[use “CS640:” in subject]
What to submit:
You will need to submit the source code along with a Makefile, located in a directory called p0/. Compress the directory into a single tar.gz file and name it p0.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:
tar xvfz p0.tar.gz cd p0/ make clean make all ./client -s <server-name> -p <port> -r <type> -d <data> -t <timeout> -n <seq-no>
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:
Finally, to handin your files, enter the following command:
handin -c cs640-1 -a PA0 -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 p0.tar.gz file.
(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, (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)
// 2 bytes of sequence number short int seq=10; short int n_seq_num =htons(seq); // in network byte order memcpy(&packet[offset],(char *) &n_seq_num, sizeof(n_seq_num)); offset += sizeof(n_seq_num);
(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
(7) For the reserve bit and operation type, you need to use bit wise operator:
A. Example to create and R = 1 and Type = 1 (hostname to IP address resolution request from the client)
#define R_MASK 0x01 #define TYPE_MASK 0x0e
// Let us say we want to set the reserve bit and set type to 1 reserve_bit =1; type = 1;
char bit_data; memset(&bit_data, 0, 1); // make it all zeros // R flag bit_data = reserve_bit; // reserve bit is set // Type char type = 1; char data_type = type << 1;
bit_data = bit_data | data_type; // Copy into the packet memcpy(&packet, &bit_data, 1); // offset used should be 4 for packet (Refer to Packet Structure)
// Copy the data byte from index 4 of the packet char recv_data; memcpy(&recv_data, &packet, 1); // byte at offset 4
if((recv_data & R_MASK) > 0) reserve_bit = true;
// Get the type type = (recv_data & TYPE_MASK) >> 1;