func askServerForName(name string, queryType uint16, client *dns.Client, servAddr string, edns bool) (*dns.Msg, error) {
	msg := &dns.Msg{}

	msg.SetQuestion(dns.Fqdn(name), queryType)
	if edns {
		msg.SetEdns0(dns.DefaultMsgSize, false)
	}

	response, _, err := client.Exchange(msg, servAddr)
	if err != nil {
		return nil, err
	}

	if response.Truncated {
		if client.Net == "tcp" {
			return nil, errors.New("got truncated message on TCP (64kiB limit exceeded?)")
		}

		client.Net = "tcp"
		return askServerForName(name, queryType, client, servAddr, false)
	}

	return response, nil
}
func askServerForName(name string, queryType uint16, client *dns.Client, servAddr string, edns bool) (*dns.Msg, error) {
	msg := &dns.Msg{}

	msg.SetQuestion(dns.Fqdn(name), queryType)
	if edns {
		msg.SetEdns0(dns.DefaultMsgSize, false)
	}

	response, _, err := client.Exchange(msg, servAddr)
	if err != nil {
		return nil, err
	}

	if response.Truncated {
		if client.Net == "tcp" {
			return nil, errors.New("got truncated message on TCP (64kiB limit exceeded?)")
		}

		client.Net = "tcp"
		return askServerForName(name, queryType, client, servAddr, false)
	}

	return response, nil
}
func askServerForName ( name string , queryType uint16 , client * dns . Client , servAddr string , edns bool ) ( * dns . Msg , error ) { msg := & dns . Msg { } msg . SetQuestion ( dns . Fqdn ( name ) , queryType ) if edns { msg . SetEdns0 ( dns . DefaultMsgSize , false ) } response , _ , err := client . Exchange ( msg , servAddr ) if err != nil { return nil , err } if response . Truncated { if client . Net == " " { return nil , errors . New ( " " ) } client . Net = " " return askServerForName ( name , queryType , client , servAddr , false ) } return response , nil }
// askServerForName makes a request to a specific DNS server for a specific
// name (and qtype).  Retries with TCP in the event of response truncation,
// but otherwise just sends back whatever the server gave, whether that be a
// valid-looking response, or an error.
askServerForName makes a request to a specific DNS server for a specific name ( and qtype ) . Retries with TCP in the event of response truncation but otherwise just sends back whatever the server gave whether that be a valid - looking response or an error .