add makefile
This commit is contained in:
parent
94233874e6
commit
261f24d9ef
24 changed files with 207 additions and 293 deletions
|
|
@ -1,13 +1,9 @@
|
|||
use std::mem::size_of;
|
||||
use std::{
|
||||
io::{Error, Read},
|
||||
mem,
|
||||
os::fd::{AsRawFd, FromRawFd, IntoRawFd, RawFd},
|
||||
};
|
||||
|
||||
use tracing::{debug, error, instrument};
|
||||
|
||||
use super::{syscall, TunOptions};
|
||||
use tracing::instrument;
|
||||
|
||||
mod queue;
|
||||
|
||||
|
|
@ -19,13 +15,9 @@ mod imp;
|
|||
#[path = "linux/mod.rs"]
|
||||
mod imp;
|
||||
|
||||
use crate::os_imp::imp::sys;
|
||||
use crate::os_imp::imp::sys::resolve_ctl_info;
|
||||
use fehler::throws;
|
||||
pub use imp::TunInterface;
|
||||
use libc::{getpeername, sockaddr_ctl, sockaddr_storage, socklen_t, AF_SYSTEM, AF_SYS_CONTROL};
|
||||
pub use queue::TunQueue;
|
||||
use socket2::SockAddr;
|
||||
|
||||
impl AsRawFd for TunInterface {
|
||||
fn as_raw_fd(&self) -> RawFd {
|
||||
|
|
@ -82,35 +74,3 @@ pub fn string_to_ifname(name: &str) -> [libc::c_char; libc::IFNAMSIZ] {
|
|||
buf[..len].copy_from_slice(unsafe { &*(name.as_bytes() as *const _ as *const [libc::c_char]) });
|
||||
buf
|
||||
}
|
||||
|
||||
#[cfg(any(target_os = "linux", target_vendor = "apple"))]
|
||||
pub fn retrieve() -> Option<TunInterface> {
|
||||
(3..100)
|
||||
.filter_map(|i| {
|
||||
let result = unsafe {
|
||||
let mut addr = sockaddr_ctl {
|
||||
sc_len: size_of::<sockaddr_ctl>() as u8,
|
||||
sc_family: 0,
|
||||
ss_sysaddr: 0,
|
||||
sc_id: 0,
|
||||
sc_unit: 0,
|
||||
sc_reserved: Default::default(),
|
||||
};
|
||||
let mut len = mem::size_of::<sockaddr_ctl>() as libc::socklen_t;
|
||||
let res = syscall!(getpeername(i, &mut addr as *mut _ as *mut _, len as *mut _));
|
||||
tracing::debug!("getpeername{}: {:?}", i, res);
|
||||
if res.is_err() {
|
||||
return None;
|
||||
}
|
||||
if addr.sc_family == sys::AF_SYSTEM as u8
|
||||
&& addr.ss_sysaddr == sys::AF_SYS_CONTROL as u16
|
||||
{
|
||||
Some(TunInterface::from_raw_fd(i))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
};
|
||||
result
|
||||
})
|
||||
.next()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue