Skip to content

Commit fc7905d

Browse files
adding method to retrieve recv hoplimit, and adding tests
1 parent 0241610 commit fc7905d

File tree

2 files changed

+45
-0
lines changed

2 files changed

+45
-0
lines changed

src/socket.rs

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2019,6 +2019,33 @@ impl Socket {
20192019
}
20202020
}
20212021

2022+
/// Get the value of the `IPV6_RECVHOPLIMIT` option for this socket.
2023+
///
2024+
/// For more information about this option, see [`set_recv_hoplimit_v6`].
2025+
///
2026+
/// [`set_recv_hoplimit_v6`]: Socket::set_recv_hoplimit_v6
2027+
#[cfg(all(
2028+
feature = "all",
2029+
not(any(
2030+
target_os = "dragonfly",
2031+
target_os = "fuchsia",
2032+
target_os = "illumos",
2033+
target_os = "netbsd",
2034+
target_os = "openbsd",
2035+
target_os = "redox",
2036+
target_os = "solaris",
2037+
target_os = "haiku",
2038+
target_os = "hurd",
2039+
target_os = "espidf",
2040+
target_os = "vita",
2041+
))
2042+
))]
2043+
pub fn recv_hoplimit_v6(&self) -> io::Result<bool> {
2044+
unsafe {
2045+
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IPV6, sys::IPV6_RECVHOPLIMIT)
2046+
.map(|recv_tclass| recv_tclass > 0)
2047+
}
2048+
}
20222049
/// Set the value of the `IPV6_RECVHOPLIMIT` option for this socket.
20232050
///
20242051
/// The received hop limit is returned as ancillary data by recvmsg()

tests/socket.rs

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1475,6 +1475,24 @@ test!(IPv6 tclass_v6, set_tclass_v6(96));
14751475
)))]
14761476
test!(IPv6 recv_tclass_v6, set_recv_tclass_v6(true));
14771477

1478+
#[cfg(all(
1479+
feature = "all",
1480+
not(any(
1481+
target_os = "dragonfly",
1482+
target_os = "fuchsia",
1483+
target_os = "hurd",
1484+
target_os = "illumos",
1485+
target_os = "netbsd",
1486+
target_os = "openbsd",
1487+
target_os = "redox",
1488+
target_os = "solaris",
1489+
target_os = "windows",
1490+
target_os = "vita",
1491+
target_os = "haiku",
1492+
))
1493+
))]
1494+
test!(IPv6 recv_hoplimit_v6, set_recv_hoplimit_v6(true));
1495+
14781496
#[cfg(all(
14791497
feature = "all",
14801498
any(target_os = "android", target_os = "fuchsia", target_os = "linux")

0 commit comments

Comments
 (0)