TCP/IP study notes 5-tcp header message detailed

background

TCP/IPProtocols are the foundation of the current Internet era. All network products, or development languages, and development frameworks are based on tcp/ipprotocols. Therefore, learning well tcp/ipwill 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/ipagreement, it will have a positive effect on your future development or troubleshooting problems at work.

tcp header format

tcpThe header information will appear in each tcpmessage and is used to specify the source port, destination port, management tcpconnection, retransmission, sliding window, etc. of the communication. Each row 32position, 0-31expressed.

tcpThe header format is as follows:
tcp header format

Source port and destination port
  • tcpHow to uniquely identify a connection?
    Of course, is tcpconnected to 源IPfour-tuple: 源端口, 目标IP, ,目标端口

  • tcpWhy is there no IPinformation in the header of the message?
    Because IPit has been processed at the network layer, you tcponly 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 4bytes and 32bits, indicating the range is 0~2^32-1. If it reaches the maximum value, it loops 0.

  • The role of serial numbers in communication
  1. SYNExchange each other's initialization sequence numbers in the message
  2. Ensure that the data packets are assembled in the correct order
  • ISN: Initial Sequence Number Initial Sequence Number
    . During 3the handshake, the two parties will SYNexchange each other's ISNvalues through messages

    ISN is not a fixed value, but every time it is 4msadded 1, the overflow returns 0. This algorithm makes guessing ISNvery difficult. So why do you do this?

    You know, 源IPand 源端口are easy to forge. If an ISNattacker predicts it, RSTafter forging a request directly , it can be forcibly disconnected, which is very dangerous. The dynamic growth ISNgreatly increases the ISNdifficulty of guessing .

Confirmation Number

It is used to inform the other party of the next expected sequence number, indicating ACKthat all packets smaller than that have been received.

Head length

Identifies tcphow many 4bytes the header has . Because the length of the steal header is only 4bits, 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 URGbit: ACK, PSH, RST, SYN, ,FIN

  • URG:Indicates whether the emergency pointer is valid
  • ACK: Confirm receipt of the request
  • PSH: push, Inform the other party that these data packets should be delivered to the upper application immediately after being received. Can't cache
  • RST: reset, Reset the reset flag, force disconnection
  • SYN:Send/Sync flag, used to establish connection
  • FIN: That finishmeans the sender is ready to disconnect
Window size

Window size accounted for 16bit, in fact, this is not enough. Therefore, tcpthe window zoom option is introduced as a scale factor for window zoom. The range of this factor is 0~14that the scale factor can expand the window to the original 2^npower.

Checksum

It occupies 2one 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 tcpdirectly 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: tcpTimestamp
  • MSS: Refers to the tcpmaximum message segment allowed to be received from the other party
  • SACK:Select confirmation option/selective retransmission
  • WindowScale: Window zoom options

to sum up

This is tcp/ipthe fifth part of the series, which mainly introduces the tcphead 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.

Guess you like

Origin blog.csdn.net/Free_time_/article/details/107434317