This is a creation in Article, where the information may have evolved or changed.
Some instructions on Go DNS parsing refer to another article http://blog.csdn.net/mumumuwudi/article/details/48200505
Go DNS resolves source code in Go/src/net/dnsclient_unix.go, Lookuphost () obtains IP and domain name by sending a request to the local DNS server
The corresponding relationship is then returned, and the function call relationship is as follows:
Lookuphost ()
->golookuphostorder ()
-->golookupiporder ()
--->tryonename ()
---->exchange ()
Func Exchange (server, name string, Qtype uint16, timeout time. Duration) (*dnsmsg, error) {d: = dialer{timeout:timeout}out: = Dnsmsg{dnsmsghdr:dnsmsghdr{recursion_desired:true,}, Question: []dnsquestion{{name, Qtype, Dnsclassinet},},}for _, Network: = range []string{"UDP", "TCP"} {c, err: = D.dialdns (Network, server) Create UDPIF Err! = Nil {return nil, Err}defer c.close () If timeout > 0 {c.setdeadline (time. Now (). ADD (timeout))}out.id = UInt16 (rand. Int ()) ^ UInt16 (time. Now (). Unixnano ()) If err: = C.writednsquery (&out); Err! = Nil { //Send DNS request return nil, err}in, err: = C.readdnsresponse () //Parse DNS request get IPIF Err! = Nil {return nil, err}i F in.id! = Out.id {return nil, errors. New ("DNS message ID mismatch")}if in.truncated {//See RFCs 5966continue}return in, Nil}return Nil, errors. New ("No answer from DNS server")}
Where timeout is the DNS time-out is determined by the configuration of the read/etc/reslove.conf in the Dnsconfig_unix.go file
The Dialtimeout function in Net.go will also go to the DNS resolution process, which will eventually call to Lookupipdeadline to enable a new co-
Process to parse DNS, the specific call stack is as follows:
Dialtimeout ()
->resolveaddrlist ()
-->internetaddrlist ()
--->lookupipdeadline ()
---->lookupgroup.dochan () to do DNS resolution in the new process
----->LOOKUPIP ()
------>golookupiporder ()
In short, the Pure Go language DNS parsing process is still relatively perfect ~ ~
Copyright NOTICE: Reprint Please indicate the source, thank Http://blog.csdn.net/mumumuwudi