Exercises


8.1

We have two applications, one using TCP and the other using UDP. 4,096 bytes are in the receive buffer for the TCP socket and two 2,048-byte datagrams are in the receive buffer for the UDP socket. The TCP application calls read with a third argument of 4,096 and the UDP application calls recvfrom with a third argument of 4,096. Is there any difference?

8.2

What happens in Figure 8.4 if we replace the final argument to sendto (which we show as len ) with clilen ?

8.3

Compile and run the UDP server in Figures 8.3 and 8.4 and then the UDP client in Figures 8.7 and 8.8. Verify that the client and server work together.

8.4

Run the ping program in one window, specifying the -i 60 option (send one packet every 60 seconds; some systems use -I instead of -i ), the -v option (print all received ICMP errors), and the loopback address (normally 127.0.0.1). We will use this program to see the ICMP port unreachable returned by the server host. Next, run our client from the previous exercise in another window, specifying the IP address of some host that is not running the server. What happens?

8.5

We said with Figure 8.5 that each connected TCP socket has its own socket receive buffer. What about the listening socket; do you think it has its own socket receive buffer?

8.6

Use the sock program (Section C.3) and a tool such as tcpdump (Section C.5) to test what we claimed in Section 8.10: If the client binds an IP address to its socket but sends a datagram that goes out some other interface, the resulting IP datagram still contains the IP address that was bound to the socket, even though this does not correspond to the outgoing interface.

8.7

Compile the programs from Section 8.13 and run the client and server on different hosts . Put a printf in the client each time a datagram is written to the socket. Does this change the percentage of received packets? Why? Put a printf in the server each time a datagram is read from the socket. Does this change the percentage of received packets? Why?

8.8

What is the largest length that we can pass to sendto for a UDP/IPv4 socket, that is, what is the largest amount of data that can fit into a UDP/IPv4 datagram? What changes with UDP/IPv6?

Modify Figure 8.8 to send one maximum-size UDP datagram, read it back, and print the number of bytes returned by recvfrom .

8.9

Modify Figure 8.25 to conform to RFC 1122 by using IP_RECVDSTADDR for the UDP socket.




UNIX Network Programming Volume 1, Third Edition
Unix Network Programming, Volume 1: The Sockets Networking API (3rd Edition)
ISBN: 0131411551
EAN: 2147483647
Year: 2003
Pages: 441

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net