File tree 3 files changed +50
-0
lines changed
3 files changed +50
-0
lines changed Original file line number Diff line number Diff line change @@ -890,6 +890,28 @@ impl UnixDatagram {
890
890
self . 0 . set_mark ( mark)
891
891
}
892
892
893
+ /// Set the route FIB table id
894
+ ///
895
+ /// The kernel allows up to 65536 distinct routes
896
+ /// (visible via net.fibs sysctl), this socket option
897
+ /// allows to set the id programmatically
898
+ #[ cfg_attr( target_os = "freebsd" , doc = "```no_run" ) ]
899
+ #[ cfg_attr( not( target_os = "freebsd" ) , doc = "```ignore" ) ]
900
+ /// #![feature(unix_set_fib)]
901
+ /// use std::os::unix::net::UnixDatagram;
902
+ ///
903
+ /// fn main() -> std::io::Result<()> {
904
+ /// let sock = UnixDatagram::unbound()?;
905
+ /// sock.set_fib(1)?;
906
+ /// Ok(())
907
+ /// }
908
+ /// ```
909
+ #[ cfg( any( doc, target_os = "freebsd" ) ) ]
910
+ #[ unstable( feature = "unix_set_fib" , issue = "none" ) ]
911
+ pub fn set_fib ( & self , fib : i32 ) -> io:: Result < ( ) > {
912
+ self . 0 . set_fib ( fib)
913
+ }
914
+
893
915
/// Returns the value of the `SO_ERROR` option.
894
916
///
895
917
/// # Examples
Original file line number Diff line number Diff line change @@ -482,6 +482,28 @@ impl UnixStream {
482
482
self . 0 . set_mark ( mark)
483
483
}
484
484
485
+ /// Set the route FIB table id
486
+ ///
487
+ /// The kernel allows up to 65536 distinct routes
488
+ /// (visible via net.fibs sysctl), this socket option
489
+ /// allows to set the id programmatically
490
+ #[ cfg_attr( target_os = "freebsd" , doc = "```no_run" ) ]
491
+ #[ cfg_attr( not( target_os = "freebsd" ) , doc = "```ignore" ) ]
492
+ /// #![feature(unix_set_fib)]
493
+ /// use std::os::unix::net::UnixStream;
494
+ ///
495
+ /// fn main() -> std::io::Result<()> {
496
+ /// let sock = UnixStream::connect("/tmp/sock")?;
497
+ /// sock.set_fib(1)?;
498
+ /// Ok(())
499
+ /// }
500
+ /// ```
501
+ #[ cfg( any( doc, target_os = "freebsd" , ) ) ]
502
+ #[ unstable( feature = "unix_set_fib" , issue = "none" ) ]
503
+ pub fn set_fib ( & self , fib : i32 ) -> io:: Result < ( ) > {
504
+ self . 0 . set_fib ( fib)
505
+ }
506
+
485
507
/// Returns the value of the `SO_ERROR` option.
486
508
///
487
509
/// # Examples
Original file line number Diff line number Diff line change @@ -504,6 +504,12 @@ impl Socket {
504
504
setsockopt ( self , libc:: SOL_SOCKET , option, mark as libc:: c_int )
505
505
}
506
506
507
+ #[ cfg( target_os = "freebsd" ) ]
508
+ pub fn set_fib ( & self , fib : i32 ) -> io:: Result < ( ) > {
509
+ // Allows to bind the socket to special routing rules via ipfw
510
+ setsockopt ( self , libc:: SOL_SOCKET , libc:: SO_SETFIB , fib as libc:: c_int )
511
+ }
512
+
507
513
pub fn take_error ( & self ) -> io:: Result < Option < io:: Error > > {
508
514
let raw: c_int = getsockopt ( self , libc:: SOL_SOCKET , libc:: SO_ERROR ) ?;
509
515
if raw == 0 { Ok ( None ) } else { Ok ( Some ( io:: Error :: from_raw_os_error ( raw as i32 ) ) ) }
You can’t perform that action at this time.
0 commit comments