2024-02-29 07:08:44 +03:30
|
|
|
#![cfg(any(target_os = "ios", target_os = "macos"))]
|
2024-02-01 19:15:32 +08:00
|
|
|
|
|
|
|
use crate::{
|
|
|
|
args::{ArgDns, ArgProxy},
|
|
|
|
ArgVerbosity, Args,
|
|
|
|
};
|
2024-02-10 17:36:54 +01:00
|
|
|
use std::os::raw::{c_char, c_int, c_ushort};
|
2024-02-01 19:15:32 +08:00
|
|
|
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// Run the tun2proxy component with some arguments.
|
2024-02-29 07:08:44 +03:30
|
|
|
/// Parameters:
|
|
|
|
/// - proxy_url: the proxy url, e.g. "socks5://127.0.0.1:1080"
|
|
|
|
/// - tun_fd: the tun file descriptor
|
|
|
|
/// - tun_mtu: the tun mtu
|
|
|
|
/// - dns_strategy: the dns strategy, see ArgDns enum
|
|
|
|
/// - verbosity: the verbosity level, see ArgVerbosity enum
|
2024-02-01 19:15:32 +08:00
|
|
|
#[no_mangle]
|
2024-02-29 07:08:44 +03:30
|
|
|
pub unsafe extern "C" fn tun2proxy_with_fd_run(
|
2024-02-01 19:15:32 +08:00
|
|
|
proxy_url: *const c_char,
|
|
|
|
tun_fd: c_int,
|
2024-02-10 17:36:54 +01:00
|
|
|
tun_mtu: c_ushort,
|
2024-02-07 23:32:51 +08:00
|
|
|
dns_strategy: ArgDns,
|
|
|
|
verbosity: ArgVerbosity,
|
2024-02-01 19:15:32 +08:00
|
|
|
) -> c_int {
|
2024-02-07 23:32:51 +08:00
|
|
|
log::set_max_level(verbosity.into());
|
2024-02-01 19:15:32 +08:00
|
|
|
log::set_boxed_logger(Box::<crate::dump_logger::DumpLogger>::default()).unwrap();
|
|
|
|
|
|
|
|
let proxy_url = std::ffi::CStr::from_ptr(proxy_url).to_str().unwrap();
|
|
|
|
let proxy = ArgProxy::from_url(proxy_url).unwrap();
|
|
|
|
|
2024-02-12 21:36:18 +08:00
|
|
|
let mut args = Args::default();
|
|
|
|
args.proxy(proxy).tun_fd(Some(tun_fd)).dns(dns_strategy).verbosity(verbosity);
|
2024-02-01 19:15:32 +08:00
|
|
|
|
2024-02-13 10:46:13 +08:00
|
|
|
crate::mobile_api::mobile_run(args, tun_mtu)
|
2024-02-01 19:15:32 +08:00
|
|
|
}
|
|
|
|
|
|
|
|
/// # Safety
|
|
|
|
///
|
|
|
|
/// Shutdown the tun2proxy component.
|
|
|
|
#[no_mangle]
|
2024-02-29 07:08:44 +03:30
|
|
|
pub unsafe extern "C" fn tun2proxy_with_fd_stop() -> c_int {
|
2024-02-13 10:46:13 +08:00
|
|
|
crate::mobile_api::mobile_stop()
|
2024-02-01 19:15:32 +08:00
|
|
|
}
|