CS162mp10 - Network Programming Lab Exercise [You can work alone, or in groups of two students per group]. Write three C programs: 1. ngetputd.c 2. nget.c 3. nput.c ngetputd.c ngetputd.c or "Network Get/Put Daemon" is a server program that listens for connections from client programs "nget.c" and "nput.c". It is intended to run on the server machine. On receiving a connect request, ngetputd forks a child and lets the child handle the connection and service the request from the client, and returns to listening for new connections. The ngetputd child that handles the connection should allow the nget.c client program to get only files from the server that are readable by the world, and should return an error to the client if the file requested is not world-readable. Also the ngetputd child should put all files uploaded by the nput.c client program in the single location /var/publicfiles/ on the server machine, and this directory should have the permissions drwxrwxrwt /var/publicfiles The commands sudo mkdir /var/publicfiles sudo chmod 1777 /var/publicfiles will take care of creating this directory and giving it the proper permissions. These restrictions on what files can be gotten from the server and where uploaded files will be placed, will simplify the writing of the three programs, ngetputd.c, nget.c, and nput.c. nget.c The nget.c program is intended to run on the client machine. It should be invoked as: ./nget HOSTNAME:/DIRECTORY/FILENAME where HOSTNAME is an Internet hostname with a proper DNS entry somewhere on the Internet, like curry.ateneo.net, or HOSTNAME is the name of a neighbor machine in CTC-214 lab, with an IP address entry in the /etc/hosts file of the client machine. The nget program connects to the server machine specified as HOSTNAME, and requests the server for the specified FILENAME in the specified DIRECTORY. If the file exists and is world-readable, the server program ngetputd will deliver the file to the client program nget, and in turn nget will save the file in the current directory on the client machine. Otherwise, if the file does not exist, or if the file is not world-readable, then the server will return an error message to the client. For example, the command ./nget pc130:/etc/passwd will request the ngetputd server program on the machine pc130 for the file /etc/passwd. We assume that the client program where you run this command has an entry for pc130 in its /etc/hosts file, like 10.11.81.130 pc130 The server program on pc130 will then deliver the world-readable file /etc/passwd on pc130 to the client, and the nget program on the client will save this file "passwd" in the current directory. nput.c The nput.c program is intended to run on the client machine. It should be invoked as: ./nput /DIRECTORY/FILENAME HOSTNAME For example, the command ./nput /etc/services pc130 will upload the file /etc/services on the client machine to the ngetputd server program on the server machine pc130. The ngetputd server will then write the file "services" in the directory /var/publicfiles/ on the server machine. Some remarks 1. ngetputd runs unattended. Once started, it becomes daemonized, listening for connections. It does not exit unless explicitly stopped by the "kill -9" command. 2. nget and nput are commandline programs that are typed at the command line when needed. They exit() after they have completed their work, or after an error. Required Reading You need to read the following documents (or equivalent documents) before you can write the three programs. These documents are available from my Multiply site 1. netprog.txt - this file containing your programming exercise. 2. NETWORKING_PRELIMINARIES - helps you determine if networking is up and running on your machine. 3. bgnet.pdf ("Beej's Guide to Network Programming Using Internet Sockets") - explains some networking terminology and how to use the networking API: getaddrinfo() socket() bind() connect() listen() accept() send() and recv() sendto() and recvfrom() close() and shutdown() getpeername() gethostname() This is a "must read", and the original is from http://beej.us/guide/bgnet/ 4. services.ods - an OpenOffice spreadsheet document, like the file /etc/services, but lists the reserved ports in increasing numerical order. Great to use if you are looking for a free port for your program. 5. daemon.html - "Unix Daemon Server Programming" from: http://www.enderunix.org/docs/eng/daemon.php - explains how to convert a "normal" program into a "server daemon". Deadline This programming exercise is due before midnight 23:59 o'clock on Monday, February 22, 2010. As usual put all your source code, Makefile, AUTHORS.odt, and README in a directory with your name. The file AUTHORS.odt is an OpenOffice text document with the names, student numbers, email addresses, mobile numbers and 2"x2" photographs of the authors. The file README is a plain text file (optional) where you explain how your program differs from the specifications given by the teacher in this document (enhancements, limitations, unimplemented features, etc). For example: ./dy_thomas_lim_joyce_mp10/ ./dy_thomas_lim_joyce_mp10/ngetputd.c ./dy_thomas_lim_joyce_mp10/nget.c ./dy_thomas_lim_joyce_mp10/nput.c ./dy_thomas_lim_joyce_mp10/Makefile ./dy_thomas_lim_joyce_mp10/AUTHORS.odt ./dy_thomas_lim_joyce_mp10/README Then zip this directory, and email-attach the archive "dy_thomas_lim_joyce_mp10.zip" to the teacher at the address prmanalastas@gmail.com. Have a good time reading and programming! |