Program 3
One thing that's interesting to do, is talk to some existing server.
For example, the NFS server, the ftp server or the telnet server. This
would be a cruel thing to do. One that is easier to talk to is the
Post Office Protocol (POP) server. Some of you are probably familiar
with the POP server. If you start a mail client from a PC and tell it
that your mail is stored on esus, it will contact to the POP server on
esus and it will download your mail to the PC.
It's basic function is just that. If you connect to the POP server, it
expects to download the contents of a mail file to you. The POP3 protocol
that you need to use is simple and is described in
rfc1725.
Your assignment is to create a client that will use the POP server
to manage your mail file. This doesn't have to be anything fancy, unless
you want to put in the extra effort. A simple command line interface that
lets a person list their messages and look at or delete selected messages
would be great. You could of course, just open the mail file and do this,
but what fun would that be.
For this assignment, use port 110, since that's where the POP3 server is
running. You might notice in /etc/services that port 109 is reserved for
something called "pop2" which is an older service type.
You might think about how you would do this from a remote system. That is,
if the client you wrote would connect over the network to esus and get the
data and display it at the remote host. This really wouldn't be too hard
to do from a PC or another host, since the network programming calls will
work just as well from any other host that supports them.
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.
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.
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
#include
#include
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);
}
Your mail client should be able to list, retrieve and delete messages
from your mailbox with some sort of interaction with the user. Turn in
listings and an example run showing that the commands work.