Goals:
Collaboration: You will complete this lab in teams of 2-3 of your choice. You may consult me or your classmates with proper attribution.
netserv. In another, run netclient.
Briefly explain what you see.
nslookup hostname, where
hostname is the name of the computer you are working on, to learn
the IP address of that computer \.
netserv and netclient
again. Explain what you see.
netclient when netserv
is not running? Try this and explain what you see.
netserv
and netclient on any computer, without having to
change the IP address and recompile the client? The way we will do
this is by using the getaddrinfo(3) library
call. This function lets us supply a hostname as a string, and it
will resolve that hostname to a result of type struct
sockaddr. The program
my-nslookup.c
illustrates the use of getaddrinfo(3). Download this
program, compile it, run it a few times supplying different
hostnames as arguments, and review the code to understand how it
works.
my-nslookup.c
to resolve this hostname to a result of type struct
sockaddr, and then use the result you obtain to connect to this
address rather than the hard-coded IP_ADDRESS.
wget(1) program allows you to fetch the contents
of a URL and save it to a local file. If you've never
used wget, try using it to fetch the file named
by
http://www.cs.grinnell.edu/~weinman/csc/213/2008F/index.html
In this part of the lab, we will build a simple analog
to wget. Our program will take a URL as a
command-line argument and write the response from the web server
to standard output.
GET path HTTP/1.0↵
HOST: hostname↵
↵
http://www.cs.grinnell.edu/. The HTTP
header is separated from the contents of the file by a blank
line. What information do you see in the header?
http://www.cs.grinnell.edu/does-not-exist. How
is the HTTP header different from what you saw in step
12?
wwwserv.c to understand what you
observed.
ROOT constant to
specify the directory in which the web server should look for
files. Does this guarantee that a malicious web client cannot
access files outside of the web server's root directory? If so,
explain why. If not, give an example of a request a client could
make to obtain an "unauthorized" file.
A note on sockets. Run wwwserv again and use the client you
wrote in part B to request the
url http://localhost:8000/. Then,
run the command "netstat --inet". You will see a list
of all open Internet domain sockets on the computer, such as the
following:
Active Internet connections (w/o servers)
Proto Recv-Q Send-Q Local Address Foreign Address State
tcp 0 0 localhost.localdom:8000 localhost.localdo:42526 TIME_WAIT
The TIME_WAIT state is used to ensure that "stray" packets from
previous connections do not interfere with new connections, when a
new socket is opened on the same port number as an old
connection. In practice, it means you cannot open another socket
using the same port number for about two minutes after the
previous socket is closed. (You may have already discovered this
in part A of the lab.)
For this reason, wwwserv accepts a port number as
an optional command-line argument. This will allow you to
easily cycle through a few different server port numbers (e.g.,
8000, 8001, 8002, 8003) as you are testing your
server.
Serving content. Modify wwwserv.c to write the
actual contents of the file to the connection socket, rather
than "Content of file goes here." To test the server, you
may wish to use the WWW client program you wrote in Part
B.
A good strategy is to iteratively read chunks of data from the file into a character array and then write them to the socket. (Much like you did in Lab 3.)
fork. Note that the parent process
should not wait for a child to complete its execution
before accepting the next connection. If it waits for each
connection to complete before starting the next, then it's not
concurrent!
Parts A & B: Due Friday 11/7
Part C: Due Monday, 11/10