讲解CSE 3100留学生、辅导java/python编程语言、讲解Systems Programming
- 首页 >> Python编程CSE 3100 Systems Programming
Homework #6 Due: 10/30/2018
Complete your work in the hw6 folder. Remember to pull, add, commit, and push.
Note: For this homework you will work on a project that has multiple source files. Study the Makefile
and learn how to write rules for such targets.
An implementation of a TFTP server and client has been demonstrated in the lecture. In this assignment
you extend the functionality of the server and client programs. Descriptive error messages should be provided
when commands cannot be executed. Assume filenames do not have white spaces and cannot be longer than
255 characters. The length of the files can be represented by a 32 bit integer. Both the server and client
should only read/write files under the directory where they start. In general the two directories may not be
the same (indeed, the server and client may run on two different machines).
Exercise 1. (20 points) Modify the server to take the port number as an optional command line argument,
and the client to take as optional command line argument the host name, optionally followed by a port
number. The default host name localhost and port 8080 should be used whenever these arguments are not
specified.
Exercise 2. (20 points) Extend the client with a new lls command, which lists the content of the local
directory (the directory in which the client is started). Recall that running the existing ls command lists
the content of the remote directory (the directory in which the server runs).
Exercise 3. (20 points) Extend the client with two new commands, size and lsize, which display the
size in bytes of a remote, respectively local file whose name is given as command argument.
Exercise 4. (20 points) Extend the client with a new command, mget, which takes as argument a list of
file names, separated by one or more spaces or tabs, and transfers the files in the specified order from the
server to the client. The file names may be specified on the same line as the mget command. If no filename
is specified on the same line as mget, the client asks the user to enter one or more filenames on the next line.
You can implement this command by repeating the provided get command.
Exercise 5. (20 points) Improve the code with more error checking, careful string handling, and input
validation (especially on the server side). The example code is written for the purposes of demonstrating
socket programming. It does not check the return value of some function calls and has some vulnerabilities
that are easy to fix. More specifically, improve the code by fixing the following issues.
1. The client uses scanf("%s") to read strings, which may result in buffer overflow.
2. The server does not sanitize the filenames received from the client. Currently, the filename may not
be NUL terminated and the client can specify filenames like "/etc/passwd".
3. Ther server does not report some of the errors. If there is an error, the server should abort the execution
of the current command and report error messages to the client.
You are encouraged to identify and fix more bugs/vulnerabilities.
Enjoy!