File tree Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Expand file tree Collapse file tree 2 files changed +16
-2
lines changed Original file line number Diff line number Diff line change @@ -900,16 +900,24 @@ impl Socket {
900
900
/// requires that this option be set on the redirected socket.
901
901
/// this feature is only available on linux
902
902
#[ cfg( any( target_os = "linux" ) ) ]
903
- pub fn set_ip_transparent ( & self ) -> io:: Result < ( ) > {
903
+ pub fn set_ip_transparent ( & self , transparent : bool ) -> io:: Result < ( ) > {
904
904
unsafe {
905
905
setsockopt (
906
906
self . inner ,
907
907
sys:: IPPROTO_IP ,
908
908
libc:: IP_TRANSPARENT ,
909
- 1 as c_int ,
909
+ transparent as c_int ,
910
910
)
911
911
}
912
912
}
913
+ /// Get whether the IP_TRANSPARENT is set for this socket.
914
+ #[ cfg( any( target_os = "linux" ) ) ]
915
+ pub fn ip_transparent ( & self ) -> io:: Result < bool > {
916
+ unsafe {
917
+ getsockopt :: < c_int > ( self . inner , sys:: IPPROTO_IP , libc:: IP_TRANSPARENT )
918
+ . map ( |transparent| transparent != 0 )
919
+ }
920
+ }
913
921
914
922
/// Get the value of the `SO_SNDBUF` option on this socket.
915
923
///
Original file line number Diff line number Diff line change @@ -1047,6 +1047,12 @@ test!(
1047
1047
mss,
1048
1048
set_mss( 256 )
1049
1049
) ;
1050
+ #[ cfg( any( target_os = "linux" ) ) ]
1051
+ test ! (
1052
+ #[ ignore = "setting `IP_TRANSPARENT` requires the `CAP_NET_ADMIN` capability (works when running as root)" ]
1053
+ ip_transparent,
1054
+ set_ip_transparent( true )
1055
+ ) ;
1050
1056
#[ cfg( all( feature = "all" , any( target_os = "fuchsia" , target_os = "linux" ) ) ) ]
1051
1057
test ! (
1052
1058
#[ ignore = "setting `SO_MARK` requires the `CAP_NET_ADMIN` capability (works when running as root)" ]
You can’t perform that action at this time.
0 commit comments