A detailed explanation of TCP/IP data packet structure

Source: Internet
Author: User
Tags ack reserved

Keywords TCP IP Packet Structure Detailed network protocol

In general, network programming we only need to call some of the encapsulated functions or components can do most of the work, but some special circumstances, it requires in-depth understanding

Network packet structure, and protocol analysis. such as: network monitoring, troubleshooting, etc...

IP packet is not secure, but it is the basis of the Internet, in all aspects have a wide range of applications. There are 10 of different protocols derived from the IP protocol (as far as I know)

More ip-based protocols ...

Let's start with the reality.

In general, we talk about the speed of the Internet, the professional use of bandwidth to describe, in fact, whether the speed or bandwidth is not accurate, hehe. For example: 1 trillion, 512K ...

Some students in the school, may have doubts, obviously my business is 1M, why download speed to 100K will not go up. 512K of why more than 50 k on the ceiling. ...

The 1M mentioned here refers to 1Mbps = 1 million bits per Second, which is 1M bit every second, that is, one second transmits 1,048,576 bits. We know a byte

is 8 bits.

Okay, here's the problem again. Even so, 1m=1048756÷8=131072÷1024=128k. That should also have 128K ah, why download speed is still very little to 120K,

110K, thank goodness. After reading this article, your account is right ...

IP Packet Structure:

As shown in figure, a scale represents 1 bits (bits).

1-1. Version 4, indicating version number, currently the most extensive is 4=b1000, that is often said IPv4; believe IPv6 will be widely used, it can give every button in the world to allocate

An IP address.

1-2. Head length 4 bits, data Baotou Minister degree. It indicates how many 32-bit long integers are included in the header of the packet, that is, how many 4-byte data. No option is 5 (the red portion).

1-3. Service type, including 8 bits, each bit has the following meanings:

Process field: 3 bits, set the importance of the packet, the greater the value of data, the value range is: 0 (normal) ~ 7 (Network control)

Delay field: 1 bit, value: 0 (normal), 1 (Low period delay)

Flow field: 1 bits, Value: 0 (normal), 1 (Special high traffic)

Reliability field: 1 bits, Value: 0 (normal), 1 (High reliability)

Cost field: 1 bits, Value: 0 (normal), 1 (minimum cost of special period)

Reserved field: 1-bit, not used

1-4. The total length of the package is 16 bits, and the current packet is in bytes. Of course, the biggest can only be 65535, and 64KB.

2-1. The reorganization identification 16 bits, sends the host to give the identity, for the receiver to carry on the fragment reorganization.

2-2. Sign 3, their respective meanings are as follows:

Reserved Dan (2): 1-bit, not used

No division (1): 1 bits, Value: 0 (Allow datagram segmentation), 1 (datagram can not be segmented)

More Dan (0): 1 bits, Value: 0 (packet is not after the packet, the package is the last package), 1 (there are more packets behind the packet)

2-3. Segment offset 13 bits, combined with more Dan, helps the receiver to combine segmented packets in bytes.

3-1. Survival time 8 bits, often ping command to see the TTL (Times to Live) is this, each through a router, the value is reduced by one, to zero discard.

3-2. Protocol code 8 BITS, indicating the use of the package upper layer protocol, such as TCP=6,ICMP=1,UDP=17.

3-3. Head inspection and 16-bit, is the IPV4 data Baotou section of the checksum.

4-1. Source start Address, 32 bits 4 bytes, we often see the IP is to each byte with dots (.) Separate, that's all.

5-1. Destination address, 32 digits, ditto.

6-1. Optional option, mainly for some special situations, often safe routes will be filtered as an attack, Puling (Tp_link) of the tl-er5110 route can do so.

7-1. User data.

TCP Packet Structure:

1-1. Source Port 16, the range of course is 0-65535.

1-2. Destination port, ditto.

2-1. Data serial number 32 bits, TCP for each byte sent a number, here store the current packet data the first byte ordinal.

3-1. Confirm Serial Number 32 bits, for security, TCP tells the recipient to expect him to receive the first byte ordinal of the packet next time.

4-1. Offset 4 bits, similar to IP, indicating how many 32 bits the data is from the header.

4-2. Keep 6 bits, not used, should be zero.

4-3. Emergency bit urg-when urg=1, indicates that the emergency pointer field is valid. It tells the system that there are urgent data in this segment and should be delivered as soon as possible (equivalent to high priority data).

4-3. Confirm that the bit ack-is only valid when the ack=1 is in the confirmation Number field. The confirmation number is not valid when ack=0. Reference TCP three times handshake

4-4. Reset bit RST-when rst=1 indicates that a serious error occurred in the TCP connection (for example, due to a host crash or other reason), the connection must be released and then

Establish a transport connection. Reference TCP three times handshake

4-5. Synchronous bit syn-synchronous bit SYN is set to 1, which means that this is a connection request or a connection acceptance message. Reference TCP three times handshake

4-6. Terminate bit fin (FINal)-Used to release a connection. When Fin=1, indicates that the data for the sender of this segment has been sent and the transport connection is released.

4-7. window field 16 Bits, the window field is used to control the amount of data sent by each other, in bytes. One end of a TCP connection determines its own receive window based on the size of the cache space set

Size, and then notifies each other to determine the upper limit of the other's send window.

5-1. Package checksum 16 bits, including the header and the data in the two parts. In the calculation of the test and time, the TCP segment is preceded by a 12-byte pseudo header.

5-2. Emergency pointers 16 digits, the emergency pointer indicates the ordinal number of the last byte of the emergency data in this section.

6-1. Optional options 24 bits, similar to IP, are optional.

6-2. Fill 8 bits so that the options are up to 32 bits.

7-1. User Data ...

As can be seen, each IP packet must be at least 20 bytes of head length, which is independent of the download content, plus the current majority of transmissions, including the HTTP protocol (ie direct download), are based on

TCP protocol, so the IP package will also be deducted from the user data 20 bytes of TCP header, which is already 40 bytes, plus other programs of the connection, status confirmation and so on parcels, because

And it's smaller than the theoretical value.

In addition, the network environment (including the stability factor and transmission node's forwarding rate) is also the important reason which affects the download speed ...

Oh, well, that's all.

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.