From a57a993dab7715b0dde4874f5d37d1b3f9e6a73e Mon Sep 17 00:00:00 2001 From: Nathaniel Bennett Date: Mon, 4 Nov 2024 21:08:46 -0500 Subject: [PATCH] Remove every instance of i8 and replace with libc::c_char --- src/lib.rs | 2 +- src/linux/tap.rs | 8 ++++---- src/linux/tun.rs | 8 ++++---- src/macos/feth.rs | 18 ++++++++++++------ src/macos/utun.rs | 7 ++++++- src/unix/tap.rs | 2 +- src/unix/tun.rs | 4 ++-- 7 files changed, 30 insertions(+), 19 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index baefbe8..13cdfc8 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -675,7 +675,7 @@ impl Interface { } let mut name = [0u8; Self::MAX_INTERFACE_NAME_LEN + 1]; - match unsafe { libc::if_indextoname(if_index, name.as_mut_ptr() as *mut i8) } { + match unsafe { libc::if_indextoname(if_index, name.as_mut_ptr() as *mut libc::c_char) } { ptr if ptr.is_null() => Err(io::Error::last_os_error()), _ => Ok(Self { name, diff --git a/src/linux/tap.rs b/src/linux/tap.rs index 834cfea..8d82859 100644 --- a/src/linux/tap.rs +++ b/src/linux/tap.rs @@ -43,7 +43,7 @@ impl Tap { let flags = libc::IFF_TAP | libc::IFF_NO_PI | libc::IFF_TUN_EXCL; let mut req = libc::ifreq { - ifr_name: [0i8; 16], + ifr_name: [0; 16], ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: flags as i16, }, @@ -137,7 +137,7 @@ impl Tap { /// Retrieves the interface name associated with the TAP device. pub fn name(&self) -> io::Result { let mut req = libc::ifreq { - ifr_name: [0i8; 16], + ifr_name: [0; 16], ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: 0 }, }; @@ -177,7 +177,7 @@ impl Tap { /// Retrieves the current state of the TAP device (i.e. "up" or "down"). pub fn state(&self) -> io::Result { let mut req = libc::ifreq { - ifr_name: [0i8; 16], + ifr_name: [0; 16], ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: 0 }, }; @@ -198,7 +198,7 @@ impl Tap { /// Sets the adapter state of the TAP device (e.g. "up" or "down"). pub fn set_state(&self, state: DeviceState) -> io::Result<()> { let mut req = libc::ifreq { - ifr_name: [0i8; 16], + ifr_name: [0; 16], ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: 0 }, }; diff --git a/src/linux/tun.rs b/src/linux/tun.rs index a10e3e5..24a24f0 100644 --- a/src/linux/tun.rs +++ b/src/linux/tun.rs @@ -43,7 +43,7 @@ impl Tun { let flags = libc::IFF_TUN_EXCL | libc::IFF_TUN | libc::IFF_NO_PI; let mut req = libc::ifreq { - ifr_name: [0i8; 16], + ifr_name: [0; 16], ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: flags as i16, }, @@ -134,7 +134,7 @@ impl Tun { /// Retrieves the interface name associated with the TUN device. pub fn name(&self) -> io::Result { let mut req = libc::ifreq { - ifr_name: [0i8; 16], + ifr_name: [0; 16], ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: 0 }, }; @@ -175,7 +175,7 @@ impl Tun { /// Retrieves the current state of the TUN device (i.e. "up" or "down"). pub fn state(&self) -> io::Result { let mut req = libc::ifreq { - ifr_name: [0i8; 16], + ifr_name: [0; 16], ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: 0 }, }; @@ -196,7 +196,7 @@ impl Tun { /// Sets the adapter state of the TUN device (e.g. "up" or "down"). pub fn set_state(&self, state: DeviceState) -> io::Result<()> { let mut req = libc::ifreq { - ifr_name: [0i8; 16], + ifr_name: [0; 16], ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_flags: 0 }, }; diff --git a/src/macos/feth.rs b/src/macos/feth.rs index 522a787..7f48849 100644 --- a/src/macos/feth.rs +++ b/src/macos/feth.rs @@ -800,7 +800,7 @@ impl FethTap { ifr_ifru: libc::__c_anonymous_ifr_ifru { ifru_addr: libc::sockaddr { sa_family: 0, - sa_data: [0i8; 14], + sa_data: [0; 14], } }, }; @@ -828,7 +828,13 @@ impl FethTap { sdl_nlen: 0, sdl_alen: 6, // This is what the XNU kernel wants, based on source inspection sdl_slen: 0, - sdl_data: array::from_fn(|i| if i < 6 { addr.addr[i] as i8 } else { 0i8 }), + sdl_data: array::from_fn(|i| { + if i < 6 { + addr.addr[i] as libc::c_char + } else { + 0 + } + }), }; let mut req = libc::ifreq { @@ -837,7 +843,7 @@ impl FethTap { ifru_addr: libc::sockaddr { sa_family: 0, sa_len: mem::size_of::() as u8, - sa_data: [0i8; 14], + sa_data: [0; 14], }, }, }; @@ -874,9 +880,9 @@ impl FethTap { sdl_slen: 0, sdl_data: array::from_fn(|i| { if i < 6 { - multicast_addr.addr[i] as i8 + multicast_addr.addr[i] as libc::c_char } else { - 0i8 + 0 } }), }; @@ -887,7 +893,7 @@ impl FethTap { ifru_addr: libc::sockaddr { sa_family: 0, sa_len: mem::size_of::() as u8, - sa_data: [0i8; 14], + sa_data: [0; 14], }, }, }; diff --git a/src/macos/utun.rs b/src/macos/utun.rs index 3c1cc2e..c99c611 100644 --- a/src/macos/utun.rs +++ b/src/macos/utun.rs @@ -95,7 +95,12 @@ impl Utun { let mut utun_ctrl_iter = UTUN_CONTROL_NAME.iter(); let mut info = libc::ctl_info { ctl_id: 0u32, - ctl_name: array::from_fn(|_| utun_ctrl_iter.next().map(|b| *b as i8).unwrap_or(0)), + ctl_name: array::from_fn(|_| { + utun_ctrl_iter + .next() + .map(|b| *b as libc::c_char) + .unwrap_or(0) + }), }; if unsafe { diff --git a/src/unix/tap.rs b/src/unix/tap.rs index 724a65d..bb9f415 100644 --- a/src/unix/tap.rs +++ b/src/unix/tap.rs @@ -109,7 +109,7 @@ impl Tap { let mut name = [0u8; Interface::MAX_INTERFACE_NAME_LEN + 1]; if fdevname_r( tap_fd, - name.as_mut_ptr() as *mut i8, + name.as_mut_ptr() as *mut libc::c_char, Interface::MAX_INTERFACE_NAME_LEN as i32, ) .is_null() diff --git a/src/unix/tun.rs b/src/unix/tun.rs index fe4a5ef..433073e 100644 --- a/src/unix/tun.rs +++ b/src/unix/tun.rs @@ -132,7 +132,7 @@ impl Tun { let mut name = [0u8; Interface::MAX_INTERFACE_NAME_LEN + 1]; if fdevname_r( tun_fd, - name.as_mut_ptr() as *mut i8, + name.as_mut_ptr() as *mut libc::c_char, Interface::MAX_INTERFACE_NAME_LEN as i32, ) .is_null() @@ -151,7 +151,7 @@ impl Tun { let mut name = [0u8; Interface::MAX_INTERFACE_NAME_LEN + 1]; if fdevname_r( tun_fd, - name.as_mut_ptr() as *mut i8, + name.as_mut_ptr() as *mut libc::c_char, Interface::MAX_INTERFACE_NAME_LEN as i32, ) != 0 {