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 and execve 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
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, and then fork a new process and execve the finger command locally on this username. You should 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.
We have provided a skeleton sc project directory. It is available in ~class/src/fingerd.tar.gz. Start by unpacking the source code in your home directory. On the class machines, you can do so with the following commands:
% tar xzf ~class/src/fingerd.tar.gz % cd fingerd % setenv AUTOCONF_VERSION 2.13 % sh ./setup automake: configure.in: installing `./install-sh' automake: configure.in: installing `./mkinstalldirs' automake: configure.in: installing `./missing' configure.in: 22: required file `./ltconfig' not found automake: Makefile.am: installing `./INSTALL' automake: Makefile.am: installing `./COPYING' + autoconf + set +x %
The skeleton source tree contains source file fingerd.c, where you need to implement your echo server.
Next, you must configure the software and generate a Makefile--a set of instructions for how to compile the software. For this class, we will use the GNU autoconf and automake tools to generate Makefiles. On the class machines, generate the Makefile with the following commands:% setenv DEBUG -g % ./configure creating cache ./config.cache checking for a BSD compatible install... /usr/bin/install -c checking whether build environment is sane... yes ... creating Makefile creating config.h %
Once the software is configured, you can build fingerd by running
gmake
. (Note that this is gmake
with
a g, and not make
.)
% gmake gcc -DHAVE_CONFIG_H -I. -I. -I. -g -O2 -c fingerd.c /bin/sh ./libtool --mode=link gcc -g -O2 -static -o fingerd fingerd.o mkdir .libs gcc -g -O2 -o fingerd fingerd.o %That's it! You've now built
fingerd
.
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. any data typed into stdin at the client should be output at your server, and echoed back to the client.
For example, using the system fingerd running on port 79:101 class-serv:~> nc localhost 79 mfreed ^R Login: mfreed Name: Michael Freedman Directory: /home/c/mfreed Shell: /usr/local/bin/tcsh On since Tue Jan 27 13:35 (EST) on ttyp1 from ludlow.scs.cs.nyu.edu Mail last read Fri Jan 23 03:58 2004 (EST) No Plan.
You must write all the code you hand in for the programming assignments, except for code that we give you as part of the assigment. 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.
% gmake distcheck rm -rf fingerd-0.0 mkdir fingerd-0.0 chmod 777 fingerd-0.0 here=`cd . && pwd`; \ top_distdir=`cd fingerd-0.0 && pwd`; \ distdir=`cd fingerd-0.0 && pwd`; \ cd /home/c/dm/sc \ && automake-1.4 --include-deps --build-dir=$here --srcdir-name=/home/c/dm/sc --output-dir=$top_distdir --gnu Makefile chmod -R a+r fingerd-0.0 ... gmake[1]: Leaving directory `/disk/c3/scratch/dm/fingerd-0.0/=build' rm -rf fingerd-0.0 ============================================== fingerd-0.0.tar.gz is ready for distribution ============================================== %To turn in your distribution, copy it to the directory
~class/handin/lab2/username
where
username is your username:
% cp fingerd-0.0.tar.gz ~class/handin/lab2/`logname`/ %To create a script file, use the
script
command. When
you run script, everything you type gets saved in a file called
typescript. Press CTRL-D to finish the script. The typescript should
be copied to the same directory as the software distribution. For
example:
% script Script started, output file is typescript % testfingerd ./fingerd fingerd: connect test: passed fingerd: server read test: passed fingerd: server send known test: passed fingerd: server send unknown test: passed fingerd: multiple connect test: passed fingerd: server read at multiple connect test: passed fingerd: server write at multiple connect test: passed test-fingerd: passed 7 failed 0 % ^D Script done, output file is typescript % cp typescript ~class/handin/lab2/`logname`/ %If you have any problems about submission, please contact the TA or instructor.