Setting up a C programming environment

In PA3 you will be implementing an SMTP server. Compared to Java, C programming environments tend to vary much more significantly between platforms so the instructions for this tutorial will assume that you’re running on the department’s linux servers. These instructions will likely also work on MacOS or WSL, but we won’t make any guarantees. At any rate, the assignments will be tested in a Linux environment, so developing on Linux will probably make your life easier when it comes to debugging failing PrairieLearn tests.

The assignments only require make and a C compiler to be installed, so you shouldn’t have to download anything else. Download the zip archive, extract the files and run make in the extracted directory. It should produce two executables - server and client. The server is already implemented for you; in the next section you’ll complete the implementation of the client. You can test the server with netcat if you wish - simply run the command ./server to start a server that listens on 127.0.0.1. In another terminal window you can connect to the server with nc localhost <port-number>. Read the server.c source file to see which port the server listens on. If everything works properly, netcat will print out a message and then exit.

Introduction to sockets in C

POP is a TCP-based protocols so we’re going to practice working with TCP sockets in C by implementing a simple TCP client. Before diving into the code, we recommend reviewing Beej’s Guide to Network Programming to get an overview of the C sockets API – In particular, sections 2, 3, and 5 will be particularly helpful. Section 6 contains an example client and server implementation, but we suggest attempting to complete the client independently before looking at the solution.

Once you’ve read through the guide, take a look at the client.c file from the archive you downloaded earlier. We’ve provided the scaffolding for a TCP client – you’re responsible for establishing a TCP connection to the server and reading from the connection.