Ethernet frame, IP message format

Source: Internet
Author: User

These days to complete a comparison of the Ethernet frame of the program (c), the teacher gave the Ethernet frame head and IP packet header structure, and the actual fetch to the packet format is the same.

Data structure of Ethernet frame head:

struct {        char   dest_mac[6];         Char   src_mac[6];          Short   Eth_type;} ethernet_header;

The Eth_type field is used to indicate the upper-layer protocol type, two bytes. Eth_type field common values and corresponding protocols

0x0800 Internet Protocol (IP)
0x0806 Address Resolution Protocol (ARP)
0X8035 Reverse Address Resolution Protocol

More visible: http://blog.sina.com.cn/s/blog_a206e924010111tm.html

Data structure of the header of the IP message format:

typedefstruct{unsignedCharHeader_len:4; unsignedCharVersion4; unsignedCharTos8; unsigned ShortTotal_len; unsigned Shortident; unsigned Shortflags; unsignedCharTtl:8; unsignedCharProto8; unsigned Shortchecksum; unsignedCharsrc_ip[4]; unsignedChardest_ip[4];} Ip_header;

Format of IP messages

There are only 4 bits in the IP packet, and the members in the struct are in the form of a bit field definition.

struct name{
Type name:n;
};

The member variable name occupies a space of n bits, n must be a positive integer, its value must be less than the number of digits occupied by the type, and if type is int, then n must be an integer between 1~31. For a member of a bit field type, if the actual value exceeds the range of n potential expression when the value is assigned, the excess will be truncated.

The header Length field in the struct is preceded by the version field, as opposed to in the picture, because of the reason the network byte order is represented.

Proto represents the protocol for the Transport layer, a common correspondence description:

1 Internet Control Message (ICMP)
2 Internet Group Management (IGMP)
6 Transport Control (TCP)
17 User Data message (UDP)

See more: http://blog.csdn.net/jiary5201314/article/details/41213561

The header Length field in the IP packet represents the number of 32 bits in the head, that is, the length of the IP packet header is Header_len * 4 bytes.

Ethernet frame, IP message format

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.