Lab 2: Fingerd server

Due date: Wednesday, April 16th.
Free extension to Saturday, April 19 @ 5pm if you attend class on Wed.

Reading:

Introduction

In this lab assignment you will write a finger server (fingerd). Your fingerd will answer finger requests from clients.

You'll be writing this server to learn about how to use the server-side of the socket abstraction, as well as the fork,execve, pipe and dup2 system calls. As in the first lab, we use client to mean an application program that establishes connections for the purpose of sending data. We use server to mean an application program that accepts connections in order to service requests by sending back responses, e.g., the finger daemon, the Apache web server, the SSH daemon, etc. For this lab, all network communication will continue to occur over TCP.

For more information about sockets and the various system calls we will use throughout the lab, please see the IPC Tutorial, as well as following man pages:

% man bind
% man listen
% man accept
% man fork
% man execve

Design Requirements

Your finger server will create a blocking TCP socket, either on a specified port or allowing the kernel to assign the port. (Although fingerd normally runs on port 79, you will be using a port above 1024, that you will subsequently specify in your client request. Port numbers below 1024 require root permissions to bind.)

The server will then listen on this socket, accepting connections from clients. Recall that accept returns a new socket that is connected to the client. You should read the client's request (of some user's name) from the socket until you read a newline character ('\r' or '\n'), you read 0 on recv (client's side of connection has closed), or you have read 1024 characters of input. Then fork a new process and exec the finger command locally on this username. If you find a newline character in the input, you will need to replace it with a NULL byte because the finger program does not expect an input with a newline in it. You should then return the output from the local execution of finger to the client.

Your server application should be run in the following way:

% ./fingerd [port]

where the first optional argument is the port on which the server listens on its host. If it is not included, the kernel should assign a port.

Getting Started

To get started, log in to a cluster machine, and copy the starter directory:

% cp -r /usr/class/cs144/src/fingerd .

You can then start editing the fingerd.c starter file, which needs to be completed to implement the assignment, and run make to create the fingerd binary. To add headers and sources to the project, edit the SOURCES and HEADERS lines in the Makefile (e.g., SOURCES = fingerd.c foo.c bar.c).

Some good general coding guidelines can be found on the CS244A coding guidelines page, including some strategies for dealing with handling errors.

Testing

You might wish to test your server using the netcat utility, as shown in class. On the same machine as your server,

% nc localhost [port]

Now, type in your username at the client and press return. It should be sent to the server, which should reply with your finger information.

Requirements

You should make sure your client satisfies these requirements:

Submitting

To submit, run

make submit
from your project directory and submit the resulting tarball on the submission page.

Collaboration policy

You must write all the code you hand in for the programming assignments, except for code that we give you as part of the assignment. You are not allowed to look at anyone else's solution (and you're not allowed to look at solutions from previous years). You may discuss the assignments with other students, but you may not look at or copy each others' code.

Grades

Here is a histogram for the final grades on this assignment:

Click here to see your grade.