Skip to content

Commit

Permalink
proxy: fix lookup slicing
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Mar 24, 2023
1 parent f9672a9 commit db08d96
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions proxy/lookup.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"net"

"github.com/AdguardTeam/dnsproxy/proxyutil"
"github.com/AdguardTeam/golibs/errors"

"github.com/miekg/dns"
)
Expand Down Expand Up @@ -31,13 +32,17 @@ func (p *Proxy) lookupIPAddr(host string, qtype uint16, ch chan *lookupResult) {
ch <- &lookupResult{d.Res, err}
}

const ErrEmptyHost = errors.Error("host is empty")

// LookupIPAddr resolves the specified host IP addresses
// It sends two DNS queries (A and AAAA) in parallel and returns both results
func (p *Proxy) LookupIPAddr(host string) ([]net.IPAddr, error) {
if host[:1] != "." {
host += "."
if host == "" {
return nil, ErrEmptyHost
}

host = dns.Fqdn(host)

ch := make(chan *lookupResult)
go p.lookupIPAddr(host, dns.TypeA, ch)
go p.lookupIPAddr(host, dns.TypeAAAA, ch)
Expand Down

0 comments on commit db08d96

Please sign in to comment.