From 424814615491c604e6a0945f33e5a7b779dc2be5 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Tue, 26 Jul 2022 13:29:16 -0700 Subject: [PATCH] net: document UDPConn.ReadFromUDPAddrPort's AddrPort result more Clarify the form of its IPv4 addresses when listening on an unspecified address. (found while testing/reviewing CL 399454) Change-Id: I62b367f5a4e6d340eb72dd7ec342080f1821e63e Reviewed-on: https://go-review.googlesource.com/c/go/+/419614 Reviewed-by: Ian Lance Taylor Reviewed-by: Cherry Mui TryBot-Result: Gopher Robot Auto-Submit: Ian Lance Taylor Run-TryBot: Ian Lance Taylor --- src/net/udpsock.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/net/udpsock.go b/src/net/udpsock.go index 6d29a39edf..e30624dea5 100644 --- a/src/net/udpsock.go +++ b/src/net/udpsock.go @@ -164,6 +164,10 @@ func (c *UDPConn) ReadFrom(b []byte) (int, Addr, error) { } // ReadFromUDPAddrPort acts like ReadFrom but returns a netip.AddrPort. +// +// If c is bound to an unspecified address, the returned +// netip.AddrPort's address might be an IPv4-mapped IPv6 address. +// Use netip.Addr.Unmap to get the address without the IPv6 prefix. func (c *UDPConn) ReadFromUDPAddrPort(b []byte) (n int, addr netip.AddrPort, err error) { if !c.ok() { return 0, netip.AddrPort{}, syscall.EINVAL -- 2.48.1