From b8d78acef2c2bd1c3a7b5beec280d8e2bca0dcde Mon Sep 17 00:00:00 2001 From: Andrey Buchinskiy Date: Thu, 28 Nov 2024 14:15:22 -0800 Subject: [PATCH] adding support to enable IPV6_RECVHOPLIMIT socket option --- src/socket.rs | 29 +++++++++++++++++++++++++++++ src/sys/unix.rs | 14 ++++++++++++++ 2 files changed, 43 insertions(+) diff --git a/src/socket.rs b/src/socket.rs index 8d517b47..27983109 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -1998,6 +1998,35 @@ impl Socket { ) } } + + /// Set the value of the `IPV6_RECVHOPLIMIT` option for this socket. + /// + /// The received hop limit is returned as ancillary data by recvmsg() + /// only if the application has enabled the IPV6_RECVHOPLIMIT socket + /// option: + #[cfg(not(any( + target_os = "dragonfly", + target_os = "fuchsia", + target_os = "illumos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", + target_os = "solaris", + target_os = "haiku", + target_os = "hurd", + target_os = "espidf", + target_os = "vita", + )))] + pub fn set_recv_hoplimit_v6(&self, recv_hoplimit: bool) -> io::Result<()> { + unsafe { + setsockopt( + self.as_raw(), + sys::IPPROTO_IPV6, + sys::IPV6_RECVHOPLIMIT, + recv_hoplimit as c_int, + ) + } + } } /// Socket options for TCP sockets, get/set using `IPPROTO_TCP`. diff --git a/src/sys/unix.rs b/src/sys/unix.rs index 3a898bc3..1ea97a2f 100644 --- a/src/sys/unix.rs +++ b/src/sys/unix.rs @@ -135,6 +135,20 @@ pub(crate) use libc::ipv6_mreq as Ipv6Mreq; target_os = "espidf", target_os = "vita", )))] +pub(crate) use libc::IPV6_RECVHOPLIMIT; +#[cfg(not(any( + target_os = "dragonfly", + target_os = "fuchsia", + target_os = "hurd", + target_os = "illumos", + target_os = "netbsd", + target_os = "openbsd", + target_os = "redox", + target_os = "solaris", + target_os = "haiku", + target_os = "espidf", + target_os = "vita", +)))] pub(crate) use libc::IPV6_RECVTCLASS; #[cfg(all(feature = "all", not(any(target_os = "redox", target_os = "espidf"))))] pub(crate) use libc::IP_HDRINCL;