From 7d327ed35aef08e2f54c12645a3002c94c6aec91 Mon Sep 17 00:00:00 2001 From: "Jason A. Donenfeld" Date: Fri, 10 Mar 2023 16:18:01 +0100 Subject: [PATCH] conn: use right cmsghdr len types on 32-bit in sticky test Cmsghdr uses uint32 and uint64 on 32-bit and 64-bit respectively for the Len member, which makes assignments and comparisons slightly more irksome than usual. Signed-off-by: Jason A. Donenfeld --- conn/sticky_linux_test.go | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/conn/sticky_linux_test.go b/conn/sticky_linux_test.go index a42c89e..672b67e 100644 --- a/conn/sticky_linux_test.go +++ b/conn/sticky_linux_test.go @@ -38,7 +38,7 @@ func Test_setSrcControl(t *testing.T) { if hdr.Type != unix.IP_PKTINFO { t.Errorf("unexpected type: %d", hdr.Type) } - if hdr.Len != uint64(unix.CmsgLen(int(unsafe.Sizeof(unix.Inet4Pktinfo{})))) { + if uint(hdr.Len) != uint(unix.CmsgLen(int(unsafe.Sizeof(unix.Inet4Pktinfo{})))) { t.Errorf("unexpected length: %d", hdr.Len) } info := (*unix.Inet4Pktinfo)(unsafe.Pointer(&control[unix.CmsgLen(0)])) @@ -68,7 +68,7 @@ func Test_setSrcControl(t *testing.T) { if hdr.Type != unix.IPV6_PKTINFO { t.Errorf("unexpected type: %d", hdr.Type) } - if hdr.Len != uint64(unix.CmsgLen(int(unsafe.Sizeof(unix.Inet6Pktinfo{})))) { + if uint(hdr.Len) != uint(unix.CmsgLen(int(unsafe.Sizeof(unix.Inet6Pktinfo{})))) { t.Errorf("unexpected length: %d", hdr.Len) } info := (*unix.Inet6Pktinfo)(unsafe.Pointer(&control[unix.CmsgLen(0)])) @@ -101,7 +101,7 @@ func Test_getSrcFromControl(t *testing.T) { hdr := (*unix.Cmsghdr)(unsafe.Pointer(&control[0])) hdr.Level = unix.IPPROTO_IP hdr.Type = unix.IP_PKTINFO - hdr.Len = uint64(unix.CmsgLen(int(unsafe.Sizeof(unix.Inet4Pktinfo{})))) + hdr.SetLen(unix.CmsgLen(int(unsafe.Sizeof(unix.Inet4Pktinfo{})))) info := (*unix.Inet4Pktinfo)(unsafe.Pointer(&control[unix.CmsgLen(0)])) info.Spec_dst = [4]byte{127, 0, 0, 1} info.Ifindex = 5 @@ -121,7 +121,7 @@ func Test_getSrcFromControl(t *testing.T) { hdr := (*unix.Cmsghdr)(unsafe.Pointer(&control[0])) hdr.Level = unix.IPPROTO_IPV6 hdr.Type = unix.IPV6_PKTINFO - hdr.Len = uint64(unix.CmsgLen(int(unsafe.Sizeof(unix.Inet6Pktinfo{})))) + hdr.SetLen(unix.CmsgLen(int(unsafe.Sizeof(unix.Inet6Pktinfo{})))) info := (*unix.Inet6Pktinfo)(unsafe.Pointer(&control[unix.CmsgLen(0)])) info.Addr = [16]byte{0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1} info.Ifindex = 5