background
TCP/IP
Protocols are the foundation of the current Internet era. All network products, or development languages, and development frameworks are based on tcp/ip
protocols. Therefore, learning well tcp/ip
will be of great help to individuals in the Internet industry in the future.
But this is a basic theoretical course, just like the course of operating system, after learning it may not have much impact on you, and it will not let you immediately have the skills to put into work. But precisely because this is a basic theory course, all Internet technologies are based on it. So if you understand the tcp/ip
agreement, it will have a positive effect on your future development or troubleshooting problems at work.
tcp header format
tcp
The header information will appear in each tcp
message and is used to specify the source port, destination port, management tcp
connection, retransmission, sliding window, etc. of the communication. Each row 32
position, 0-31
expressed.
tcp
The header format is as follows:
Source port and destination port
-
tcp
How to uniquely identify a connection?
Of course, istcp
connected to源IP
four-tuple:源端口
,目标IP
, ,目标端口
-
tcp
Why is there noIP
information in the header of the message?
BecauseIP
it has been processed at the network layer, youtcp
only need to record the ports at both ends.
serial number
The first byte of the segment. The serial number is an integer with a length of 4
bytes and 32
bits, indicating the range is 0~2^32-1
. If it reaches the maximum value, it loops 0
.
- The role of serial numbers in communication
SYN
Exchange each other's initialization sequence numbers in the message- Ensure that the data packets are assembled in the correct order
-
ISN: Initial Sequence Number Initial Sequence Number
. During3
the handshake, the two parties willSYN
exchange each other'sISN
values through messagesISN is not a fixed value, but every time it is
4ms
added1
, the overflow returns0
. This algorithm makes guessingISN
very difficult. So why do you do this?You know,
源IP
and源端口
are easy to forge. If anISN
attacker predicts it,RST
after forging a request directly , it can be forcibly disconnected, which is very dangerous. The dynamic growthISN
greatly increases theISN
difficulty of guessing .
Confirmation Number
It is used to inform the other party of the next expected sequence number, indicating ACK
that all packets smaller than that have been received.
Head length
Identifies tcp
how many 4
bytes the header has . Because the length of the steal header is only 4
bits, the maximum can be expressed 15
, so the maximum length of the tcp header is 60 bytes.
Reserved bit
Temporarily reserved
Mark bit
Common markers URG
bit: ACK
, PSH
, RST
, SYN
, ,FIN
URG
:Indicates whether the emergency pointer is validACK
: Confirm receipt of the requestPSH
:push
, Inform the other party that these data packets should be delivered to the upper application immediately after being received. Can't cacheRST
:reset
, Reset the reset flag, force disconnectionSYN
:Send/Sync flag, used to establish connectionFIN
: Thatfinish
means the sender is ready to disconnect
Window size
Window size accounted for 16
bit, in fact, this is not enough. Therefore, tcp
the window zoom option is introduced as a scale factor for window zoom. The range of this factor is 0~14
that the scale factor can expand the window to the original 2^n
power.
Checksum
It occupies 2
one byte to prevent the data packet from being damaged or tampered with during transmission. If a packet with an error in the checksum is encountered, it is tcp
directly discarded and waiting for retransmission.
Options
The format of the options is as follows:
Kind (kind) 1byte | Length (length) 1byte | Value |
---|
The commonly used options are as follows:
TimeStamp
:tcp
TimestampMSS
: Refers to thetcp
maximum message segment allowed to be received from the other partySACK
:Select confirmation option/selective retransmissionWindowScale
: Window zoom options
to sum up
This is tcp/ip
the fifth part of the series, which mainly introduces the tcp
head components in detail . There will be more in-depth and more usage scene explanations later, this series of articles will be very long.
Let's start the next article.