resolver/dns: support ipv6 addrs
Signed-off-by: Vasiliy Tolstov <v.tolstov@unistack.org>
This commit is contained in:
parent
9c695ac343
commit
fb233374a0
@ -42,23 +42,29 @@ func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
|
||||
return records, nil
|
||||
}
|
||||
|
||||
for _, q := range []uint16{dns.TypeA, dns.TypeAAAA} {
|
||||
m := new(dns.Msg)
|
||||
m.SetQuestion(dns.Fqdn(host), dns.TypeA)
|
||||
m.SetQuestion(dns.Fqdn(host), q)
|
||||
rec, err := dns.ExchangeContext(context.Background(), m, r.Address)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
var addr string
|
||||
for _, answer := range rec.Answer {
|
||||
h := answer.Header()
|
||||
// check record type matches
|
||||
if h.Rrtype != dns.TypeA {
|
||||
switch h.Rrtype {
|
||||
case dns.TypeA:
|
||||
arec, _ := answer.(*dns.A)
|
||||
addr = arec.A.String()
|
||||
case dns.TypeAAAA:
|
||||
arec, _ := answer.(*dns.AAAA)
|
||||
addr = arec.AAAA.String()
|
||||
default:
|
||||
continue
|
||||
}
|
||||
|
||||
arec, _ := answer.(*dns.A)
|
||||
addr := arec.A.String()
|
||||
|
||||
// join resolved record with port
|
||||
address := net.JoinHostPort(addr, port)
|
||||
// append to record set
|
||||
@ -66,6 +72,7 @@ func (r *Resolver) Resolve(name string) ([]*resolver.Record, error) {
|
||||
Address: address,
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
// no records returned so just best effort it
|
||||
if len(records) == 0 {
|
||||
|
Loading…
Reference in New Issue
Block a user