Homework Assignment 2

This assignment is to be done individually. Do not show your answers to others and do not look at other students' solutions. Prevent other students from accessing your solutions (do not put it in a public library). Provide short and concise answers to the questions below.

Question 1 (Sockets, 15%)

(a) When you call 'bind()' on a socket, what happens if you pass 'INADDR_ANY' as address?
INADDR_ANY tells the system to identify the IP address of the local machine (don't have to specify it yourself).
(b) Describe the network traffic that results from a call to 'connect()' on a TCP socket. Assume that the destination address given to connect() is valid (there is a TCP server listening at the specified address).
A 3-way handshake takes place with a SYN packet from the client to the server first, then a SYN/ACK packet from the server to the client and then another ACK from the client to the server.

Question 2 (Servers, 30%)

(a) Describe two potential deadlock situations for servers (i.e., how could a client cause a server to deadlock)?
Iterative servers are prone to deadlocks, e.g., a client could initate a request but never actually make a request and the server keeps waiting for data from the client. Or clients could make requests to the server, the server responses, but the clients ignore these responses, leading to overflowing buffers at the client, then to overflowing buffers at the server and finally a deadlocked server.
(b) What is the purpose of the 'KeepAlive' directive in the Apache 2.0 configuration file?
KeepAlive indicates that the clients use 'persistent' connections, i.e., multiple HTTP requests can share the same connection.
(c) Obtain a freely available web server performance meter (e.g., httperf), install it, learn about its usage, and use it to measure the response times (reply times) of a web server of your choice. Set the performance meter to make requests once per second ten times and average the response times. Show the output of the performance meter for one request. Also, if you receive error messages, mention which errors and how many.
This task should not pose any problems. You could see reduced response times beginning with the 2nd request (if identical requests are sent) because the reply could come from caches.

Question 3 (DNS, 10%)

(a) Show and describe the content of the /etc/resolv.conf file on your Linux computer.
Example: nameserver 129.74.250.100 (IP address of name server, could have several), search cse.nd.edu (if you type 'pluto', your system would try to find 'pluto.cse.nd.edu').
(b) Use the 'host' command with the 'a' parameter (for the 'A' record of the DNS database) on any computer of your choice to retrieve the IP address. Show how you call the host command and the answer you received. Further, use the host command with the 'cname' parameter on 'www.cc.gatech.edu' and show the answer you received.
'host -t a gaia.cc.gatech.edu' would return 'gaia.cc.gatech has address 130.207.3.8' (as example). 'host -t cname www.cc.gatech.edu' returns 'www.cc.gatech.edu is an alias for rhampora.cc.gatech.edu'.

Question 4 (RPC, 15%)

(a) Why do you need a program number, a version number, and a procedure number for RPC servers?
To uniquely identify RPC servers (program number) and procedures of these servers (multiple programs can have multiple procedures). Version numbers allow you to simultaneously use different versions of a program or to develop and test a new version while the old one is still being used.
(b) Why does the output parameter in the server procedure have to be declared 'static'?
To make sure that it is not removed from the stack when the procedure returns so that the RPC runtime can access it (to marshall it and return it back to the client stub).

Question 5 (Programming, 30%)

Imagine a simple TCP-based chat server allowing users to use any TCP client (telnet, for example) to communicate with each other. For this question, you can either implement (and test) the code or just provide the pseudo code (uncompiled code). The focus in this question is not on the correct use of all system call parameters, etc., but the correct sequence of system calls (or library calls) and the correct choice of calls. Also, error handling is not required. The server should be a single process, single thread server that can support exactly 2 clients at once. The server forwards whatever is sent from one client to the other (in both directions). Your server must not insist on any specific ordering of messages, as soon as something arrives on one socket, it will be forwarded to the other socket immediately. As soon as one client terminates the connection, the server can exit. Hints: open two passive sockets and then 'wait' for messages (do not use busy waiting, instead think of an efficient' way of waiting). When you read from a socket and 0 bytes of data are returned, the client has terminated the connection.
Sample program:
sd = socket(...);
bind(sd, ...);
listen(sd, ...);
first = accept(sd, ...);
second = accept(sd, ...);
while (1) {
  FD_ZERO(set); FD_SET(first, &set); FD_set(second, &set);
  select(max(first,second)+1, &set, ...)
  if (FD_ISSET(first, &set)) {
    n = read(first, buff, MAX);
    if (n == 0) break;
    n = write(second, buff, n);
  }
  if (FD_ISSET(second, &set)) {
    n = read(second, buff, MAX);
    if (n == 0) break;
    n = write(first, buff, n);
  }
}

Submission

The due date for this homework is February 25th, 2005, 11.59pm EST. You will use the drop-off boxes, make a directory called "homework2" and place one single file (.ps, .pdf, .doc, or .txt) into this directory. Your file should clearly relate the answers to the questions (e.g., 'Answer 3a:', etc.). If you made any assumptions or encountered problems with the programming tasks, state these clearly in your document.
Late submissions: Unlike with the programming assignments, late homeworks will absolutely NOT be accepted!