Skip to main content

Goals 

  • Practice with Unix calls for byte-stream network communication. 
  • Continue to develop skills to read and correctly interpret Unix manual pages.

Credits

This lab was developed by Prof. L. Felipe Perrone. Permission to reuse this material in parts or in its entirety is granted provided that this credits note is not removed. Additional students files associated with this lab, as well as any existing solutions can be provided upon request by e-mail to: perrone[at]bucknell[dot]edu

Academic Responsibility

It should go without saying that all the work that you will turn in for this lab will be yours. You should try your best to debug your code on your own, but it’s fine to get help from a colleague as long as that means getting assistance to identify the problem and doesn’t go as far as receiving source code to fix it (in writing or orally).

Set Up

Before you start, do the following on a terminal:

cd ~/csci307/Labs/Lab5
cp ~perrone/csci307/Labs/Lab5/* .

Problem 1

  1. Read the manual pages of gethostbyname(3). Describe how its usage is different from getaddrinfo(3).
  2. Do a web search and do your best to learn and understand why gethostbyname(3) has been deprecated and explain your findings here.
  3. Do your best to understand the C code in echoreq.c and echod.c. Explain why there needs to be no call to bind(2) in echoreq.c and why this system call is essential in echod.c.
  4. Consider the code echoreq.c and echod.c. Explain why the calls the htons(3) are necessary.

After you debug your code and get everything working correctly, add, commit and push your files to your gitlab as follows:

git add answers.txt
git commit -m "lab5-1 completed" 
git push

Problem 2

In this problem you will complete the skeleton code in files echod.c and echoreq.c to create an echo server and an echo request program. To test these, we recommend that you first run echod in your local machine and later run echoreq in a different machine. When you run echoreq, it will send a string to the server and then wait for a response. The server will receive that string and send it back to echoreq without any modifications. When the server’s response arrives at echoreq, the program will print it to the terminal and terminate.

After you debug your code and get everything working correctly, add, commit and push your files to your gitlab as follows:

git add echoreq.c
git add echod.c
git commit -m "lab5-2 completed" 
git push

Problem 3

  1. Rename flightClient-udp.c and flightServer-udp.c to flightClient-tcp.c and flightServer-tcp.c.
  2. Taking inspiration from echoreq.c and echod.c, modify flightClient-tcp.c and flightServer-tcp.c to behave as client and server programs that use SOCK_STREAM sockets. Obviously, you will need to change the socket set up in both programs.
  3. Make your flightServer-tcp.c, create a program that instantiates three different flights (choose their data as you wish) and inserts them all in a global list declared as struct slist *flight_list. Modify the server loop so that when it receives a message from the client, it sends back to the client three instances of a message like: <uint32_t, struct flight> where the uint32_t number is the byte size of a struct flight and the struct flight is data in one of the flights you initialized.
  4. Using your flightClient-tcp.c, create a program that sends a one-byte request to the corresponding server (it doesn’t matter what the data in the request is), receives three messages from the server where each message is in the format <uint32_t, struct flight> storing each of the struct flight data in an instance of struct flight, and prints to the terminal the data for each flight.

After you debug your code and get everything working correctly, add, commit and push your files to your gitlab as follows:

git add Makefile
git add snode.h snode.c
git add slist.h slist.c
git add flight.h flight.c
git add flightClient-tcp.c flightServer-tcp.c
git commit -m “lab5-3 completed” 
git push

Problem 4

Modify the Makefile given to you so that it also generates all the executables in this assignment.

After you debug your code and get everything working correctly, add, commit and push your files to your gitlab as follows:

git add Makefile
git commit -m "lab5-4 completed" 
git push

Grading Rubric

The rubric below shows the number of points that will be earned for each item that compiles and runs correctly. If the item does not compile correctly, 60% of the total points will be deducted. If the item compiles correctly and runs with major errors, 40% of the total points will be deducted. If the item compiles correctly and runs with minor errors, 20% of the total points will be deducted. If the item compiles with warnings, and runs correctly, 10% of the total points will be deducted.

  1. Problem 1.1 [5 points]
  2. Problem 1.2 [5 points]
  3. Problem 1.3 [5 points]
  4. Problem 1.4 [5 points]
  5. Problem 2 [30 points]
  6. Problem 3 [35 points]
  7. Problem 4 [15 points]