Skip to content

Commit

Permalink
feat: add support for Windows (#98)
Browse files Browse the repository at this point in the history
  • Loading branch information
zarkdav authored and fujiapple852 committed Dec 31, 2022
1 parent 38e37f3 commit 4e949bd
Show file tree
Hide file tree
Showing 3 changed files with 742 additions and 131 deletions.
15 changes: 15 additions & 0 deletions src/tracing/net/ipv4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -181,6 +181,7 @@ pub fn dispatch_tcp_probe(
Ok(socket)
}

#[cfg(unix)]
pub fn recv_icmp_probe(
recv_socket: &mut Socket,
protocol: TracerProtocol,
Expand All @@ -205,6 +206,20 @@ pub fn recv_icmp_probe(
}
}

#[cfg(windows)]
pub fn recv_icmp_probe(
recv_socket: &mut Socket,
protocol: TracerProtocol,
multipath_strategy: MultipathStrategy,
direction: PortDirection,
) -> TraceResult<Option<ProbeResponse>> {
let bytes = &recv_socket.buf_bytes();
let ipv4 = Ipv4Packet::new_view(bytes).req()?;
// post the WSARecvFrom again, so that the next OVERLAPPED event can get triggered
recv_socket.recv_from()?;
extract_probe_resp(protocol, multipath_strategy, direction, &ipv4)
}

pub fn recv_tcp_socket(
tcp_socket: &Socket,
sequence: Sequence,
Expand Down
20 changes: 20 additions & 0 deletions src/tracing/net/ipv6.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ pub fn dispatch_tcp_probe(
Ok(socket)
}

#[cfg(unix)]
pub fn recv_icmp_probe(
recv_socket: &mut Socket,
protocol: TracerProtocol,
Expand All @@ -161,6 +162,25 @@ pub fn recv_icmp_probe(
}
}

#[cfg(windows)]
#[allow(unsafe_code)]
pub fn recv_icmp_probe(
recv_socket: &mut Socket,
protocol: TracerProtocol,
direction: PortDirection,
) -> TraceResult<Option<ProbeResponse>> {
let bytes = &recv_socket.buf_bytes();
let icmp_v6 = IcmpPacket::new_view(bytes).req()?;
let addr = recv_socket.from()?;
// post the WSARecvFrom again, so that the next OVERLAPPED event can get triggered
recv_socket.recv_from()?;
if let IpAddr::V6(src_addr) = addr {
extract_probe_resp(protocol, direction, &icmp_v6, src_addr)
} else {
Err(TracerError::InvalidSourceAddr(addr))
}
}

pub fn recv_tcp_socket(
tcp_socket: &Socket,
sequence: Sequence,
Expand Down
Loading

0 comments on commit 4e949bd

Please sign in to comment.