From 5023b6b0c328c0fb7286bbfb3325fec1a371b615 Mon Sep 17 00:00:00 2001 From: Josh Bleecher Snyder Date: Thu, 8 Jul 2021 13:58:06 -0700 Subject: [PATCH] make ipv4/ipv6 code parallel and thus more clearly correct weirdly, since it is using unsafe --- net/uring/io_uring_linux.go | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/net/uring/io_uring_linux.go b/net/uring/io_uring_linux.go index 183d334d9..e5f1e3b69 100644 --- a/net/uring/io_uring_linux.go +++ b/net/uring/io_uring_linux.go @@ -5,7 +5,6 @@ package uring import "C" import ( - "encoding/binary" "errors" "fmt" "net" @@ -289,9 +288,9 @@ func (u *UDPConn) WriteTo(p []byte, addr net.Addr) (n int, err error) { copy(rbuf, p) if u.is4 { - // TODO: are the following two lines of code correct? - ipu32 := binary.BigEndian.Uint32(udpAddr.IP) - r.sa.sin_addr.s_addr = C.uint32_t(endian.Hton32(ipu32)) + dst := (*[4]byte)((unsafe.Pointer)(&r.sa.sin_addr.s_addr)) + src := (*[4]byte)((unsafe.Pointer)(&udpAddr.IP[0])) + *dst = *src r.sa.sin_port = C.uint16_t(endian.Hton16(uint16(udpAddr.Port))) r.sa.sin_family = C.AF_INET } else {