awl/query/general.go
Sam Therapy 92812c337f
All checks were successful
continuous-integration/drone/push Build is passing
continuous-integration/drone/pr Build is passing
Another day's work
Signed-off-by: Sam Therapy <sam@samtherapy.net>
2022-07-21 19:06:46 -05:00

61 lines
1 KiB
Go

// SPDX-License-Identifier: BSD-3-Clause
package query
import (
"fmt"
"git.froth.zone/sam/awl/cli"
"git.froth.zone/sam/awl/internal/helpers"
"github.com/miekg/dns"
)
type StandardResolver struct {
server string
opts cli.Options
}
func (r *StandardResolver) LookUp(msg *dns.Msg) (helpers.Response, error) {
var (
resp helpers.Response
err error
)
dnsClient := new(dns.Client)
if r.opts.TCP || r.opts.TLS {
dnsClient.Net = "tcp"
} else {
dnsClient.Net = "udp"
}
switch {
case r.opts.IPv4:
dnsClient.Net += "4"
case r.opts.IPv6:
dnsClient.Net += "6"
}
if r.opts.TLS {
dnsClient.Net += "-tls"
}
resp.DNS, resp.RTT, err = dnsClient.Exchange(msg, r.server)
if err != nil {
return helpers.Response{}, err
}
if resp.DNS.MsgHdr.Truncated && !r.opts.Truncate {
fmt.Printf(";; Truncated, retrying with TCP\n\n")
dnsClient.Net = "tcp"
switch {
case r.opts.IPv4:
dnsClient.Net += "4"
case r.opts.IPv4:
dnsClient.Net += "6"
}
resp.DNS, resp.RTT, err = dnsClient.Exchange(msg, r.server)
}
return resp, err
}