Skip to content

Commit 5b84e0a

Browse files
committed
net: fix LookupNetIP to return IPv4 addresses instead of IPv4 in IPv6
The method is currently just a wrapper around the old way. But the old way represents IPv4 in 16 bytes slice, so when this wrapper parses the slice it will always create IPv6 address. For IPv4 addreses it's IPv4 in IPv6. The fix just converts the old IPv4 address representation to 4 bytes slice before parsing, so it's parsed as IPv4 and not IPv4 in IPv6. Fixes #53554
1 parent 66685fb commit 5b84e0a

File tree

1 file changed

+3
-0
lines changed

1 file changed

+3
-0
lines changed

src/net/lookup.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -250,6 +250,9 @@ func (r *Resolver) LookupNetIP(ctx context.Context, network, host string) ([]net
250250
}
251251
ret := make([]netip.Addr, 0, len(ips))
252252
for _, ip := range ips {
253+
if ip4 := ip.To4(); ip4 != nil {
254+
ip = ip4
255+
}
253256
if a, ok := netip.AddrFromSlice(ip); ok {
254257
ret = append(ret, a)
255258
}

0 commit comments

Comments
 (0)