Data Packet formats for Ethernet, TCP, UDP, and other protocols

Source: Internet
Author: User

TCP/IP

A protocol is a complex set of protocols. There are many professional books. Here, I will only introduce the layer structure of TCP/IP protocol and its message format that are closely related to programming. We know that TCP/IP uses a layered structure. The hierarchical model and Protocol are as follows:
Application Layer
(Application)
HTTP, telnet, FTP, SMTP, SNMP
Transmission Layer
(Transport)
TCP and UDP
Inter-network layer
(Internet)
IP Address [ARP, RARP, ICMP]
Network Interface Layer
(Network)
Ethernet, X.25, slip, PPP

The Protocol adopts a layered structure. Therefore, data packets are also encapsulated in layers. The following uses the most widely used Ethernet as an example to describe its hierarchical encapsulation of data packets, as shown in:

 

 

Any communication protocol has a unique message format, and the TCP/IP protocol is no exception. For communication protocol programming, we must first understand the packet format. The TCP/IP protocol uses a layered model and each layer has a dedicated header. The following describes the packet formats of each layer of TCP/IP over Ethernet.

 

8-byte leading is used for frame synchronization, and CRC is used for frame verification. These users do not have to worry about the automatic addition of NIC chips. The destination address and source address are the physical address of the network card, that is, the MAC address, which is unique. The frame type or protocol type is the advanced protocol of the data packet. For example, 0x0806 indicates the ARP protocol and 0x0800 indicates the IP protocol.

  The format of ARP/RARP (Address Resolution/Reverse Address Resolution) packets is as follows:

The "Hardware type" field indicates the network interface type of the sender's Local Machine (Value "1" indicates Ethernet ). The "protocol type" field refers to the Advanced Protocol address type provided/requested by the sender ("0x0800" indicates the IP protocol ). The "operation" field specifies the type of this article ("1" is the ARP request, "2" is the ARP response, "3" is the RARP request, and "4" is the RARP response ).

  The IP data Header Format is as follows:

We need to simplify the TCP/IP protocol with single-chip microcomputer without considering data partitioning and priority. Therefore, we do not discuss the service type and flag offset fields here, just fill in "0. The Protocol "version" is 4, the "header length" is measured in 32 bits, and the "total length" is measured in bytes, indicating the length of the entire IP datagram. "Identifier" is the ID of the data packet, used to identify different IP data packets. TTL is a concept of quantity to prevent useless data packets from being stored in the network. Generally, the number of routers passing through the destination can be calculated by TTL. The protocol field indicates the advanced protocol type for creating the data packet. For example, 1 indicates ICMP, 6 indicates TCP, and 17 indicates UDP. To simplify the data forwarding time, IP data packets only use header verification. The data correctness is ensured by the high-level protocol.

  ICMP protocolIt is widely used. Only the most common response and response message formats are provided here. the USER command Ping uses this message to test the accessibility of the host machine. The message format is shown in:

Type 0 is the response message, and type 8 is the response message. The entire data packet is involved in the test. Note that ICMP is encapsulated in IP data packets for transmission.

  The UDP Message format is as follows:

  The TCP Message format is as follows:

TCP is a reliable connection-oriented data transmission protocol. Therefore, TCP is complex and only a brief introduction is provided here. "Serial Number" refers to the position of the data in the sending data stream. The "Confirmation Number" indicates the sequence number of the byte that the Local Machine wants to receive next. TCP is different from IP address verification. UDP verification uses the pseudo header label and the entire packet is verified together. The working principle of TCP protocol will be introduced separately.

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.