DNS and mDNS name (name) compression rules

Source: Internet
Author: User

DNS and mDNS name (name) compression rules
1. Rationality of name compression:

When transmitting data over the network, if the data size is too large, it will take a long time for the Network to send, so that the network efficiency is relatively low. To improve network efficiency, you can reduce the size of data sent. When an mDNS packet is generated, the mDNS execution program should use name compression for the name of the resource records to be compressed. When one data contains more than one problem, the continuous problem in a data packet is often a similar name. You can use name compression to reduce the number of bytes of the entire data packet. Transmission of compressed data packets can make the network more efficient.

1.1 name compression method:

The essence of compression is to use a two-byte pointer to point to an existing name. The Compressed Name contains this pointer (this pointer is not the memory address in the C language, but an offset ).

1.1.1 domain name storage without name compression is as follows:

Www.xupt.edu.cn

Www.baidu.com

The number in the green box indicates the count, occupying one byte (its value indicates the number of subsequent identifiers), followed by the tag identifier length within 63 bytes, it ends with the character '\ 0.

1.1.2 when compression is used

Replace the previous name with a pointer pointing to the previous one. The two bits starting with a byte are both 1. In this way, a pointer of these two bytes can be distinguished from one label. Because the label is limited to 63 bytes or less, the label must start with 00 bits. (Combinations of 10 and 01 are reserved for future use ). The OFFSET segment specifies the OFFSET from the beginning of the message (the first byte of the ID segment in the domain header. Zero Offset refers to the first byte of the ID segment.

The compression method is very simple. When the identifier in a domain name is compressed, the maximum two bytes in its "count" will be set to 11. This indicates that it is a 16-bit pointer instead of an 8-bit count byte. The remaining 14 bits in the pointer indicate the location offset of the identifier in the d n s message (relative to the DNS packet header ). Note that a pointer may point to a complete domain name, or only to the end of the domain name, and the first half of a domain name can not be compressed, only the second half of the application pointer compression. Nested compression also exists, that is, the domain name pointed to by the pointer may also be compressed (including a pointer ).

OFFSET refers to the OFFSET of a message starting from (the first byte of the ID segment in the domain header. Zero Offset refers to the first byte of the ID segment.

1.2 example:

For example, a data packet has three names:

1) youdian.jsj.com (if the offset of "y" in the data packet is 40)

The total length is 16 bytes.

2) xian.youdian.jsj.com

Total Length: 21 bytes

3) youdian.jsj.com

The second name is compressed:

The length is shortened from 21 bytes to 7 bytes.

After the third name is compressed:

The length of the original 16 bytes is shortened to the current two bytes.

Note the following two points:

1. a domain name can only contain one pointer. Either only two bytes contain only one pointer, or only one pointer is followed at the end.

2. domain names containing pointers do not need to end with the character '\ 0.

2 references

Massage compression described in section 4.1.4 of RFC 1035

Http://freesoft.org/CIE/RFC/1035/index.htm

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.