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.
- Implementation
addr_string()to convert an IP address into the correct format (IPv4 dotted decimal vs. IPv6 colon hexademical). If theserverparameter isNULL, returnno address information
. All returned strings must be dynamically allocated (caller willfree()them). - Use
addr_string()as part of the implementation ofserv_string()to display more information about the passedserver. Whereaddr_string()only formats the address,serv_string()also displays information about the transport and network layer protocols. - Implementat
get_server_list()to use DNS to resolve a human-readablehostname. Note that theprotostring can be a name (such as) or a number formatted as a string (such ashttp
), but the logic of your implementation should not need to examine that parameter explicitly.80
- Complete the designated portion of
main()to support command-line queries of servers. If theprotocolis 53 (DNS) or 67 (DHCP), use UDP instead of TCP.