66use crate :: alloc:: string:: String ;
77use crate :: backend:: c;
88use crate :: backend:: io:: syscalls:: ioctl;
9- use crate :: fd:: AsFd ;
9+ use crate :: fd:: BorrowedFd ;
1010use crate :: io;
1111#[ cfg( feature = "alloc" ) ]
1212use c:: SIOCGIFNAME ;
1313use c:: { __c_anonymous_ifr_ifru, c_char, ifreq, IFNAMSIZ , SIOCGIFINDEX } ;
1414
15- pub ( crate ) fn name_to_index ( fd : impl AsFd , if_name : & str ) -> io:: Result < u32 > {
15+ pub ( crate ) fn name_to_index ( fd : BorrowedFd < ' _ > , if_name : & str ) -> io:: Result < u32 > {
1616 let if_name_bytes = if_name. as_bytes ( ) ;
1717 if if_name_bytes. len ( ) >= IFNAMSIZ as usize {
1818 return Err ( io:: Errno :: NODEV ) ;
@@ -26,21 +26,21 @@ pub(crate) fn name_to_index(fd: impl AsFd, if_name: &str) -> io::Result<u32> {
2626 let mut if_name_c_char_iter = if_name_bytes. iter ( ) . map ( |byte| * byte as c_char ) ;
2727 ifreq. ifr_name [ ..if_name_bytes. len ( ) ] . fill_with ( || if_name_c_char_iter. next ( ) . unwrap ( ) ) ;
2828
29- unsafe { ioctl ( fd. as_fd ( ) , SIOCGIFINDEX as _ , & mut ifreq as * mut ifreq as _ ) } ?;
29+ unsafe { ioctl ( fd, SIOCGIFINDEX as _ , & mut ifreq as * mut ifreq as _ ) } ?;
3030 let index = unsafe { ifreq. ifr_ifru . ifru_ifindex } ;
3131 Ok ( index as u32 )
3232}
3333
3434#[ cfg( feature = "alloc" ) ]
35- pub ( crate ) fn index_to_name ( fd : impl AsFd , index : u32 ) -> io:: Result < String > {
35+ pub ( crate ) fn index_to_name ( fd : BorrowedFd < ' _ > , index : u32 ) -> io:: Result < String > {
3636 let mut ifreq = ifreq {
3737 ifr_name : [ 0 ; 16 ] ,
3838 ifr_ifru : __c_anonymous_ifr_ifru {
3939 ifru_ifindex : index as _ ,
4040 } ,
4141 } ;
4242
43- unsafe { ioctl ( fd. as_fd ( ) , SIOCGIFNAME as _ , & mut ifreq as * mut ifreq as _ ) } ?;
43+ unsafe { ioctl ( fd, SIOCGIFNAME as _ , & mut ifreq as * mut ifreq as _ ) } ?;
4444
4545 if let Some ( nul_byte) = ifreq. ifr_name . iter ( ) . position ( |char| * char == 0 ) {
4646 let name: String = ifreq. ifr_name [ ..nul_byte]
0 commit comments