From 02efa85a19b2a33052e9709d0e40023c5c1a2b91 Mon Sep 17 00:00:00 2001 From: dav Date: Wed, 12 Apr 2023 19:30:03 -0700 Subject: [PATCH] Fix types and fix build + clippy lints for linux This commit changes `copy_if_name` to take a c_char. --- tun/src/apple/mod.rs | 2 +- tun/src/linux.rs | 8 +++++--- tun/src/unix.rs | 4 ++-- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/tun/src/apple/mod.rs b/tun/src/apple/mod.rs index ff78a49..cce4ea1 100644 --- a/tun/src/apple/mod.rs +++ b/tun/src/apple/mod.rs @@ -38,7 +38,7 @@ impl TunInterface { } pub fn name(&self) -> Result { - 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(), diff --git a/tun/src/linux.rs b/tun/src/linux.rs index 93a341e..b1ef0ae 100644 --- a/tun/src/linux.rs +++ b/tun/src/linux.rs @@ -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::()), + request_code_read!(b'T', 210, size_of::()), libc::ifreq ); } + +pub struct TunQueue; diff --git a/tun/src/unix.rs b/tun/src/unix.rs index b598c62..17c425c 100644 --- a/tun/src/unix.rs +++ b/tun/src/unix.rs @@ -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 _)