Skip to content

Commit f839c23

Browse files
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.
1 parent db7183c commit f839c23

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

src/net/ipsock_posix.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,8 +215,11 @@ func addrPortToSockaddrInet4(ap netip.AddrPort) (syscall.SockaddrInet4, error) {
215215
func addrPortToSockaddrInet6(ap netip.AddrPort) (syscall.SockaddrInet6, error) {
216216
// ipToSockaddrInet6 has special handling here for zero length slices.
217217
// We do not, because netip has no concept of a generic zero IP address.
218+
//
219+
// addr is allowed to be an IPv4 address, because As16 will convert it
220+
// to an IPv4-mapped IPv6 address.
218221
addr := ap.Addr()
219-
if !addr.Is6() {
222+
if !addr.Is6() && !addr.Is4() {
220223
return syscall.SockaddrInet6{}, &AddrError{Err: "non-IPv6 address", Addr: addr.String()}
221224
}
222225
sa := syscall.SockaddrInet6{

0 commit comments

Comments
 (0)