修复macos上已知问题
This commit is contained in:
@@ -83,11 +83,20 @@ pub fn start(
|
||||
mut up_counter: SingleU64Adder,
|
||||
) -> io::Result<()> {
|
||||
let worker = {
|
||||
#[cfg(target_os = "macos")]
|
||||
let current_device = current_device.clone();
|
||||
let device = device.clone();
|
||||
stop_manager.add_listener("tun_device".into(), move || {
|
||||
if let Err(e) = device.shutdown() {
|
||||
log::warn!("{:?}", e);
|
||||
}
|
||||
#[cfg(target_os = "macos")]
|
||||
{
|
||||
let ip = current_device.load().virtual_ip;
|
||||
if let Ok(udp) = std::net::UdpSocket::bind("0.0.0.0:0"){
|
||||
let _ = udp.send_to(b"stop",format!("{:?}:1234",ip));
|
||||
}
|
||||
}
|
||||
})?
|
||||
};
|
||||
if parallel > 1 {
|
||||
|
||||
@@ -235,7 +235,7 @@ impl IFace for Device {
|
||||
}
|
||||
|
||||
fn shutdown(&self) -> io::Result<()> {
|
||||
self.enabled(false)
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn set_ip(&self, address: Ipv4Addr, mask: Ipv4Addr) -> io::Result<()> {
|
||||
@@ -281,6 +281,11 @@ impl IFace for Device {
|
||||
}
|
||||
|
||||
fn write(&self, buf: &[u8]) -> io::Result<usize> {
|
||||
self.tun.write(buf)
|
||||
let mut packet = Vec::<u8>::with_capacity(4 + buf.len());
|
||||
packet.push(0);
|
||||
packet.push(0);
|
||||
packet.extend_from_slice(&(libc::PF_INET as u16).to_be_bytes());
|
||||
packet.extend_from_slice(buf);
|
||||
self.tun.write(&packet)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user