Skip to content

Commit ae6581e

Browse files
committed
Deprecate (set_)ip_transparent in favour of (set_)ip_transparent_v4
1 parent 935c48b commit ae6581e

File tree

2 files changed

+47
-4
lines changed

2 files changed

+47
-4
lines changed

src/sys/unix.rs

Lines changed: 38 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3098,11 +3098,28 @@ impl crate::Socket {
30983098
}
30993099
}
31003100

3101+
/// This method is deprecated, use [`crate::Socket::ip_transparent_v4`].
3102+
#[cfg(all(
3103+
feature = "all",
3104+
any(target_os = "android", target_os = "linux", target_os = "fuchsia")
3105+
))]
3106+
#[cfg_attr(
3107+
docsrs,
3108+
doc(cfg(all(
3109+
feature = "all",
3110+
any(target_os = "android", target_os = "linux", target_os = "fuchsia")
3111+
)))
3112+
)]
3113+
#[deprecated = "Use `Socket::ip_transparent_v4` instead"]
3114+
pub fn ip_transparent(&self) -> io::Result<bool> {
3115+
self.ip_transparent_v4()
3116+
}
3117+
31013118
/// Get the value of the `IP_TRANSPARENT` option on this socket.
31023119
///
3103-
/// For more information about this option, see [`set_ip_transparent`].
3120+
/// For more information about this option, see [`set_ip_transparent_v4`].
31043121
///
3105-
/// [`set_ip_transparent`]: Socket::set_ip_transparent
3122+
/// [`set_ip_transparent_v4`]: Socket::set_ip_transparent_v4
31063123
#[cfg(all(
31073124
feature = "all",
31083125
any(target_os = "android", target_os = "linux", target_os = "fuchsia")
@@ -3114,13 +3131,30 @@ impl crate::Socket {
31143131
any(target_os = "android", target_os = "linux", target_os = "fuchsia")
31153132
)))
31163133
)]
3117-
pub fn ip_transparent(&self) -> io::Result<bool> {
3134+
pub fn ip_transparent_v4(&self) -> io::Result<bool> {
31183135
unsafe {
31193136
getsockopt::<c_int>(self.as_raw(), sys::IPPROTO_IP, libc::IP_TRANSPARENT)
31203137
.map(|transparent| transparent != 0)
31213138
}
31223139
}
31233140

3141+
/// This method is deprecated, use [`crate::Socket::set_ip_transparent_v4`].
3142+
#[cfg(all(
3143+
feature = "all",
3144+
any(target_os = "android", target_os = "linux", target_os = "fuchsia")
3145+
))]
3146+
#[cfg_attr(
3147+
docsrs,
3148+
doc(cfg(all(
3149+
feature = "all",
3150+
any(target_os = "android", target_os = "linux", target_os = "fuchsia")
3151+
)))
3152+
)]
3153+
#[deprecated = "Use `Socket::set_ip_transparent_v4` instead"]
3154+
pub fn set_ip_transparent(&self, transparent: bool) -> io::Result<()> {
3155+
self.set_ip_transparent_v4()
3156+
}
3157+
31243158
/// Set the value of the `IP_TRANSPARENT` option on this socket.
31253159
///
31263160
/// Setting this boolean option enables transparent proxying
@@ -3147,7 +3181,7 @@ impl crate::Socket {
31473181
any(target_os = "android", target_os = "linux", target_os = "fuchsia")
31483182
)))
31493183
)]
3150-
pub fn set_ip_transparent(&self, transparent: bool) -> io::Result<()> {
3184+
pub fn set_ip_transparent_v4(&self, transparent: bool) -> io::Result<()> {
31513185
unsafe {
31523186
setsockopt(
31533187
self.as_raw(),

tests/socket.rs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1372,6 +1372,15 @@ test!(
13721372
ip_transparent,
13731373
set_ip_transparent(true)
13741374
);
1375+
#[cfg(all(
1376+
feature = "all",
1377+
any(target_os = "android", target_os = "linux", target_os = "fuchsia")
1378+
))]
1379+
test!(
1380+
#[ignore = "setting `IP_TRANSPARENT` requires the `CAP_NET_ADMIN` capability (works when running as root)"]
1381+
ip_transparent,
1382+
set_ip_transparent_v4(true)
1383+
);
13751384
#[cfg(all(feature = "all", any(target_os = "fuchsia", target_os = "linux")))]
13761385
test!(
13771386
#[ignore = "setting `SO_MARK` requires the `CAP_NET_ADMIN` capability (works when running as root)"]

0 commit comments

Comments
 (0)