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 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")] 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];