V22.0480-002 Special Topics: Networks

 
 
Homework 3: Create a networking application using the socket interface to the "UNIX local loopback" transport provider, and use signal handling to keep track of child exit status.
 
For this assignment, you must modify Homework #2 to use the "UNIX Loopback Protocol" instead of TCP, and modify the server to log the exit status of all of its children.
 
The "UNIX Loopback Protocol" can only be used between two processes on the same system. It is generally used as an inter-process communication facility.  So, the server and the client must both run on the same machine.  Therefore, the client must be modified to not require a machine name as an argument.
 
To create a socket into the UNIX Loopback Protocol, you must specify the AF_UNIX protocol family, as follows:
 
        fd = socket(AF_UNIX, SOCK_STREAM, 0);
 
An address in the UNIX Loopback Protocol is a UNIX file name.  If the file exists, then the address is in use. If the file does not exist, then the address is free to be used by your application.
 
The address is stored in a sockaddr_un structure, defined in sys/un.h. It has the following definition:
 
        struct  sockaddr_un {
                short   sun_family;      /* AF_UNIX */
                char    sun_path[108];   /* path name */
        };
 
Granted, the structure does not fit into a sockaddr structure, but the UNIX kernel has a series of "if" conditions to handle this special case.
 
Please use an address that corresponds to a filename of the form "/tmp/ss#", where "ss#" is your student ID. For fun, when your server process is running, do an "ls -l" on the file to see the file attributes. You will notice that there is an "s" or a "p" in the first column, indicating that the file is not a real file at all, but rather an address. Also for fun, try to "cat" the file or do other file operations on it.
 
One other thing: the server is responsible for removing the file when it is finished. So, if your server process must exit, make sure you unlink the file you used as an address. When the server tries to bind to the address and the file exists, you will get a message like "address already in use". If that occurs, you must remove the file.
 
Additionally, you must modify the server to catch the SIGCHLD signal, and call a corresponding signal handler.  In that handler, you should get the exit status of the child, and print out the PID and exit status of each child.  For example, the server should print the following for each child process:
 
Child with PID pid exited with an exit status of num (signal num)
 
Also, make sure you block critical sections appropriately.  In this program, you should use the new sighold() and sigrelse() functions to block signals, and check for EINTR if you don’t.
 
What you must turn in:
 
1. The C code that implements the client-side of the application.
2. The C code that implements the server-side of the application.
 
Due date: Tuesday, October 30