CS 485 Lab 4
Networking

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.

Networking

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.

Note:
If, when you run the echo server, you receive an error about the address already being in use, that is most likely because you already have a copy of the server running. Two things to try:
  1. 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

  2. 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

Steps to Perform

YOU MUST PERFORM THIS EXERCISE ON YOUR VM. SSH access will be sufficient for this assignment.

  1. Prepare a plain text file in which you will answer ten questions from this assignment.

    1. 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.

    2. Q0: Questions to answer in the text file appear in a box like this one. Include the question number with your answer.

      For question 0, list the names of classmates you worked with on this assignment.
  2. Investigate your virtual machine's IP addresses:

    1. Use nslookup to look up the IP address of your virtual machine:
      nslookup myvmname.netlab.uky.edu
      The address should be near the end.

    2. 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.

    3. Q1: Why might the two addresses be different? Is there anything special about the "192.168" block of IP addresses? Try a web search for "192.168 special".
  3. 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.

    1. Use telnet to connect to www.cs.uky.edu on port 80:
      telnet www.cs.uky.edu 80

    2. 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.

    3. 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.

    4. Q2: Copy and paste the headers you received, including the response code.
    5. Q3: Copy and paste the content of the page. What URL can you use to retrieve the same content in a web browser?
  4. 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

    1. 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/.

    2. Change to the lecture/16/ directory and rebuild the programs:
      make clean; make

    3. Try running the echo server on port 485:
      ./echoserveri 485

    4. Q4: What error message did you receive?
    5. What if we try another port?
      ./echoserveri 2000

    6. Q5: What is the smallest port number that works? Try a web search for "privileged port".
    7. 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

    8. Q6: What is the line of the netstat output corresponding to your echo server? Do you recognize any of the other port numbers?
    9. 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.

    10. 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.

  5. 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.

    1. 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.

    2. Q7: Copy and paste from your 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!
    3. Q8: That wasn't the only call to socket in the trace. Speculate as to what those other calls might be about.
    4. Q9: Use 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?

      (The trace shows the error code after the system call's return value. The error code is an all-uppercase identifier beginning with the letter "E"; see man errno for a full list of possible error codes.)
  6. Upload your text file to csportal, under assignment "Lab 4".