CSE 80 -- Lecture 16 -- Feb 27


Today I gave a shell script version of a (simple) finger client to complement last time's finger daemon. The caret-M below denotes the control-M character (carriage return); in the file a real control-M is embedded.
#!/bin/sh
#
# myfinger -- connects to myfingerd
#
net_redir -s ${FINGER:-1079}@localhost -d 0 -d 1 -- sh -c "echo '$1^M'; cat 1>&3" 3>&1

BTW, the source to netd and net_redir is available. This tape archive as well as the myfingerd and myfinger scripts are also available in the public directory.

A functionally equivalent version is:

#!/bin/sh
#
# myfinger -- connects to myfingerd
#
net_redir -s ${FINGER:-1079}@localhost -d 0 -d 3 -- sh -c "echo '$1^M' >&3; cat"

As an in-class collaboration, we wrote a very simple Web client which uses HTTP 0.9 to obtain Web files:

#!/bin/sh
#
# httpc -- HTTP client; assumes $1 is hostname, $2 is port, $3 is pathspec
# of the URL.
#
net_redir -s $2@$1 -d 0 -d 1 -- sh -c "echo 'GET $3^M'; cat 1>&3" 3>&1
The final assignment is to write the complementary web server. The server should run under netd, just like myfingerd above. The server must be able to (barely) understand both HTTP/0.9 and HTTP/1.0 requests -- in case of HTTP/1.0 requests, the extra request-modifier lines may be ignored. The Web documents that it serves should come from your own htdoc directory, so if the request was
GET /index.html HTTP/1.0 Accept: text/html, text/plain, image/*, */*
your Web server should send the file $HOME/htdoc/index.html.

You should do sanity/security checks, e.g., the pathspec should start with a slash and should not include "..", but I do not require this. Note that you should not leave your code running after you're done testing it, especially if you have not thought hard about what a malicious web client might be able to trick your server into doing.

To debug your web server code, create an htdoc directory and populate it with an index.html, and run the server (call it myhttpd under netd as follows:

$ hostname
uape12.ucsd.edu
$ netd -p 1997 -- myhttpd
and use Netscape or another web browser to visit the URL http://uape12.ucsd.edu:1997/index.html. Note that the hostname portion of the URL matches the hostname of the host on which you are running the web server, and the optional port number matches as well.
[ CSE 80 | ACS home | CSE home | CSE calendar | bsy's home page ]
picture of bsy

bsy@cse.ucsd.edu, last updated Tue Mar 18 15:49:41 PST 1997.

email bsy