11.4 A Simple Example

11.4 A Simple Example

We'll use our sock program to generate some UDP datagrams that we can watch with tcpdump:

 bsdi %  sock -v -u -i -n4 svr4 discard  connected on 140.252.13.35.1108 to 140.252.13.34.9     bsdi %  sock -v -u -i -n4 -w0 svr4 discard  connected on 140.252.13.35.1110 to 140.252.13.34.9 

The first time we execute the program we specify the verbose mode ( -v ) to see the ephemeral port numbers , specify UDP ( -u ) instead of the default TCP, and use the source mode ( -i ) to send data instead of trying to read and write standard input and output. The -n4 option says to output 4 datagrams (instead of the default 1024) and the destination host is svr4. We described the discard service in Section 1.12. We use the default output size of 1024 bytes per write.

The second time we run the program we specify -w0, causing 0-length datagrams to be written. Figure 11.6 shows the tcpdump output for both commands.

Figure 11.6. tcpdump output when UDP datagrams are sent in one direction.
graphics/11fig06.gif

This output shows the four 1024-byte datagrams, followed by the four 0-length datagrams. Each datagram followed the previous by a few milliseconds . (It took 41 seconds to type in the second command.)

There is no communication between the sender and receiver before the first datagram is sent. (We'll see in Chapter 17 that TCP must establish a connection with the other end before the first byte of data can be sent.) Also, there are no acknowledgments by the receiver when the data is received. The sender, in this example, has no idea whether the other end receives the datagrams.

Finally note that the source UDP port number changes each time the program is run. First it is 1108 and then it is 1110. We mentioned in Section 1.9 that the ephemeral port numbers used by clients are typically in the range 1024 through 5000, as we see here.



TCP.IP Illustrated, Volume 1. The Protocols
TCP/IP Illustrated, Vol. 1: The Protocols (Addison-Wesley Professional Computing Series)
ISBN: 0201633469
EAN: 2147483647
Year: 1993
Pages: 378

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