修复macos上已知问题

This commit is contained in:
lu
2024-03-12 23:52:53 +08:00
parent 8627046deb
commit 066e655c30
2 changed files with 16 additions and 2 deletions
+9
View File
@@ -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 {
+7 -2
View File
@@ -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)
}
}