05 Tcpip3 Slides
05 Tcpip3 Slides
Introduction
In TCP/IP, the transport layer consists of two different
protocols.
⋅ Transmission control protocol (TCP).
⋅ User datagram protocol (UDP).
Basic idea:
⋅ User processes (applications) interact with the TCP/IP
protocol suite by sending/receiving TCP or UDP data.
⋅ Both TCP and UDP in turn use the IP layer for delivery of
packets.
TCP and UDP
TCP User process UDP User process
TCP UDP
IP
Host
Port Numbers
0 15 16 31
Source Port Destination Port
Sequence Number
Acknowledgment Number Header of
U A P R S F TCP
HLEN Reserved R C S S Y I Window
(4 bit) (6 bit) G K H T N N Datagram
Checksum Urgent Pointer
Options Padding
Data of
Data TCP Packet
(Payload)
TCP Header Fields
Source port (16 bits)
⋅ Identifies the process at the source.
Destination port (16 bits)
⋅ Identifies the process at the destination.
Sequence number (32 bits)
⋅ Used for reliable delivery of message
⋅ Each byte of message is assigned a 32-bit number that is
incremented sequentially. Specifies the number assigned to the
first byte of data in the encapsulated TCP message segment.
TCP Header Fields
Acknowledgment Number (32 bits)
⋅ Used by remote host to acknowledge receipt of data.
⋅ Contains the number of the next byte expected to be
received.
HLEN (Header Length) a.k.a. Data Offset field (4 bits)
⋅ Specifies the header length in number of 32-bit words.
⋅ This information is needed because the Options field has
variable length, so the header length is variable too.
Reserved field (6 bits) must be zero. This is for future use.
TCP Header Fields
Flags (6 bits) - There are six flags.
URG—Indicates that the urgent pointer is in use.
ACK—Indicates that acknowledgement number is valid.
PSH—(push) Indicates that data should be passed to the
application as soon as possible, end of message.
RST—Resets the connection. It is also used to reject a
connection attempt
SYN—Synchronizes sequence numbers to initiate a connection.
FIN—Means that the sender of the flag has finished sending
data.
⋅ A connection request is sent by making SYN=1 and ACK=0.
⋅ A connection is confirmed by sending SYN=1 and ACK=1.
⋅ When the sender has no more data, FIN=1 is sent to
release the connection.
TCP Header Fields
0 15 16 31
Source Port Destination Port
Length Checksum
Data
UDP header fields
Source port 16 bit
⋅ Identifies the process at the local end
Destination port 16 bit
⋅ Identifies the process at the remote end
Length 16 bit
⋅ Specifies the size of the datagram in bytes (UDP header
plus data)
Checksum 16 bit
⋅ Computed in the same way as TCP. Filled with zeros if not
used. Optional in IPv4, mandatory in IPv6.
Berkeley Socket Interface
How to develop a network application?
⋅ The best way is to use some standard and well-accepted
protocol.
⋅ At the data fink layer level, use Ethernet
⋅ At the network layer level, use IP.
⋅ At the transport layer level, use TCP.
⋅ At the application layer level, use a standard API like the
Berkeley Socket Interface