]> Cypherpunks repositories - gostls13.git/commit
net: store IPv4 returned from cgo resolver as 4-byte slice net.IP
authorZeke Lu <lvzecai@gmail.com>
Thu, 27 Oct 2022 01:43:16 +0000 (01:43 +0000)
committerGopher Robot <gobot@golang.org>
Wed, 2 Nov 2022 18:42:50 +0000 (18:42 +0000)
commitc53390b078b4d3b18e3aca8970d4b31d4d82cce1
treec4bdb46e46cf23c82defffd383ca83032c366446
parent07a70bcabb3c81a2f97e894a6910d95b19d6b074
net: store IPv4 returned from cgo resolver as 4-byte slice net.IP

net.IP states that a 16-byte slice can still be an IPv4 address.
But after netip.Addr is introduced, it requires extra care to keep
it as an IPv4 address when converting it to a netip.Addr using
netip.AddrFromSlice.

To address this issue, let's change the cgo resolver to return
4-byte net.IP for IPv4. The change will save us 12 bytes too.

Please note that the go resolver already return IPv4 as 4-byte
slice.

The test TestResolverLookupIP has been modified to cover this
behavior. So no new test is added.

Fixes #53554.

Change-Id: I0dc2a59ad785c0c67a7bc22433105529f055997f
GitHub-Last-Rev: bd7bb2f17bd8e07ea5b39e4a24512ed35d316bb8
GitHub-Pull-Request: golang/go#53638
Reviewed-on: https://go-review.googlesource.com/c/go/+/415580
Auto-Submit: Damien Neil <dneil@google.com>
TryBot-Result: Gopher Robot <gobot@golang.org>
Reviewed-by: Bryan Mills <bcmills@google.com>
Reviewed-by: Damien Neil <dneil@google.com>
Run-TryBot: Ian Lance Taylor <iant@golang.org>
src/net/cgo_unix.go
src/net/ip.go
src/net/lookup_test.go
src/net/lookup_windows.go