CSE342 - Lab 5: UDP Programming

Purpose: Gain experience with socket programming using UDP-based network applications.

Sockets. Most modern operating systems use the socket abstraction to manage interprocess communication connections. As we've seen, a socket is similar to a file descriptor. The following system calls all operate on sockets:

In class we saw how to send and receive data to a particular host via UDP. It is also possible to broadcast data to all hosts on a network. The special address 255.255.255.255 is defined to be the IPv4 broadcast address for all hosts on the local network. You can use this address to complete the second portion below. For more detail on broadcast, see RFCs 919 and 922.

Your task:

  1. Write a program to access the time server on network hosts and print the results.

    The Time Protocol is documented in an RFC. Note that there are several "network time" protocols. Look for the one that uses port 37. Look up the RFC to find out the details such as the message format for the Time Protocol. [Do you see the error in this RFC?]

  2. Rewrite your program to broadcast a request to all timeservers listening on your workstation's local network. You'll need to:

    Identify the responding host and print the time in each response. Use gethostbyaddr(), getnameinfo(), or getipnodebyaddr() to print the responding host's mnemonic name (rather than IP address number).

  3. While not required, see if you can print the date and time in a human readable form, e.g. Fri Sep 12 11:53:00 2003.

Last revised 17 September 2007.