Program 1


Gary assigned a program like this last year, and it looked like something fun, so I decided to recycle it.

One thing that's interesting to do is talk to some existing server. For example, you could write a program that connects to the NFS service, the FTP service, or the telnet service on an existing machine (like esus). Some of the protocols involved are complicated enough that this would take a while. But a protocol that is a lot easier to implement is the Post Office Protocol (POP). Some of you are probably familiar with POP servers; if you start a mail client from a PC and tell it that your mail is stored on esus, you have a couple of options for retrieving your mail - using the POP service or the IMAP service.

POP is a simple protocol - you can list your mail, download it, and optionally delete it from the server. The protocol is described in RFC 1725.

For this program, you need to implement a simple POP3 mail client to manage your mail file. It doesn't need to be anything fancy; if you want to beef it up a little, you can get some extra credit. The usage of the program should be

Note: one easy way to get an IP address if you know the host name is to use the ping command - for example, After it prints out the first ping or two, hit <CTRL>-C to stop it.

The program should have a simple command line interface that provides the following functions:

  1. List messages
  2. Display message n
  3. Delete message n
You should retrieve the port number from the services file, rather than hard-coding the value - use the "pop3" service name. (There is also a "pop2" service, which is an older protocol.)

Remember, you shouldn't be running the program on esus, but you can definitely connect to the POP server on esus to test this. In order to have anything interesting happen, you'll need to have some mail in your mail file on esus. If you have your mail set up to forward, you'll need to turn that off for a while - just rename the file .forward in your home directory to something else, then send some mail to your esus address.

You may have to do some experimenting here to figure out exactly what the POP server returns in its messages. Welcome to the real world.


Assignment Submission

NO hard copy, please. Everything should be submitted via email by the due date - mail everything to Anthony. With your source, you should turn in a couple of test runs showing lists of messages, and the interaction that displays and/or deletes messages from your account. You need to list your messages, read at least one message, and delete at least one message in each run. (The second run had better reflect the fact that you deleted a message in the first run.) Use the script command to capture each run.

You should include the following:

The first four things can just be in the body of the email - attach the source and scripts as separate files.

A Catch

One problem here is that you need to send a password to the POP server. If you type the password on the terminal, it will be plainly visible to everyone, and it is equally dangerous to hard code it in a program. The following is a short program that turns off the echo in order to read a password.

/* ============================================================== noecho.c
 *
 * Example of a program that turns off the echo on stdin to read
 * a password and then turns it back on.
 *
 * ========================================================================
 */

#include <stdio.h>
#include <stdlib.h>
#include <termios.h>

void main ()
{
    char             name [32], pass [32];
    struct termios   tios;
   
    /*
     * Get the name with echoing
     */

    printf ("Enter your name: ");
    scanf ("%s", name);
    printf ("The name is %s\n", name);

    /*
     * Output the prompt and then toggle echoing.
     */

    printf ("Enter your password: ");

    /*
     * Get the terminal characteristics
     */

    if (tcgetattr (0, &tios) < 0)
    {
       printf ("Could not get terminal attributes\n");
       exit (-1);
    }

    /*
     * Change echo to off and reset.
     */
    tios . c_lflag ^= ECHO;           /* echo off */
    tcsetattr (0, TCSAFLUSH, &tios);

    /* 
     * Read the password.  For you purists, read each character, echoing
     * an asterisk until a return is entered.
     */

    scanf ("%s", pass);

    /*
     * Reset the property and reset the terminal line.
     */

    tios . c_lflag ^= ECHO;           /* echo on */
    tcsetattr (0, TCSAFLUSH, &tios);

    /*
     * Don't do this, its just a test.
     */

    printf ("\nThe password is %s\n", pass);
   
}