In this lab, you will learn the basics of various networking tools, and will experiment with running a simple network server and client.
Due: 11:59:59 PM, 15 April, 2016.
In this lab, you will use command-line networking tools to observe the networking configuration of your virtual machine, and to simulate the behavior of a web browser. You will also use the echo client and server from Lecture 16 (Chapter 11) to make a connection between two different virtual machines, and will trace the system calls used to set up a network server.
This is a collaborative assignment. You may work in teams of two. Each member of the team should write up and submit their own answers to the questions.
Type jobs. If the server is listed,
you can bring it back to the foreground with
fg jobnumber (where jobnumber
is the number in brackets in the jobs
output, without
the brackets). Then you can kill it normally with Ctrl-C.
Note that if the server is listed as "Stopped" in the output of
jobs
, it is paused and therefore will not respond to
clients. If that is the case, and you want to unpause the server
while you issue other commands, you can put it in the background with
bg jobnumber
If the server is not listed there, it may be running in another terminal,
perhaps even a terminal that has already disconnected. In that case,
you can get a list of your running processes with
ps x . Find the
process ID (first column) of the echoserveri
process,
then do kill PID
YOU MUST PERFORM THIS EXERCISE ON YOUR VM. SSH access will be sufficient for this assignment.
Prepare a plain text file in which you will answer ten questions from this assignment.
You may edit this file either on your computer or on the VM. It will probably be easier if you edit the file in a separate window from where you are running commands.
Investigate your virtual machine's IP addresses:
Use nslookup to look up the IP address
of your virtual machine:
nslookup myvmname.netlab.uky.edu
The address should be near the end.
Check what your machine thinks its own IP address is:
/sbin/ifconfig
Look for "inet addr": but remember that 127.0.0.1
is
the loopback address, which is only accessible from the
same machine.
The program telnet is the client for an
old remote terminal protocol, which has mostly been replaced by
ssh
. However, the telnet client is still useful because it
allows us to connect to any port and interact manually with the server.
Let's try using telnet
to talk to a web server.
Use telnet to connect to www.cs.uky.edu on port 80:
telnet www.cs.uky.edu 80
The server is waiting for a request. Let's give it one. In
telnet, type:
GET /~neil/485/labs/4/test.txt HTTP/1.0
The end of the request is marked by an empty line, so you will have
to press ENTER twice.
If all went well, you should have received a response with two
parts: the headers and the content, separated
by an empty line. The first line of the response should look
like "HTTP/1.1 200 OK
": if the response code was not 200,
double-check the syntax of your GET
request.
The lecture 16 code contains a simple client and server for the
echo protocol.
We will be working with the programs echoclient
(code in echoclient.c
) and
echoserveri
(code in echoserveri.c
and
echo.c
). Both of these programs use the CS:APP library
in csapp.c
.
We recommend using this code as the basis for your Program 5
Download and extract the source code for lecture 16
wget http://www.cs.uky.edu/~neil/485/lectures/16-code.tar.gz
tar xzvf 16-code.tar.gz
The code is in the directory lecture/16/
.
Change to the lecture/16/
directory and rebuild the programs:
make clean; make
Try running the echo server on port 485:
./echoserveri 485
What if we try another port?
./echoserveri 2000
The command netstat shows information
about network connections and listening sockets on your machine.
With your echo server still running (either in the background, or
on a new terminal), run:
netstat -ltn
netstat
output corresponding to
your echo server? Do you recognize any of the other port numbers?
With your echo server still running on port 2000, have another team member
connect to the server from their VM. If you are working alone, you can use
a new terminal on (or a new ssh connection to) the same server.
./echoclient myvmname.netlab.uky.edu 2000
(where myvmname is the name of the VM on which the server is running)
Type a few lines of input, and observe what is displayed on both the server and the client. Press ctrl-d (end of file) in the client to close the connection.
Terminate the server by pressing Ctrl-C. If you put it in the background earlier, you will first have to use fg to bring it back to the foreground.
In lab 3 we saw the program ltrace
,
which traces calls that a process makes to functions from shared libraries.
The program strace is similar, but traces
system calls made by the process to the OS kernel.
Run the server under strace
, sending the trace output to
the file server-trace.txt:
strace -o server-trace.txt ./echoserveri 2000
After a couple of seconds, once the server has started, terminate it with Ctrl-C.
server-trace.txt
the lines of
the system call that are responsible for setting up the listening
socket and accepting connections. This will begin with a call to
socket
and end with a call to accept
.
Do not include the entire strace output—it's huge!
socket
in the trace.
Speculate as to what those other calls might be about.
strace
again to identify which system call fails
when you try to listen on a privileged port (for example, 485).
What system call failed, and what errno code did it return?
man errno
for a full list of possible error codes.)
Upload your text file to csportal, under assignment "Lab 4".