Fix types and fix build + clippy lints for linux

This commit changes `copy_if_name` to take a c_char.
This commit is contained in:
dav 2023-04-12 19:30:03 -07:00 committed by Conrad Kramer
parent 47f1312666
commit 02efa85a19
3 changed files with 8 additions and 6 deletions

View file

@ -38,7 +38,7 @@ impl TunInterface {
}
pub fn name(&self) -> Result<String> {
let mut buf = [0u8; libc::IFNAMSIZ];
let mut buf = [0i8; libc::IFNAMSIZ];
let mut len = buf.len() as libc::socklen_t;
syscall!(getsockopt(
self.as_raw_fd(),

View file

@ -15,13 +15,13 @@ impl TunInterface {
.write(true)
.open("/dev/net/tun")?;
let mut iff = libc::ifreq {
let iff = libc::ifreq {
ifr_name: [0; libc::IFNAMSIZ],
ifr_ifru: libc::__c_anonymous_ifr_ifru {
ifru_flags: (libc::IFF_TUN | libc::IFF_TUN_EXCL | libc::IFF_NO_PI) as i16,
},
};
unsafe { sys::tun_set_iff(file.as_raw_fd(), &mut iff)? };
unsafe { sys::tun_set_iff(file.as_raw_fd(), &iff)? };
let inner = unsafe { socket2::Socket::from_raw_fd(file.into_raw_fd()) };
Ok(TunInterface { inner })
@ -50,7 +50,9 @@ mod sys {
);
ioctl_read_bad!(
tun_get_iff,
request_code_read!(b'T', 210, size_of::<libc::c_int>()),
request_code_read!(b'T', 210, size_of::<libc::c_uint>()),
libc::ifreq
);
}
pub struct TunQueue;

View file

@ -1,6 +1,6 @@
use std::ffi::CStr;
use std::ffi::{c_char, CStr};
pub fn copy_if_name(buf: [u8; libc::IFNAMSIZ]) -> String {
pub fn copy_if_name(buf: [c_char; libc::IFNAMSIZ]) -> String {
// TODO: Switch to `CStr::from_bytes_until_nul` when stabilized
unsafe {
CStr::from_ptr(buf.as_ptr() as *const _)