@@ -955,6 +955,47 @@ fn into_linger(duration: Option<Duration>) -> sys::linger {
955
955
/// * Linux: <https://man7.org/linux/man-pages/man7/ip.7.html>
956
956
/// * Windows: <https://docs.microsoft.com/en-us/windows/win32/winsock/ipproto-ip-socket-options>
957
957
impl Socket {
958
+ /// Get the value of the `IP_TRANSPARENT` option on this socket.
959
+ ///
960
+ /// For more information about this option, see [`set_ip_transparent`].
961
+ ///
962
+ /// [`ip_transparent`]: Socket::set_ip_transparent
963
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
964
+ pub fn ip_transparent ( & self ) -> io:: Result < bool > {
965
+ unsafe {
966
+ getsockopt :: < c_int > ( self . as_raw ( ) , sys:: IPPROTO_IP , libc:: IP_TRANSPARENT )
967
+ . map ( |transparent| transparent != 0 )
968
+ }
969
+ }
970
+
971
+ /// Set the value of the `IP_TRANSPARENT` option on this socket.
972
+ ///
973
+ /// Setting this boolean option enables transparent proxying
974
+ /// on this socket. This socket option allows the calling
975
+ /// application to bind to a nonlocal IP address and operate
976
+ /// both as a client and a server with the foreign address as
977
+ /// the local endpoint. NOTE: this requires that routing be
978
+ /// set up in a way that packets going to the foreign address
979
+ /// are routed through the TProxy box (i.e., the system
980
+ /// hosting the application that employs the IP_TRANSPARENT
981
+ /// socket option). Enabling this socket option requires
982
+ /// superuser privileges (the CAP_NET_ADMIN capability).
983
+ ///
984
+ /// TProxy redirection with the iptables TPROXY target also
985
+ /// requires that this option be set on the redirected socket.
986
+ /// this feature is only available on linux
987
+ #[ cfg( all( feature = "all" , target_os = "linux" ) ) ]
988
+ pub fn set_ip_transparent ( & self , transparent : bool ) -> io:: Result < ( ) > {
989
+ unsafe {
990
+ setsockopt (
991
+ self . as_raw ( ) ,
992
+ sys:: IPPROTO_IP ,
993
+ libc:: IP_TRANSPARENT ,
994
+ transparent as c_int ,
995
+ )
996
+ }
997
+ }
998
+
958
999
/// Join a multicast group using `IP_ADD_MEMBERSHIP` option on this socket.
959
1000
///
960
1001
/// This function specifies a new multicast group for this socket to join.
0 commit comments