Golang Implementing DNS Domain name Resolution (ii)

Source: Internet
Author: User
This is a creation in Article, where the information may have evolved or changed.

The previous section has described how to construct a DNS request packet, and this section goes on to the previous section to talk about The problem part of the DNS query message. The format of each issue in the issues section is as follows:

  

  

The query name is the name to look for, and it is a sequence of one or more identifiers. Each identifier describes the byte length of the subsequent identifier in the first byte of the value, and each query name ends with a last byte of 0 , and an identifier of length 0 is the root identifier. Let's grab a bag and look at the details:

  

we see that the name of the request is www.baidu.com the contents of the package is the part of the red Line identified below, the name to look for is transformed into a 3www5baidu3com This format, So when we construct the DNS Query Request package, we need to change the name format of the query:

VAR (

Buffer bytes. Buffer

segments []string = strings. Split (Domain, ".")

)

For _, SEG: = Range Segments {

Binary. Write (&buffer, Binary. Bigendian, Byte (len (SEG)))

Binary. Write (&buffer, Binary. Bigendian, []byte (SEG)]

}

Binary. Write (&buffer, Binary. Bigendian, Byte (0x00))

return buffer. Bytes ()

Complete code please go to the previous section. The problem section of the query message is briefly described here.

Related Article

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.