Laboratory 2


Objectives

  1. Make sure you understand the POP protocol you need to use for your first programming assignment
  2. Get some more practice with Unix system calls
  3. Implement some code that you can use for your programming assignment

Preparation

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:
  1. What function call will you use to retrieve the name of the currently logged in user?
  2. What two functions do you use to disable and re-enable echo to the terminal, without changing any other terminal settings?
  3. What function call will you use to retrieve the port number of a service given its name (in a C string)?
  4. 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:

  1. determine the user name of the currently logged in user
  2. print out the user name
  3. prompt the user to enter a password
  4. turn off echo and read the password, then turn echo on again
  5. prompt the user to enter a service name
  6. 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.
  7. 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:

It should indicate that you are connected to the POP server - you'll see a response like this: 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 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:


Lab Write-Up

Your lab write-up should include the following information:
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.