diff --git a/vnt/src/handle/tun_tap/tun_handler.rs b/vnt/src/handle/tun_tap/tun_handler.rs index c849309..3e50361 100644 --- a/vnt/src/handle/tun_tap/tun_handler.rs +++ b/vnt/src/handle/tun_tap/tun_handler.rs @@ -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 { diff --git a/vnt/tun/src/macos/device.rs b/vnt/tun/src/macos/device.rs index 66bcbbc..5b971af 100644 --- a/vnt/tun/src/macos/device.rs +++ b/vnt/tun/src/macos/device.rs @@ -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 { - self.tun.write(buf) + let mut packet = Vec::::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) } }