CS 5523 Operating Systems
Laboratory 2 - Spring 2001
A UDP Port Server

Objectives:

Overview:

In this laboratory you will write a server that uses UDP to provide information about the services that are available on the host on which it is running. Prior to doing the lab, print out and read through the man page for getservbyname. Also get a copy of the include file netdb.h. Your server will call the getservbyname as described in Stevens I Section 9.9.

Requirements:

Part I: UDP warmup

The following code consists of a server that waits to receive a UDP message and echoes its contents to standard output. The client sends a UDP message to the server consisting of a line that the user types in from the keyboard. Download the following test programs, compile them and run them. Make sure that you understand them.

Modify the programs so that the server replies with a copy of the message sent from the client. The client should echo the message to standard input.

Modify the programs so that the client uses a timeout value (as specified as a command line argument) to determine how long to wait for a response. Experiment with different values of the time out to determine reasonable values. How does the needed timeout value depend on time of day?

Part II: Accessing host services

In this part of the assignment you will design and write routines to access the information about services available on a host. The client sends a UDP request containing:

The server returns a response containing: If the host does not support the service, the server should return a -1 for the port number. For simplicity, use the following struct for both the request and the response:
    #define NAMESIZE 256
    struct service {
        int sequence;
        int port;
        char names[NAMESIZE];
    } hostsev; 

Rewrite the client so that it prompts the user for host information, protocol and service name. The client chooses a sequence number at random, marshals the request and sends it to the server.

The timeout value and UDP port number of the server should be command line arguments. The client should wait until it receives a response from the server or times out before prompting the user for another request. If the sequence number of a received response does not match the sequence number of the most recent request, the client should print the response noting the mismatch and resume waiting for the server to respond. As part of your testing, set the timeout in the client very short and insert a delay in the server between the receipt of the request and the response. This will cause a previous packet to be received on the next request. During some of your tests you should run several servers on different machines and have a client access different ones in turn. You should also test your client against at least one other class member's server and your server against at least one other class member's client.


Last Revision: January 19, 2002 at 10:30 am