Lab 5: Network Programming

In this lab, you'll use functions that are common for client-side network programming. Section 4.4 describes many of the functions and data structures that you will need to use. In addition to general I/O functions (such as close(), read(), and write()), you should also consult the C documentation as needed for the following functions:

  • connect(), freeaddrinfo(), getaddrinfo(), inet_ntop(), socket()

This lab also relies on correct use of multiple C structs that are central to socket programming. Consult Chapter 4 of the textbook as needed to distinguish and use the following:

  • struct addrinfo, struct sockaddr, struct sockaddr_in, struct sockaddr_in6

Preliminaries

Set up a bare repository on stu.cs.jmu.edu based on the instructions in the CS 361 Submission Procedures, using the name lab5-net.git.


Implementation requirements: Gathering and interpreting network information

Make the following edits in client.c and main.c. This portion of the lab is focused on providing the basic functionality of the nslookup utility. After completing this implementation, you should compare your output with that of nslookup.

  1. Implementation addr_string() to convert an IP address into the correct format (IPv4 dotted decimal vs. IPv6 colon hexademical). If the server parameter is NULL, return no address information. All returned strings must be dynamically allocated (caller will free() them).
  2. Use addr_string() as part of the implementation of serv_string() to display more information about the passed server. Where addr_string() only formats the address, serv_string() also displays information about the transport and network layer protocols.
  3. Implementat get_server_list() to use DNS to resolve a human-readable hostname. Note that the proto string can be a name (such as http) or a number formatted as a string (such as 80), but the logic of your implementation should not need to examine that parameter explicitly.
  4. Complete the designated portion of main() to support command-line queries of servers. If the protocol is 53 (DNS) or 67 (DHCP), use UDP instead of TCP.


James Madison University logo


© 2011-2024 Michael S. Kirkpatrick.
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License.