Detailed description of TCP/IP packet structure

Source: Internet
Author: User


In general, we only need to call encapsulated functions or components for network programming. However, in some special cases, it is necessary to thoroughly understand the structure of network data packets and protocol analysis. Such as network monitoring and troubleshooting ...... The IP package is insecure, but it is the foundation of the Internet and widely used in various aspects. There are more than 10 protocol families (as I know) derived from the IP protocol, and more IP-based protocols will appear in the future... Let's start with the actual situation! When talking about the Internet speed, we use bandwidth to describe it professionally. In fact, neither the network speed nor the bandwidth is accurate. For example, 1 MB, 512 K ...... Some students in the school may have questions about why the download speed cannot exceed kb even though my business is 1 MB? Why is the K cap over 50 K ?... Www.2cto.com 1 m Refers to 1 Mbps = 1 Million Bits Per Second, that is, 1 m Bits Per Second, that is, 1048576 binary Bits are transmitted in one Second. We know that a byte is eight binary digits. Okay, you have another problem. Even so, 1 M = 1048756 then 8 = 131072 then 1024 = 128 K. There should also be 120 K. Why is the download speed still very low to K, and K is thankful. After reading this article, your account is correct ...... IP packet structure:

, A scale represents 1 binary bit (BIT ). 1-1. the four-digit version indicates the version number. Currently, the most widely used version is 4 = B1000, which is also known as IPv4. I believe IPv6 will be widely used in the future. It can assign an IP address to each button in the world. 1-2. The header length is 4 bits and the length of the packet header. It indicates how many 32-bit long integers are contained in the packet header, that is, how many 4 bytes of data are contained. If there is no option, the value is 5 (in red ). 1-3. the service type includes eight binary bits. Each BITs has the following meanings: Process Field: three bits, which sets the importance of data packets. The larger the value, the more important the data is. The value range is: 0 (normal )~ 7 (Network Control) www.2cto.com latency field: 1 bit, value: 0 (normal), 1 (low latency) traffic field: 1 bit, value: 0 (normal) 1 (high traffic period) Reliability field: 1 bit, value: 0 (normal), 1 (high reliability period) Cost field: 1 bit, value: 0 (normal), 1 (period-specific minimum cost) reserved field: 1 bit, not used
1-4. The total length of the package is 16 bits. The total length of the current data packet, in bytes. Of course, the maximum value is only 65535, and 64 KB. 2-1. The 16-bit re-identification is sent to the identity assigned by the host for the receiver to perform sharding. 2-2. mark 3 bits. Their respective meanings are as follows: retain the field bits (2): 1 bits, not use the field bits (1): 1 bits, value: 0 (allow the datagram to segment), 1 (the datagram cannot be segmented) More segments (0): 1 bit, value: 0 (no package after the packet, this package is the final package), 1 (more packets are next to the package) www.2cto.com 2-3. the 13-bit segment offset, which is combined with more segments to help the receiver combine segmented packets in bytes. 3-1. The survival Time is 8 bits. The TTL (Time To Live) that is often seen by the ping command is this. Each Time a vro passes through, the value is reduced by one To zero and discarded. 3-2. The 8-bit protocol code indicates the upper-layer protocol that uses the package, such as TCP = 6, ICMP = 1, UDP = 17, etc. 3-3. header check and 16-bit check are the IPv4 packet header checksum. 4-1. Source start address, 32-bit 4-byte. We often see that IP addresses are separated by DOTS. 5-1. Destination Address, 32-bit, same as above. 6-1. Optional options, mainly for some special circumstances, often Security Routing will be used as an attack to filter out, universal (TP_LINK) TL-ER5110 routing can do so. 7-1. user data. TCP packet structure:

1-1. The source start port is 16 bits, and the range is of course 0. 1-2. Destination Port, same as above. 2-1. The data serial number is 32 bits. TCP creates a number for each byte sent. The serial number of the first byte of the current data packet is stored here. Www.2cto.com 3-1. Confirm the serial number of 32 bits. For the sake of security, TCP tells the receiver that he wants to receive the first byte serial number of the next packet. 4-1. The offset is 4 bits, similar to the IP address, indicating the number of 32 bits from the header. 4-2. Retain 6 bits. if not used, set it to zero. 4-3. URG-When URG = 1, the emergency pointer field is valid. It tells the system that there is urgent data in this packet segment and should be transmitted as soon as possible (equivalent to high-priority data ).
4-3. confirm that the bit ACK is valid only when ACK = 1. When ACK = 0, the confirmation number is invalid. 4-4. reset bit RST (Reset)-When RST = 1, it indicates that a serious error occurred in the TCP connection (for example, due to host crash or other reasons), the connection must be released, then re-establish the transportation connection. 4-5. synchronous bit SYN-if the synchronous bit SYN is set to 1, this indicates a connection request or connection to receive packets. 4-6. Terminate bit FIN (FINal)-used to release a connection. When FIN = 1, it indicates that the data of the sending end of the message segment has been sent and the transport connection needs to be released. 4-7. The window field is 16 bits. The window field is used to control the data volume sent by the recipient, in bytes. The end of the TCP connection determines the size of its receiving window based on the size of the cache space, and then notifies the other end to determine the upper limit of the sending window of the other end. 5-1. The packet checksum is 16 bits, including the header and data. During the calculation test, a 12-byte pseudo header must be added before the TCP packet segment. 5-2. The emergency pointer is 16 bits, indicating the serial number of the last byte of the emergency data in this section. 6-1. Optional 24-bit, similar to IP, is optional. 6-2. Fill in 8 bits so that the options are 32 bits. 7-1. User data ...... As you can see from www.2cto.com, each IP package requires at least 20 bytes of header length, which is irrelevant to the downloaded content. In addition, most of the current transmission, including http protocol (IE direct download ), all are based on the TCP protocol, so the IP package also needs to deduct 20 bytes of TCP packet header from the user data. Here it is 40 bytes, plus the connection of other programs, status confirmation, and so on, therefore, it is smaller than the theoretical value. In addition, the network environment (including stability factors and transfer nodes) is also an important factor affecting the download speed ...... Address: http://blog.csdn.net/prsniper/article/details/6762145
 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.