Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 18 additions & 18 deletions src/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1190,8 +1190,8 @@ impl Socket {
///
/// [`SOCK_RAW`]: Type::RAW
/// [raw(7)]: https://man7.org/linux/man-pages/man7/raw.7.html
/// [`IP_TTL`]: Socket::set_ttl
/// [`IP_TOS`]: Socket::set_tos
/// [`IP_TTL`]: Socket::set_ttl_v4
/// [`IP_TOS`]: Socket::set_tos_v4
#[cfg_attr(
any(target_os = "fuchsia", target_os = "illumos", target_os = "solaris"),
allow(rustdoc::broken_intra_doc_links)
Expand All @@ -1214,12 +1214,12 @@ impl Socket {

/// Get the value of the `IP_TRANSPARENT` option on this socket.
///
/// For more information about this option, see [`set_ip_transparent`].
/// For more information about this option, see [`set_ip_transparent_v4`].
///
/// [`set_ip_transparent`]: Socket::set_ip_transparent
/// [`set_ip_transparent_v4`]: Socket::set_ip_transparent_v4
#[cfg(all(feature = "all", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
pub fn ip_transparent(&self) -> io::Result<bool> {
pub fn ip_transparent_v4(&self) -> io::Result<bool> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IP, libc::IP_TRANSPARENT)
.map(|transparent| transparent != 0)
Expand All @@ -1243,7 +1243,7 @@ impl Socket {
/// requires that this option be set on the redirected socket.
#[cfg(all(feature = "all", target_os = "linux"))]
#[cfg_attr(docsrs, doc(cfg(all(feature = "all", target_os = "linux"))))]
pub fn set_ip_transparent(&self, transparent: bool) -> io::Result<()> {
pub fn set_ip_transparent_v4(&self, transparent: bool) -> io::Result<()> {
unsafe {
setsockopt(
self.as_raw(),
Expand Down Expand Up @@ -1556,10 +1556,10 @@ impl Socket {

/// Get the value of the `IP_TTL` option for this socket.
///
/// For more information about this option, see [`set_ttl`].
/// For more information about this option, see [`set_ttl_v4`].
///
/// [`set_ttl`]: Socket::set_ttl
pub fn ttl(&self) -> io::Result<u32> {
/// [`set_ttl_v4`]: Socket::set_ttl_v4
pub fn ttl_v4(&self) -> io::Result<u32> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IP, sys::IP_TTL).map(|ttl| ttl as u32)
}
Expand All @@ -1569,7 +1569,7 @@ impl Socket {
///
/// This value sets the time-to-live field that is used in every packet sent
/// from this socket.
pub fn set_ttl(&self, ttl: u32) -> io::Result<()> {
pub fn set_ttl_v4(&self, ttl: u32) -> io::Result<()> {
unsafe { setsockopt(self.as_raw(), sys::IPPROTO_IP, sys::IP_TTL, ttl as c_int) }
}

Expand All @@ -1587,26 +1587,26 @@ impl Socket {
target_os = "illumos",
target_os = "haiku",
)))]
pub fn set_tos(&self, tos: u32) -> io::Result<()> {
pub fn set_tos_v4(&self, tos: u32) -> io::Result<()> {
unsafe { setsockopt(self.as_raw(), sys::IPPROTO_IP, sys::IP_TOS, tos as c_int) }
}

/// Get the value of the `IP_TOS` option for this socket.
///
/// For more information about this option, see [`set_tos`].
/// For more information about this option, see [`set_tos_v4`].
///
/// NOTE: <https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options>
/// documents that not all versions of windows support `IP_TOS`.
///
/// [`set_tos`]: Socket::set_tos
/// [`set_tos_v4`]: Socket::set_tos_v4
#[cfg(not(any(
target_os = "fuchsia",
target_os = "redox",
target_os = "solaris",
target_os = "illumos",
target_os = "haiku",
)))]
pub fn tos(&self) -> io::Result<u32> {
pub fn tos_v4(&self) -> io::Result<u32> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IP, sys::IP_TOS).map(|tos| tos as u32)
}
Expand All @@ -1632,7 +1632,7 @@ impl Socket {
target_os = "espidf",
target_os = "vita",
)))]
pub fn set_recv_tos(&self, recv_tos: bool) -> io::Result<()> {
pub fn set_recv_tos_v4(&self, recv_tos: bool) -> io::Result<()> {
unsafe {
setsockopt(
self.as_raw(),
Expand All @@ -1645,9 +1645,9 @@ impl Socket {

/// Get the value of the `IP_RECVTOS` option for this socket.
///
/// For more information about this option, see [`set_recv_tos`].
/// For more information about this option, see [`set_recv_tos_v4`].
///
/// [`set_recv_tos`]: Socket::set_recv_tos
/// [`set_recv_tos_v4`]: Socket::set_recv_tos_v4
#[cfg(not(any(
target_os = "aix",
target_os = "dragonfly",
Expand All @@ -1663,7 +1663,7 @@ impl Socket {
target_os = "espidf",
target_os = "vita",
)))]
pub fn recv_tos(&self) -> io::Result<bool> {
pub fn recv_tos_v4(&self) -> io::Result<bool> {
unsafe {
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IP, sys::IP_RECVTOS)
.map(|recv_tos| recv_tos > 0)
Expand Down
10 changes: 5 additions & 5 deletions tests/socket.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1366,8 +1366,8 @@ test!(
#[cfg(all(feature = "all", target_os = "linux"))]
test!(
#[ignore = "setting `IP_TRANSPARENT` requires the `CAP_NET_ADMIN` capability (works when running as root)"]
ip_transparent,
set_ip_transparent(true)
ip_transparent_v4,
set_ip_transparent_v4(true)
);
#[cfg(all(feature = "all", any(target_os = "fuchsia", target_os = "linux")))]
test!(
Expand Down Expand Up @@ -1401,7 +1401,7 @@ test!(freebind, set_freebind(true));
#[cfg(all(feature = "all", target_os = "linux"))]
test!(IPv6 freebind_ipv6, set_freebind_ipv6(true));

test!(IPv4 ttl, set_ttl(40));
test!(IPv4 ttl_v4, set_ttl_v4(40));

#[cfg(not(any(
target_os = "fuchsia",
Expand All @@ -1410,7 +1410,7 @@ test!(IPv4 ttl, set_ttl(40));
target_os = "illumos",
target_os = "haiku",
)))]
test!(IPv4 tos, set_tos(96));
test!(IPv4 tos_v4, set_tos_v4(96));

#[cfg(not(any(
target_os = "dragonfly",
Expand All @@ -1425,7 +1425,7 @@ test!(IPv4 tos, set_tos(96));
target_os = "vita",
target_os = "haiku",
)))]
test!(IPv4 recv_tos, set_recv_tos(true));
test!(IPv4 recv_tos_v4, set_recv_tos_v4(true));

#[cfg(not(windows))] // TODO: returns `WSAENOPROTOOPT` (10042) on Windows.
test!(IPv4 broadcast, set_broadcast(true));
Expand Down
Loading