From 44865ad7af26c041d7abaa82ca43f3ce2878e6f3 Mon Sep 17 00:00:00 2001 From: Masakazu Asama Date: Sun, 12 Oct 2025 12:57:00 +0000 Subject: [PATCH 1/3] =?UTF-8?q?Fix=20IPV6=5FPKTINFO/IP=5FPKTINFO=20sockopt?= =?UTF-8?q?s:=20use=20in6=5Fpktinfo/in=5Fpktinfo=20instead=20of=20bool,=20?= =?UTF-8?q?and=20correct=20docs=20to=20=E2=80=9Coutgoing=E2=80=9D?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit This fixes the Ipv6PacketInfo and Ipv4PacketInfo sockopts to use the proper payload types (libc::in6_pktinfo and libc::in_pktinfo) instead of bool. It also updates the docs to state that these options relate to outgoing packets (not “incoming”). --- src/sys/socket/sockopt.rs | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/sys/socket/sockopt.rs b/src/sys/socket/sockopt.rs index 49b305920f..19f0c77b7c 100644 --- a/src/sys/socket/sockopt.rs +++ b/src/sys/socket/sockopt.rs @@ -1052,12 +1052,12 @@ sockopt_impl!( sockopt_impl!( #[cfg_attr(docsrs, doc(cfg(feature = "net")))] /// Pass an `IP_PKTINFO` ancillary message that contains a pktinfo - /// structure that supplies some information about the incoming packet. + /// structure that supplies some information about the outgoing packet. Ipv4PacketInfo, Both, libc::IPPROTO_IP, libc::IP_PKTINFO, - bool + libc::in_pktinfo ); #[cfg(any(linux_android, bsd))] #[cfg(feature = "net")] @@ -1077,12 +1077,12 @@ sockopt_impl!( sockopt_impl!( #[cfg_attr(docsrs, doc(cfg(feature = "net")))] /// Pass an `IPV6_PKTINFO` ancillary message that contains a in6_pktinfo - /// structure that supplies some information about the incoming packet. + /// structure that supplies some information about the outgoing packet. Ipv6PacketInfo, Both, libc::IPPROTO_IPV6, libc::IPV6_PKTINFO, - bool + libc::in6_pktinfo ); #[cfg(bsd)] #[cfg(feature = "net")] From fd74695b074c3f79ca449f20bda75ed1dd970c4e Mon Sep 17 00:00:00 2001 From: Masakazu Asama Date: Sun, 12 Oct 2025 13:11:03 +0000 Subject: [PATCH 2/3] Fix test_recv_ipv4pktinfo --- test/sys/test_socket.rs | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/test/sys/test_socket.rs b/test/sys/test_socket.rs index 514e28d62b..052df3d9b7 100644 --- a/test/sys/test_socket.rs +++ b/test/sys/test_socket.rs @@ -1859,7 +1859,21 @@ pub fn test_recv_ipv4pktinfo() { bind(receive.as_raw_fd(), &lo).expect("bind failed"); let sa: SockaddrIn = getsockname(receive.as_raw_fd()).expect("getsockname failed"); - setsockopt(&receive, Ipv4PacketInfo, &true).expect("setsockopt failed"); + cfg_if! { + if #[cfg(target_os = "netbsd")] { + let pi = libc::in_pktinfo { + ipi_ifindex: 0, + ipi_addr: libc::in_addr { s_addr: 0 }, + }; + } else { + let pi = libc::in_pktinfo { + ipi_ifindex: 0, + ipi_addr: libc::in_addr { s_addr: 0 }, + ipi_spec_dst: libc::in_addr { s_addr: 0 }, + }; + } + } + setsockopt(&receive, Ipv4PacketInfo, &pi).expect("setsockopt failed"); { let slice = [1u8, 2, 3, 4, 5, 6, 7, 8]; From 9c1499a51c382b23fcb2154e4d4f76c8ab4223dc Mon Sep 17 00:00:00 2001 From: Masakazu Asama Date: Sun, 12 Oct 2025 14:38:55 +0000 Subject: [PATCH 3/3] Add changelog/2687.fixed.md --- changelog/2687.fixed.md | 1 + 1 file changed, 1 insertion(+) create mode 100644 changelog/2687.fixed.md diff --git a/changelog/2687.fixed.md b/changelog/2687.fixed.md new file mode 100644 index 0000000000..c0dcb7d899 --- /dev/null +++ b/changelog/2687.fixed.md @@ -0,0 +1 @@ +fixed IPV6_PKTINFO/IP_PKTINFO sockopt type from bool to in6_pktinfo/in_pktinfo