win's tun, linux's tap and tun, are all ok

This commit is contained in:
alex 2025-12-24 23:49:39 +08:00
parent b36f526cfc
commit 43c2b01fca
3 changed files with 7 additions and 5 deletions

View File

@ -1,4 +1,4 @@
{
"rust-analyzer.cargo.target": "x86_64-pc-windows-gnu"
// "rust-analyzer.cargo.target": "x86_64-pc-windows-gnu"
// "rust-analyzer.cargo.features": ["tun"]
}

View File

@ -29,6 +29,7 @@ use super::TunTapPacketHandler;
const RESOLV_FILE: &'static str = "/etc/resolv.conf";
const RESOLV_FILE_BACKUP: &'static str = "/etc/resolv.conf.punchnet.bak";
use crate::network::DNS_IP;
// #[link(name = "tuntap", kind="static")]
#[link(name = "tuntap")]
@ -223,6 +224,7 @@ impl TunTapPacketHandler for Iface {
if let Some(ip) = headers.net {
match ip {
etherparse::NetHeaders::Ipv4(ipv4, _) => {
if u32::from_be_bytes(ipv4.destination) == DNS_IP {
// should send to dns
if let Err(e) = edge.udp_sock_for_dns.send_to(&data[14..], format!("{}:15353", edge.server_ip)).await {
@ -476,9 +478,9 @@ impl TunTapPacketHandler for Iface {
}
if dstip == DNS_IP {
// should do the dns request
println!("request for dns");
// println!("request for dns");
let addr = format!("{}:15353", eee.server_ip);
println!("send dns to {}", addr);
// println!("send dns to {}", addr);
if let Err(e) = eee.udp_sock_for_dns.send_to(&data, &addr).await {
error!("failed to send request to 15353: {}", e);
}

View File

@ -309,9 +309,9 @@ impl TunTapPacketHandler for Iface {
return Ok(());
}
if dstip == DNS_IP {
println!("request for dns");
// println!("request for dns");
let addr = format!("{}:15353", eee.server_ip);
println!("send dns to {}", addr);
// println!("send dns to {}", addr);
if let Err(e) = eee.udp_sock_for_dns.send_to(&data, &addr).await {
error!("failed to send request to 15353: {}", e);
}