File tree 3 files changed +43
-0
lines changed
3 files changed +43
-0
lines changed Original file line number Diff line number Diff line change
1
+ Add socket option UtunIfname.
Original file line number Diff line number Diff line change @@ -1065,6 +1065,17 @@ sockopt_impl!(
1065
1065
libc:: IPV6_DONTFRAG ,
1066
1066
bool
1067
1067
) ;
1068
+ #[ cfg( apple_targets) ]
1069
+ #[ cfg( feature = "net" ) ]
1070
+ sockopt_impl ! (
1071
+ /// Get the utun interface name.
1072
+ UtunIfname ,
1073
+ GetOnly ,
1074
+ libc:: SYSPROTO_CONTROL ,
1075
+ libc:: UTUN_OPT_IFNAME ,
1076
+ OsString ,
1077
+ GetOsString <[ u8 ; libc:: IFNAMSIZ ] >
1078
+ ) ;
1068
1079
1069
1080
#[ allow( missing_docs) ]
1070
1081
// Not documented by Linux!
Original file line number Diff line number Diff line change @@ -828,3 +828,34 @@ fn test_ktls() {
828
828
Err ( err) => panic ! ( "{err:?}" ) ,
829
829
}
830
830
}
831
+
832
+ #[ test]
833
+ #[ cfg( apple_targets) ]
834
+ fn test_utun_ifname ( ) {
835
+ use nix:: sys:: socket:: connect;
836
+ use nix:: sys:: socket:: SysControlAddr ;
837
+
838
+ let fd = socket (
839
+ AddressFamily :: System ,
840
+ SockType :: Datagram ,
841
+ SockFlag :: empty ( ) ,
842
+ SockProtocol :: KextControl ,
843
+ )
844
+ . unwrap ( ) ;
845
+
846
+ let unit = 123 ;
847
+ let addr = SysControlAddr :: from_name (
848
+ fd. as_raw_fd ( ) ,
849
+ "com.apple.net.utun_control" ,
850
+ unit,
851
+ )
852
+ . unwrap ( ) ;
853
+
854
+ connect ( fd. as_raw_fd ( ) , & addr) . unwrap ( ) ;
855
+
856
+ let name = getsockopt ( & fd, sockopt:: UtunIfname )
857
+ . expect ( "getting UTUN_OPT_IFNAME on a utun interface should succeed" ) ;
858
+
859
+ let expected_name = format ! ( "utun{}\0 " , unit - 1 ) ;
860
+ assert_eq ! ( name. into_string( ) , Ok ( expected_name) ) ;
861
+ }
You can’t perform that action at this time.
0 commit comments