V22.0480-002 Special Topics: Networks

Homework 3:      Create a networking application using the socket interface
using the "UNIX local loopback" transport provider.

For this assignment, you must modify Homework #2 to use the
"UNIX Loopback Protocol" instead of TCP.

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 a "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.

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: Monday, March 6