Skip to content

Commit

Permalink
adding IPV6_RECVHOPLIMIT socket option
Browse files Browse the repository at this point in the history
  • Loading branch information
andreybuchinskiy committed Nov 30, 2024
1 parent 3a93893 commit 46f40f2
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 3 deletions.
35 changes: 32 additions & 3 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1972,9 +1972,9 @@ impl Socket {

/// Set the value of the `IPV6_RECVTCLASS` option for this socket.
///
/// If enabled, the `IPV6_TCLASS` ancillary message is passed with incoming
/// packets. It contains a byte which specifies the traffic class field of
/// the packet header.
/// 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",
Expand All @@ -1998,6 +1998,35 @@ impl Socket {
)
}
}

/// Set the value of the `IPV6_RECVHOPLIMIT` option for this socket.
///
/// If enabled, the `IPV6_TCLASS` ancillary message is passed with incoming
/// packets. It contains a byte which specifies the traffic class field of
/// the packet header.
#[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`.
Expand Down
14 changes: 14 additions & 0 deletions src/sys/unix.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 46f40f2

Please sign in to comment.