CS6420 - Programming Assignment 1

Overview

For this assignment, you are to implement a very simple telnet client, which we will call GTelnet. GTelnet should accept a single parameter which specifies the name of the remote system to connect to. Once a connection to the remote system is established, you can just check for keyboard input and forward that to the remote system if some input is available. You also need to check for screen output data from the remote and print it on the screen if present.

This assignment is extremely simple, so nobody should find it particularly difficult. Both the TA and the instructor have already coded this project, so we know any pitfalls you may run into. I coded it in about 3 hours, so you should be able to do it easily as well.

Which system to use

In order to keep some consistency in what all of us are doing, we should all develop this program on a SUN Sparc Solaris system. There are several Solaris machines generally available, notably elvis.cc.gatech.edu and asperta.cc.gatech.edu. You can log into any system on the CoC network, and then telnet to elvis by entering "telnet elvis" (from a unix system), or using the telnet window on WindowsNT and opening a connection to "elvis". Elvis has 4 CPU's and lots of memory, so it should not be a bottleneck for us getting our work done.

Coding the Program

You need to start by creating a TCP socket with the "socket" call, and then filling in the information into the "struct sockaddr_in" structure in order to connect to the remote host. You will probably need gethostbyname and getservbyname in order to do this. Once the socket address structure is completed, call "connect" to create the connection.

After the connection is created, simply loop polling for either keyboard input or remote output via the socket. The simplest way to do this is with the "select" system call, and FD_ZERO, FD_SET, and FD_ISSET. See the man page in section 3c for select if you are not familiar with it. Once select reports that data is availble from either the socket or standard input, read the data with the "read" system call. To write data to the socket (to send data to the remote), use the "write" system call.

The only tricky part is that the telnet server tries to negotiate various options once the connection is established. Read RFC854 at address http://www.rfc-editor.org/rfc.html for a discussion of how this works. To keep our program simple, we can just deny any request for an option from the server so we don't have to implement it.

Your program should exit in one of two cases. First if the remote system closes the socket (which it will do if you enter "exit" from the keyboard), or if the user types ctrl-d from the keyboard (which is an end-of-file). In either case, just exit the main loop, close the socket, and exit.

Compiling and linking your program

Use the GNU C compiler at /usr/local/bin/gcc for both compiling and linking. The socket calls we made require libsocket.a and libnsl.a, which you specify with -lsocket and -lnsl.

Testing Your Program

We will test your program simply by connecting to some remote system, entering a user name and password, running "ls -la", and typing "exit". We will then repeat the process, but enter ctrl-d instead of "exit".

Grading Criteria

Proper Connection to Remote 20%
Proper Screen Display of Remote Data 20%
Proper Keyboard Input Processing 20%
Exit on Remote Disconnect 15%
Exit on Keyboard End-of-File 15%
Quality of Code (Neatness, commenting, etc) 10%

Turning In Your Program

Email your "gtelnet.c" program (not as an attachment, but just as the body of the message) to ta-email-address@cc. One way to do this is (on unix):

mail ta-email-address@cc < gtelnet.c

Contact Information:

riley@cc.gatech.edu
College of Computing
Georgia Institute of Technology
Atlanta, GA 30332-0280

Last Modified: Jun. 9, 1998