@@ -3309,6 +3309,40 @@ impl crate::Socket {
33093309 )
33103310 }
33113311 }
3312+
3313+ /// Set the value of the `SO_BINDANY` option on this socket.
3314+ ///
3315+ /// SO_BINDANY allows the socket to be bound to addresses which are not
3316+ /// local to the machine, so it can be used to make a transparent proxy.
3317+ /// Note that this option is limited to the superuser. In order to
3318+ /// receive packets for these addresses, SO_BINDANY needs to be combined
3319+ /// with matching outgoing pf(4) rules with the divert-reply parameter.
3320+ #[ cfg( all( feature = "all" , target_os = "openbsd" ) ) ]
3321+ #[ cfg_attr( docsrs, doc( cfg( all( feature = "all" , target_os = "openbsd" ) ) ) ) ]
3322+ pub fn set_so_bindany ( & self , bindany : bool ) -> io:: Result < ( ) > {
3323+ unsafe {
3324+ setsockopt (
3325+ self . as_raw ( ) ,
3326+ libc:: IPPROTO_IP ,
3327+ libc:: SO_BINDANY ,
3328+ bindany as c_int ,
3329+ )
3330+ }
3331+ }
3332+
3333+ /// Get the value of the `IP_BINDANY` option on this socket.
3334+ ///
3335+ /// For more information about this option, see [`set_ip_bindany`].
3336+ ///
3337+ /// [`set_ip_bindany`]: crate::Socket::set_ip_bindany
3338+ #[ cfg( all( feature = "all" , target_os = "freebsd" ) ) ]
3339+ #[ cfg_attr( docsrs, doc( cfg( all( feature = "all" , target_os = "freebsd" ) ) ) ) ]
3340+ pub fn ip_bindany ( & self ) -> io:: Result < bool > {
3341+ unsafe {
3342+ getsockopt :: < c_int > ( self . as_raw ( ) , libc:: IPPROTO_IP , libc:: IP_BINDANY )
3343+ . map ( |bindany| bindany != 0 )
3344+ }
3345+ }
33123346}
33133347
33143348/// See [`Socket::dccp_available_ccids`].
0 commit comments