The first two applications, ping and traceroute, are diagnostic applications that use ICMP.
traceroute builds its own UDP packets to send and reads ICMP replies.
The three popular routing protocols demonstrate the variety of transport protocols used by routing protocols. OSPF uses IP directly, employing a raw socket, while RIP uses UDP and BGP uses TCP.
The next five are UDP-based applications, followed by seven TCP applications and four that use both UDP and TCP. The final five are IP telephony applications that use SCTP exclusively or optionally UDP, TCP, or SCTP.
[ Team LiB ]
UNREGISTERED VERSION OF CHM TO PDF CONVERTER PRO BY THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER PRO BY THETA-SOFTWARE
[ Team LiB ]
2.14 Summary
UDP is a simple, unreliable, connectionless protocol, while TCP is a complex, reliable, connection-oriented protocol. SCTP combines some of the features of both protocols, providing additional features beyond those found in TCP. While most applications on the Internet use TCP (the Web, Telnet, FTP, and email), there is a need for all three transport layers. In Section 22.4, we will discuss the reasons to choose UDP instead of TCP. In Section 23.12, we will discuss the reasons to choose SCTP instead of TCP.
TCP establishes connections using a three-way handshake and terminates connections using a four-packet exchange. When a TCP connection is established, it goes from the CLOSED state to the ESTABLISHED state, and when it is terminated, it goes back to the CLOSED state. There are 11 states in which a TCP connection can be, and a state transition diagram gives the rules on how to go between the states. Understanding this diagram is essential to diagnosing problems using the netstat command and understanding what happens when an application calls functions such as connect, accept, and close.
TCP's TIME_WAIT state is a continual source of confusion with network programmers. This state exists to implement TCP's full-duplex connection termination (i.e., to handle the case of the final ACK being lost), and to allow old duplicate segments to expire in the network.
SCTP establishes an association by using a four-way handshake and terminates connections using a three-packet exchange. When an SCTP association is established, it goes from the CLOSED state to the ESTABLISHED state, and when it is terminated, it goes back to the CLOSED state. There are eight states in which an SCTP association can be, and a state transition diagram gives the rules on how to go between the states. SCTP does not need the TIME_WAIT state as TCP does due to its use of verification tags.
[ Team LiB ]
[ Team LiB ]
Exercises
2.1 We have mentioned IP versions 4 and 6. What happened to version 5 and what were versions 0, 1, 2, and 3? (Hint: Find the IANA's "Internet Protocol" registry. Feel free to skip ahead to the solution if you cannot visit http://www.iana.org.)
2.2 Where would you look to find more information about the protocol that is assigned IP version 5?
2.3 With Figure 2.15, we said that TCP assumes an MSS of 536 if it does not receive an MSS option from the peer. Why is this value used?
2.4 Draw a figure like Figure 2.5 for the daytime client/server in Chapter 1, assuming the server returns the 26 bytes of data in a single TCP segment.
2.5 A connection is established between a host on an Ethernet, whose TCP advertises an MSS of 1,460, and a host on a Token Ring, whose TCP advertises an MSS of 4,096.
Neither host implements path MTU discovery. Watching the packets, we never see more than 1,460 bytes of data in either direction. Why?
2.6 In Figure 2.19, we said that OSPF uses IP directly. What is the value of the protocol field in the IPv4 header (Figure A.1) for these OSPF datagrams?
2.7 In discussing SCTP output, we said that the SCTP sender must wait for the cumulative acknowledgment point to pass sent data before the data could be freed from the socket buffer. If a selective acknowledgment shows that data is acknowledged beyond the cumulative acknowledgment point, why can't the data be freed?
[ Team LiB ]
UNREGISTERED VERSION OF CHM TO PDF CONVERTER PRO BY THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER PRO BY THETA-SOFTWARE
[ Team LiB ]
Part 2: Elementary Sockets
Chapter 3. Sockets Introduction Chapter 4. Elementary TCP Sockets Chapter 5. TCP Client/Server Example
Chapter 6. I/O Multiplexing: The select and poll Functions Chapter 7. Socket Options
Chapter 8. Elementary UDP Sockets Chapter 9. Elementary SCTP Sockets Chapter 10. SCTP Client/Server Example Chapter 11. Name and Address Conversions [ Team LiB ]
[ Team LiB ]
Chapter 3. Sockets Introduction
Section 3.1. Introduction
Section 3.2. Socket Address Structures Section 3.3. Value-Result Arguments Section 3.4. Byte Ordering Functions Section 3.5. Byte Manipulation Functions
Section 3.6. inet_aton, inet_addr, and inet_ntoa Functions Section 3.7. inet_pton and inet_ntop Functions
Section 3.8. sock_ntop and Related Functions Section 3.9. readn, writen, and readline Functions Section 3.10. Summary
Exercises [ Team LiB ]
UNREGISTERED VERSION OF CHM TO PDF CONVERTER PRO BY THETA-SOFTWARE
UNREGISTERED VERSION OF CHM TO PDF CONVERTER PRO BY THETA-SOFTWARE
[ Team LiB ]
3.1 Introduction
This chapter begins the description of the sockets API. We begin with socket address structures, which will be found in almost every example in the text. These structures can be passed in two directions: from the process to the kernel, and from the kernel to the process. The latter case is an example of a value-result argument, and we will encounter other examples of these arguments throughout the text.
The address conversion functions convert between a text representation of an address and the binary value that goes into a socket address structure. Most existing IPv4 code uses inet_addr and inet_ntoa, but two new functions, inet_pton and inet_ntop, handle both IPv4 and IPv6.
One problem with these address conversion functions is that they are dependent on the type of address being converted: IPv4 or IPv6. We will develop a set of functions whose names begin with sock_ that work with socket address structures in a protocol-independent fashion. We will use these throughout the text to make our code protocol-independent.
[ Team LiB ]
[ Team LiB ]
3.2 Socket Address Structures
Most socket functions require a pointer to a socket address structure as an argument. Each supported protocol suite defines its own socket address structure. The names of these structures begin with sockaddr_ and end with a unique suffix for each protocol suite.