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. An example of a local machine (as of Fall 2009) that provides this service is kato.cse.lehigh.edu.

    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?]

    Note that the representation of numeric variables is not the same across all cpu architectures. As a result, the format of numbers sent over a network was standardized, and so when you write programs to read such numbers over the network, you need to convert them. See byteorder(3SOCKET) for useful conversion utilities.

  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. Print the date and time in a human readable form, e.g. Fri Sep 12 11:53:00 2003.

Last revised 24 September 2009.