From 913fdfc929e6cbe3301168a573acc0f7445ca3d2 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 25 Jan 2025 11:14:50 +0100 Subject: [PATCH 1/4] Suffix Socket::(set_)ttl with v4 To indicate it an option for IPv4 sockets. --- src/socket.rs | 10 +++++----- tests/socket.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/socket.rs b/src/socket.rs index 698d3556..c23a6ebc 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -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 #[cfg_attr( any(target_os = "fuchsia", target_os = "illumos", target_os = "solaris"), allow(rustdoc::broken_intra_doc_links) @@ -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 { + /// [`set_ttl_v4`]: Socket::set_ttl_v4 + pub fn ttl_v4(&self) -> io::Result { unsafe { getsockopt::(self.as_raw(), sys::IPPROTO_IP, sys::IP_TTL).map(|ttl| ttl as u32) } @@ -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) } } diff --git a/tests/socket.rs b/tests/socket.rs index 98a535c7..e79a5a1a 100644 --- a/tests/socket.rs +++ b/tests/socket.rs @@ -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", From 1490af818b42194936d072cded722ffcce4c62ae Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 25 Jan 2025 11:15:48 +0100 Subject: [PATCH 2/4] Suffix Socket::(set_)tos with v4 To indicate it an option for IPv4 sockets. --- src/socket.rs | 10 +++++----- tests/socket.rs | 2 +- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/socket.rs b/src/socket.rs index c23a6ebc..19dce186 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -1190,8 +1190,8 @@ impl Socket { /// /// [`SOCK_RAW`]: Type::RAW /// [raw(7)]: https://man7.org/linux/man-pages/man7/raw.7.html - /// [`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) @@ -1587,18 +1587,18 @@ 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: /// 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", @@ -1606,7 +1606,7 @@ impl Socket { target_os = "illumos", target_os = "haiku", )))] - pub fn tos(&self) -> io::Result { + pub fn tos_v4(&self) -> io::Result { unsafe { getsockopt::(self.as_raw(), sys::IPPROTO_IP, sys::IP_TOS).map(|tos| tos as u32) } diff --git a/tests/socket.rs b/tests/socket.rs index e79a5a1a..28f1e84f 100644 --- a/tests/socket.rs +++ b/tests/socket.rs @@ -1410,7 +1410,7 @@ test!(IPv4 ttl_v4, set_ttl_v4(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", From 3e8bee44e8fa3fbba03e295d01818adafa72c307 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 25 Jan 2025 11:16:09 +0100 Subject: [PATCH 3/4] Suffix Socket::(set_)ip_transparent with v4 To indicate it an option for IPv4 sockets. --- src/socket.rs | 8 ++++---- tests/socket.rs | 4 ++-- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/socket.rs b/src/socket.rs index 19dce186..daac5def 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -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 { + pub fn ip_transparent_v4(&self) -> io::Result { unsafe { getsockopt::(self.as_raw(), sys::IPPROTO_IP, libc::IP_TRANSPARENT) .map(|transparent| transparent != 0) @@ -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(), diff --git a/tests/socket.rs b/tests/socket.rs index 28f1e84f..c1a407da 100644 --- a/tests/socket.rs +++ b/tests/socket.rs @@ -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!( From f2c3b951b02c775a9bbacfc008ed61cb645de350 Mon Sep 17 00:00:00 2001 From: Thomas de Zeeuw Date: Sat, 25 Jan 2025 11:16:27 +0100 Subject: [PATCH 4/4] Suffix Socket::(set_)recv_tos with v4 To indicate it an option for IPv4 sockets. --- src/socket.rs | 8 ++++---- tests/socket.rs | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/src/socket.rs b/src/socket.rs index daac5def..822ab93c 100644 --- a/src/socket.rs +++ b/src/socket.rs @@ -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(), @@ -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", @@ -1663,7 +1663,7 @@ impl Socket { target_os = "espidf", target_os = "vita", )))] - pub fn recv_tos(&self) -> io::Result { + pub fn recv_tos_v4(&self) -> io::Result { unsafe { getsockopt::(self.as_raw(), sys::IPPROTO_IP, sys::IP_RECVTOS) .map(|recv_tos| recv_tos > 0) diff --git a/tests/socket.rs b/tests/socket.rs index c1a407da..3776a4b4 100644 --- a/tests/socket.rs +++ b/tests/socket.rs @@ -1425,7 +1425,7 @@ test!(IPv4 tos_v4, set_tos_v4(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));