Пример #1
0
/*
 * sendRequest() - send a DNS query
 */
func sendRequest(ctx *Context, m *dns.Msg, transport string, timeout time.Duration) (response *dns.Msg, rtt time.Duration, err error) {

	c := new(dns.Client)
	c.Timeout = timeout
	c.Net = transport // "udp" or "tcp"
	response, rtt, err = c.Exchange(m, addressString(ctx.server, ctx.port))
	return

}
Пример #2
0
func digester(server string, done <-chan struct{}, names <-chan string, output chan<- DNSResponse) {
	for targetName := range names {
		message := new(dns.Msg)
		client := new(dns.Client)
		client.Timeout = 10 * 1e9
		message.SetQuestion(targetName, dns.TypeA)
		response, _, err := client.Exchange(message, server+":53")
		// retry errors.
		if err != nil {
			response, _, err = client.Exchange(message, server+":53")
		}
		resp := makeDNSResponse(targetName, response, err)
		select {
		case output <- *resp:
		case <-done:
			return
		}
	}
}