Team-FLY |
This exercise describes a server that uses UDP to provide information about the services that are available on the host on which it is running. Start by reading the man page for getservbyname if this function is available on your system. Also, get a copy of the netdb.h header file. If your system does not support getservbyname , your server should use a table of your own construction. Design a "service server" that allows clients to find out which services are available on a host. The client sends a UDP request containing the following.
The server returns a response containing the following information.
If the host does not support the service, the server should return “1 for the port number. For simplicity, use the following structure for both the request and the response. #define NAMESIZE 256 struct service { int sequence; int port; char names[NAMESIZE]; } hostsev; Write a UDP test client that prompts the user for host information, protocol and service name. The client chooses a sequence number at random, marshals the request (puts it in the form of the preceding structure), and sends it to the server. The UDP client should take three command-line arguments: the name of the host running the service server, the UDP port number for this service and the timeout value by the client. The client either waits until it receives a response from the server or times out before prompting the user for another request. If the sequence number of a received response does not match the sequence number of the most recent request, the client should print the response, noting the mismatch, and resume waiting for the server to respond. As part of your testing, set a very short timeout in the client and insert a delay in the server between the receipt of the request and the response. The delay will cause a previous packet to be received on the next request. During testing, run several servers on different machines and have multiple clients accessing different servers in turn . |
Team-FLY |