fix windows's read tun, fill first 14 bytes with 0's
This commit is contained in:
parent
97a7403015
commit
150d1c8e67
2
.vscode/settings.json
vendored
2
.vscode/settings.json
vendored
@ -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"]
|
||||
}
|
||||
@ -30,6 +30,9 @@ use sdlan_sn_rs::{
|
||||
utils::{create_or_load_uuid, get_sdlan_sock_from_socketaddr, Result, SDLanError},
|
||||
};
|
||||
|
||||
#[cfg(all(feature = "tun", target_os = "windows"))]
|
||||
compile_error!("tun feature is not supported on windows");
|
||||
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum ConnectionInfo {
|
||||
|
||||
@ -255,7 +255,7 @@ async fn loop_tap(eee: &'static Node, cancel: CancellationToken) {
|
||||
error!("loop_tap exited");
|
||||
}
|
||||
|
||||
#[cfg(feature = "tun")]
|
||||
#[cfg(any(feature = "tun", target_os = "windows"))]
|
||||
fn get_data_from_tun_with_layer2_zeroed(eee: &Node) -> BytesMut {
|
||||
let mut temp = BytesMut::zeroed(1514);
|
||||
// let mut temp = BytesMut::with_capacity(1514);
|
||||
@ -282,9 +282,9 @@ fn get_data_from_tap_with_layer2(eee: &Node) -> BytesMut {
|
||||
async fn get_tun_flow(eee: &'static Node, tx: Sender<BytesMut>) {
|
||||
loop {
|
||||
let buf = tokio::task::spawn_blocking(|| {
|
||||
#[cfg(feature = "tun")]
|
||||
#[cfg(any(feature = "tun", target_os = "windows"))]
|
||||
let data = get_data_from_tun_with_layer2_zeroed(eee);
|
||||
#[cfg(not(feature = "tun"))]
|
||||
#[cfg(all(not(feature = "tun"), not(target_os="windows")))]
|
||||
let data = get_data_from_tap_with_layer2(eee);
|
||||
|
||||
data
|
||||
|
||||
@ -328,7 +328,7 @@ impl TunTapPacketHandler for Iface {
|
||||
|
||||
if u32::from_be_bytes(ipv4.destination) == DNS_IP {
|
||||
// should send to dns
|
||||
parse_dns_payload(edge, &headers.payload);
|
||||
parse_dns_payload(edge, &headers.payload.slice());
|
||||
if let Err(e) = edge.udp_sock_for_dns.send_to(&data[14..], format!("{}:15353", edge.server_ip)).await {
|
||||
error!("failed to send request to 15353: {}", e);
|
||||
}
|
||||
@ -1029,18 +1029,5 @@ pub async fn arp_reply_arrived(edge: &Node, data: SdlArpResponse) {
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
fn parse_dns_payload(edge: &Node, payload: &[u8]) {
|
||||
match dns_parse::parse(Bytes::from(payload)) {
|
||||
Ok(packet) => {
|
||||
packet[0].
|
||||
if let Some(questions) = packet.questions.first() {
|
||||
debug!("got dns query for {:?}", questions.qname);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
error!("failed to parse dns packet: {}", e.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
Loading…
x
Reference in New Issue
Block a user