From f839c235c87d17d9909b8bb19a97d4310a8021f5 Mon Sep 17 00:00:00 2001 From: database64128 Date: Sun, 10 Apr 2022 22:37:38 +0800 Subject: [PATCH] net: fix WriteMsgUDPAddrPort addr handling WriteMsgUDPAddrPort should accept IPv4 target addresses on IPv6 UDP sockets. An IPv4 target address will be converted to an IPv4-mapped IPv6 address. Fixes #52264. --- src/net/ipsock_posix.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/net/ipsock_posix.go b/src/net/ipsock_posix.go index 2c724478481e78..b9662f593999ff 100644 --- a/src/net/ipsock_posix.go +++ b/src/net/ipsock_posix.go @@ -215,8 +215,11 @@ func addrPortToSockaddrInet4(ap netip.AddrPort) (syscall.SockaddrInet4, error) { func addrPortToSockaddrInet6(ap netip.AddrPort) (syscall.SockaddrInet6, error) { // ipToSockaddrInet6 has special handling here for zero length slices. // We do not, because netip has no concept of a generic zero IP address. + // + // addr is allowed to be an IPv4 address, because As16 will convert it + // to an IPv4-mapped IPv6 address. addr := ap.Addr() - if !addr.Is6() { + if !addr.Is6() && !addr.Is4() { return syscall.SockaddrInet6{}, &AddrError{Err: "non-IPv6 address", Addr: addr.String()} } sa := syscall.SockaddrInet6{