CSCI 342: Networks

Semester: Spring 2013
Room: Kng 227
Class Time: Mon/Wed/Fri 2:30pm-3:20pm
Office Hours: Monday,  3:30-4:30pm
Thursday, 4:30-5:30pm
or by appointment
Professor: Cynthia Taylor
email: ctaylor AT oberlin edu
Please include "cs342" in the subject.
Office: King 229
Phone: x58424

Build Your Own Webserver


In this homework, we'll do the server end of http. First download the template in hw2.zip. This time around, the template only contains a Makefile. Based on sockets.c, create a web server application that takes a port and a directory name as arguments, and serves the contents of this directory over http. For example, after building hw2, you should be able to run ./hw2 8080 WWW and then visit http://localhost:8080/index.html, to see the simple test page in the WWW folder of the hw2 template. Clicking on the link should take you to a second page, than contains an image. You may change the files in the WWW directory, as long as there is at least two pages connected by a link, and at least one image embedded in a page.

You need to handle the following cases:

Note that if you use port 80, there is no need to indicate the port in the URL, and you should also be able to fetch the pages with hw0. However, port 80 requires administrative privileges on your machine, which you may not have, depending on what machine you are doing the homework on.

HINT: useful libc functions to use are stat(), strstr()/strcasestr(), sprintf(), sscanf(). The code in examples/sockets/server.c should be very helpful. My entire solution, starting from the 68-line server.c, with lots of comments and nice formatting, is 124 lines. Think before you code and try to keep your code manageable.

Make sure your code works using both a web browser, and the wget command. (man wget for more information)

Handin

We will be using Handin to turn in all assignments. Turn this in for class 342, assignment 2.