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:
socket() - Create and return the file
descriptor (a small integer) of a new socket. The socket's
address family, connection type and protocol type are specified
in the call.
sendto() - Send a message through a socket to a
specific destination.
recv() - Receive a message into a local buffer.
Your task:
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?]
recvfrom() to return the address of the
remote host as well as the data value.
recvfrom() in an infinite loop to watch
for multiple returns (you'll need to use
ctrl-C to terminate your program).
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).