Skip to content

Commit

Permalink
upstream: imp names, docs
Browse files Browse the repository at this point in the history
  • Loading branch information
EugeneOne1 committed Nov 24, 2023
1 parent 51fa582 commit 10657f4
Showing 1 changed file with 5 additions and 4 deletions.
9 changes: 5 additions & 4 deletions upstream/hostsresolver.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func NewDefaultHostsResolver(rootFSys fs.FS) (hr *HostsResolver, err error) {
return nil, fmt.Errorf("getting default hosts paths: %w", err)
}

// The error is always nil here since no readers passed.
strg, _ := hostsfile.NewDefaultStorage()
for _, filename := range paths {
err = parseHostsFile(rootFSys, strg, filename)
Expand Down Expand Up @@ -74,20 +75,20 @@ func (hr *HostsResolver) LookupNetIP(
network string,
host string,
) (addrs []netip.Addr, err error) {
var checkIP func(netip.Addr) (ok bool)
var ipMatches func(netip.Addr) (ok bool)
switch network {
case "ip4":
checkIP = netip.Addr.Is4
ipMatches = netip.Addr.Is4
case "ip6":
checkIP = netip.Addr.Is6
ipMatches = netip.Addr.Is6
case "ip":
return slices.Clone(hr.strg.ByName(host)), nil
default:
return nil, fmt.Errorf("unsupported network %q", network)
}

for _, n := range hr.strg.ByName(host) {
if checkIP(n) {
if ipMatches(n) {
addrs = append(addrs, n)
}
}
Expand Down

0 comments on commit 10657f4

Please sign in to comment.