
Transport Layer + Network Layer = TCP Stack
The header of each TCP packet includes two port numbers: a source and a
destination port. Each of them has a length of 16 bits (see TCP packet header).
Ports aren’t physical doors; there are logical entities defined by the
TCP stack software. There are 56 535 different TCP ports (216-1),
port 0 is reserved and not used.
The “well-known” port numbers are spelled out in RFC 1700.

Like pictured below the TCP header has a length of 32 Bits and consists
of:
Contains the port number from where the packet was sent, is dynamically
assigned by TCP Stack.
Contains the port number where the packet should be routed by TCP Stack
@ the destination.
Often it is a “well-known” port which is associated with a server
application.
Number for session initializing in TCP (see three way
handshake).
Number for session initializing in TCP (see three way
handshake).
This field describes where in the TCP packet the header ends and the
data starts. It is equal to the TCP header in 32-bit words.
This field is reserved for the future.

·
URG
(Urgent)
The Urgent pointer in the TCP
Header field is significant.
·
ACK
(Acknowledge)
The Acknowledgement field is
significant. This packet is used to acknowledge earlier packets.
·
PSH
(Push Function)
This is the push function,
used to flush data through the TCP layer.
·
RST
(Reset)
The connection should be
reset, due to error or other interruption.
·
SYN
(Synchronize)
The system should synchronise
sequence numbers. This code bit is use during session establishment.
·
FIN
(Finish)
There is no mire data from
the sender. Therefore, the session should be torn down.
This field is used to control the number of outstanding packets sent
between systems. It gives each side of the communication a way to control the
flow of the packets from the other side to make sure that all packets are
received properly and acknowledgement appropriately before new packets are
sent.
It is used to verify that the TCP packet (header and data) was not
corrupted in its journey across the network.
This field has a Pointer into the data of the packet to indicate where
urgent information is located.
This set of variable length fields can indicate additional information
about the TCP processing capabilities of either side of the connection. For
example, if a TCP layer can handle only TCP packet of a given maximum size, the
System can indicate this limitation in the TCP Options.
This field includes enough bits set to zero to extend the length of the
TCP header so that it ends on a 32-bit boundary. It’s just fluff included in
the header to make sure everything lines up evenly.
Fields for Data (or urgent Data)

Suppose a machine called
Both Sides have agreed upon a set of sequence numbers that will be used
in the communication. All packets going from
The URG and PSH code bit are used less often then the other four code
bits. The URG code bit means that the data stream includes some urgent data. If
the URG cod bit is set to one, the Urgent Pointer field will indicate where in
the data stream the really urgent data is located. TCP doesn’t specify how the
urgent data should be handled by the application; it merely allows the
application on one side of a connection to flag the urgent data flag the other
side of the connection. The PSH code bit means that the TCP layer should flush
the packet through the stack quickly, not queuing it
up for later delivery.
UDP is connectionless – the Protocol doesn’t know or remember the state
of a connection. It doesn’t have any concept of session initiation,
acknowledgement, tear down, or anything else. Furthermore UDP itself does not
retransmit lost packets, nor does it put them in the proper order. So if packet
1, packet 2 and packet 3 are sent out, the destination may receive packet 2,
packet 1, and another copy of packet 1. Packet 1 is lost and packet 1 was
somehow transmitted twice. UDP is inherently unreliable. It may loss packets or
sent them out of order. But sometimes unreliable is OK, particularly when it
cans buy your speed. Some applications are much more interested in getting
packets across the network quickly, and don’t need super-high reliability. Such
applications do not want the overhead of a three way handshake, sequence
numbers on every packet, acknowledgement, etc. Instead ,for
some applications simplicity and speed are the requirements.

The UDP header shown below illustrates the simplicity of UDP.
Essentially, one a source and a destination port are included, together with
the massage length and a checksum. No sequence numbers or code bits are
required.
UDP has 16-bit port numbers, so there are 65 535 possible UDP ports.
Once the TCP or UDP layer generates a packet, it must be send across the
network. The Transport layer (TCP or UDP) will pass the packet to the Network
layer for end-to-end packet delivery.

Upon receiving information form the Transport layer, the IP layer
generates a header, shown in the picture below, which includes the source and
destination IP addresses. The header is added to the front of the TCP packet to
create a resulting IP packet which will be used to carry the entire contents
(IP header, TCP header and application-level data) across the network.

·
Version
These bits describe which
version of the Internet Protocol is in use. IP Version 4 is the one in
widespread use all over the Internet.
·
IHL
(Internet Header Length)
This field is the Internet
Header Length, the total length of the IP header.
·
Service
Type
This field is associated with
quality of service QOS, indicating to network elements how sensitive the
traffic might be to delays.
·
Total
Length
This Identifies
the total length of the IP packet, including the IP header and its data.
·
Identification
This field is used to support
fragments reassembly.
·
Flags
This 2 are the “Don’t
Fragment” bit, and the “More Fragments” bit:
Flag Bit1 (the don’t fragment
bit):0=may fragment, 1=don’t fragment
Flag Bit2 (the more Fragment
bit):0=last fragment, 1=more fragments.
·
Fragment
Offset
This field is used to
indicate where this fragment fits into the overall packet.
·
Time
to Live (TTL)
This field is used to
indicate the maximum number of router-to-router hops the packet should take as
it crosses the network.
·
Protocol
This field describes the
protocol (TCP/UDP) that is being carried by IP packet.
·
Header
Checksum
This information is used to
make sure the header dies not get corrupted. It is recalculated at each router
hop.
·
Source
IP Address
This field indicates the
network and host where the packet is from.
·
Destination
IP Address
This field indicates the network
and host where the packet is going to.
·
Options
These variables length fields
indicate extended information for the IP Layer. In particular, it is used in
source routing.
·
Padding
This catch-all field is used
to round out the length of the IP header so that it lines up on a 32-bit
boundary.