@@ -8,7 +8,7 @@ use crate::io;
8
8
use crate :: net:: netdevice:: open_socket;
9
9
#[ cfg( feature = "alloc" ) ]
10
10
use libc:: SIOCGIFNAME ;
11
- use libc:: { __c_anonymous_ifr_ifru, ifreq, IFNAMSIZ , SIOCGIFINDEX } ;
11
+ use libc:: { __c_anonymous_ifr_ifru, c_char , ifreq, IFNAMSIZ , SIOCGIFINDEX } ;
12
12
13
13
#[ cfg( target_os = "linux" ) ]
14
14
pub ( crate ) fn name_to_index ( if_name : & str ) -> io:: Result < u32 > {
@@ -22,11 +22,11 @@ pub(crate) fn name_to_index(if_name: &str) -> io::Result<u32> {
22
22
ifr_ifru : __c_anonymous_ifr_ifru { ifru_ifindex : 0 } ,
23
23
} ;
24
24
25
- let mut if_name_i8_iter = if_name_bytes. iter ( ) . map ( |byte| * byte as i8 ) ;
26
- ifreq. ifr_name [ ..if_name_bytes. len ( ) ] . fill_with ( || if_name_i8_iter . next ( ) . unwrap ( ) ) ;
25
+ let mut if_name_c_char_iter = if_name_bytes. iter ( ) . map ( |byte| * byte as c_char ) ;
26
+ ifreq. ifr_name [ ..if_name_bytes. len ( ) ] . fill_with ( || if_name_c_char_iter . next ( ) . unwrap ( ) ) ;
27
27
28
28
let fd = open_socket ( ) ?;
29
- unsafe { ioctl ( fd. as_fd ( ) , SIOCGIFINDEX , & mut ifreq as * mut ifreq as _ ) } ?;
29
+ unsafe { ioctl ( fd. as_fd ( ) , SIOCGIFINDEX as _ , & mut ifreq as * mut ifreq as _ ) } ?;
30
30
let index = unsafe { ifreq. ifr_ifru . ifru_ifindex } ;
31
31
Ok ( index as u32 )
32
32
}
@@ -46,7 +46,7 @@ pub(crate) fn index_to_name(index: u32) -> io::Result<String> {
46
46
let Some ( nul_byte) = ifreq. ifr_name . iter ( ) . position ( |char| * char == 0 ) else {
47
47
return Err ( io:: Errno :: INVAL ) ;
48
48
} ;
49
- let name = ifreq. ifr_name [ ..nul_byte]
49
+ let name: String = ifreq. ifr_name [ ..nul_byte]
50
50
. iter ( )
51
51
. map ( |v| * v as u8 as char )
52
52
. collect ( ) ;
0 commit comments