增加安卓端支持、优化广播、增加停止监听

This commit is contained in:
lubeilin
2023-07-05 23:36:41 +08:00
parent 890e5f7391
commit 50e97fd95f
25 changed files with 768 additions and 350 deletions
+10 -6
View File
@@ -1,11 +1,11 @@
use std::io;
use std::net::Ipv4Addr;
use crate::tun_tap_device::{DeviceReader, DeviceType, DeviceWriter};
use crate::tun_tap_device::{DeviceReader, DeviceType, DeviceWriter, DriverInfo};
use tun::Device;
use parking_lot::Mutex;
use std::process::Command;
use std::sync::Arc;
use crate::tun_tap_device::unix::DeviceW;
use crate::tun_tap_device::linux_mac::DeviceW;
impl DeviceWriter {
pub fn change_ip(&self, address: Ipv4Addr, netmask: Ipv4Addr,
@@ -56,8 +56,7 @@ pub fn create_device(device_type: DeviceType,
netmask: Ipv4Addr,
gateway: Ipv4Addr,
in_ips: Vec<(Ipv4Addr, Ipv4Addr)>,
) -> io::Result<(DeviceWriter, DeviceReader)> {
println!("========网卡配置========");
) -> io::Result<(DeviceWriter, DeviceReader,DriverInfo)> {
let mut config = tun::Configuration::default();
config
@@ -79,7 +78,6 @@ pub fn create_device(device_type: DeviceType,
let reader = queue.reader();
let writer = queue.writer();
let name = dev.name();
println!("name:{:?}", name);
for (address, netmask) in &in_ips {
add_route(name, *address, *netmask)?;
}
@@ -111,10 +109,16 @@ pub fn create_device(device_type: DeviceType,
DeviceW::Tap((writer, mac))
}
};
println!("========TUN网卡配置========");
let driver_info = DriverInfo {
device_type,
name:name.to_string(),
version:String::new(),
mac: None,
};
Ok((
DeviceWriter::new(device_w, Arc::new(Mutex::new(dev)), in_ips, address, packet_information),
DeviceReader::new(reader),
driver_info,
))
}