Laboratory 2
Objectives
- Make sure you understand the POP protocol you need to use for your
first programming assignment
- Get some more practice with Unix system calls
- Implement some code that you can use for your programming assignment
Preparation
- Make sure you are familiar with the
first programming assignment.
- Look through the Unix Network Programming Manual to
find out how to get information about network services.
- Look through RFC 1725 and pick out some
of the commands you will need to talk to a POP server.
- Do some research and find out how you can determine the user name of
the logged-in user.
- Make sure you are familiar with the code at the end of the first
assignment that turns off terminal echo so you can enter a password.
Pre-Lab Write-up: The point of the pre-lab prep is to get prepared so
you'll have time in the lab to get everything done. To give some motivation
to do the pre-lab, please submit the following via email to Anthony
before the start of your lab:
- What function call will you use to retrieve the name of the currently
logged in user?
- What two functions do you use to disable and re-enable echo to the
terminal, without changing any other terminal settings?
- What function call will you use to retrieve the port number of a
service given its name (in a C string)?
- What are four different commands you will need to use to talk to a POP
server to manipulate a mailbox?
In Lab Activities
Since I didn't give you much more than a week to work on your first programming
assignment, you get some time in the lab this week to work on some pieces of
the assignment. If you've already got the program working, then the lab should
only take you a few minutes to finish.
For the lab, you will be creating a simple program that will perform the
following steps:
- determine the user name of the currently logged in user
- print out the user name
- prompt the user to enter a password
- turn off echo and read the password, then turn echo on again
- prompt the user to enter a service name
- determine the port number of the specified service (specify the tcp
protocol) and print it out. You should gracefully handle the case where
the service name can't be found.
- exit the program
Hopefully all of this looks like code you can use for the programming
assignment.
Once you have the program running, start a typescript and run the program.
Enter a password, then enter the service name pop3. It should print
out 110 for the port number. Now, with the script still going, run the program
again, enter a password, then enter the service name nosuchservice.
The program should print out some reasonable error message. End the script.
You will also need to actually interact with a POP server, to make sure you
understand how the protocol works. Here's a nifty little trick that you can
use to interact with a number of different TCP-based services: you can use
the telnet program to connect with any TCP port on a server. As long
as the exchange with the server uses ASCII messages, which is true of the POP
protocol, you can just type messages into telnet and see the responses from
the server.
So try the following:
telnet esus.cs.montana.edu 110
It should indicate that you are connected to the POP server - you'll see a
response like this:
+OK POP3 esus.cs.montana.edu v2003.83 server ready
You can start typing POP commands; for instance, type
and see what it sends back. If you typed your login correctly, it should
respond with something like
+OK User name accepted, password please
You can now enter the command to send your password - because you need
to type this in plain text, and you won't be able to turn off the terminal
echo while using telnet, you might want to change your password on esus before
you start this exercise.
You can enter POP commands and see the responses; when you are done, just type
the command
and telnet should exit.
Once you feel comfortable with the POP commands, start a typescript, use telnet
to connect to esus, enter the commands to get authenticated, retrieve the
list of messages from the pop server, retrieve one of the messages on the
list, and exit the POP session. Close the script.
Bonus: If you want to do a little more work on your lab program for
some extra credit, you can do the following:
Modify your program so after you enter your password, you verify that the
password string is actually the correct password for the current user.
(Hint: user passwords are actually stored in an encrypted form in Unix, and
you can't unencrypt them. But you can encrypt a string and see if it
generates the same encrypted password.)
Lab Write-Up
Your lab write-up should include the following information:
- Name and lab section
- A copy of the source for the client program that you wrote for the
lab
- The script of the program runs that retrieve the port for pop3 and
nosuchservice
- The script of the telnet interaction with the POP3 server on esus
- If you did the bonus work, another script that shows a run of the
program where you enter your password correctly, and another script that
shows a run where you enter your password incorrectly.
The lab write-up is due by the end of the day Wednesday for the Tuesday lab
section and by the end of the day Friday for the Thursday lab section.