Skip to content

Commit 2583500

Browse files
committed
Remove old windows traceroute impl
1 parent 809c13b commit 2583500

File tree

1 file changed

+0
-137
lines changed

1 file changed

+0
-137
lines changed

mullvad-leak-checker/src/traceroute/windows.rs

-137
Original file line numberDiff line numberDiff line change
@@ -102,140 +102,3 @@ pub async fn traceroute_using_ping(opt: &TracerouteOpt) -> anyhow::Result<LeakSt
102102
result = wait_for_first_leak.fuse() => result,
103103
}
104104
}
105-
106-
// TODO: remove this
107-
/*
108-
use std::{
109-
ffi::c_void,
110-
io, mem,
111-
net::{IpAddr, SocketAddr},
112-
os::windows::io::{AsRawSocket, AsSocket, FromRawSocket, IntoRawSocket},
113-
ptr::null_mut,
114-
str,
115-
};
116-
117-
use anyhow::{anyhow, bail, Context};
118-
use futures::{select, stream::FuturesUnordered, FutureExt, StreamExt};
119-
use socket2::Socket;
120-
use talpid_windows::net::{get_ip_address_for_interface, luid_from_alias, AddressFamily};
121-
122-
use tokio::time::sleep;
123-
use windows_sys::Win32::Networking::WinSock::{
124-
WSAGetLastError, WSAIoctl, SIO_RCVALL, SOCKET, SOCKET_ERROR,
125-
};
126-
127-
use crate::{
128-
traceroute::{
129-
Ip, TracerouteOpt, DEFAULT_TTL_RANGE, LEAK_TIMEOUT, PROBE_INTERVAL, SEND_TIMEOUT,
130-
},
131-
Interface, LeakInfo, LeakStatus,
132-
};
133-
use super::{common, AsyncIcmpSocket, AsyncUdpSocket, Traceroute};
134-
135-
pub struct TracerouteWindows;
136-
137-
pub struct AsyncIcmpSocketImpl(tokio::net::UdpSocket);
138-
139-
pub struct AsyncUdpSocketWindows(tokio::net::UdpSocket);
140-
141-
impl Traceroute for TracerouteWindows {
142-
type AsyncIcmpSocket = AsyncIcmpSocketImpl;
143-
type AsyncUdpSocket = AsyncUdpSocketWindows;
144-
145-
fn bind_socket_to_interface(
146-
socket: &Socket,
147-
interface: &Interface,
148-
ip_version: Ip,
149-
) -> anyhow::Result<()> {
150-
common::bind_socket_to_interface::<Self>(socket, interface, ip_version)
151-
}
152-
153-
fn get_interface_ip(interface: &Interface, ip_version: Ip) -> anyhow::Result<IpAddr> {
154-
get_interface_ip(interface, ip_version)
155-
}
156-
157-
fn configure_icmp_socket(socket: &socket2::Socket, _opt: &TracerouteOpt) -> anyhow::Result<()> {
158-
configure_icmp_socket(socket)
159-
}
160-
}
161-
162-
impl AsyncIcmpSocket for AsyncIcmpSocketImpl {
163-
fn from_socket2(socket: Socket) -> Self {
164-
let raw_socket = socket.as_socket().as_raw_socket();
165-
mem::forget(socket);
166-
let std_socket = unsafe { std::net::UdpSocket::from_raw_socket(raw_socket) };
167-
let tokio_socket = tokio::net::UdpSocket::from_std(std_socket).unwrap();
168-
AsyncIcmpSocketImpl(tokio_socket)
169-
}
170-
171-
fn set_ttl(&self, ttl: u32) -> anyhow::Result<()> {
172-
self.0
173-
.set_ttl(ttl)
174-
.context("Failed to set TTL value for ICMP socket")
175-
}
176-
177-
async fn send_to(&self, packet: &[u8], destination: impl Into<IpAddr>) -> io::Result<usize> {
178-
self.0.send_to(packet, (destination.into(), 0)).await
179-
}
180-
181-
async fn recv_from(&self, buf: &mut [u8]) -> io::Result<(usize, std::net::IpAddr)> {
182-
let (n, source) = self.0.recv_from(buf).await?;
183-
Ok((n, source.ip()))
184-
}
185-
186-
async fn recv_ttl_responses(&self, opt: &TracerouteOpt) -> anyhow::Result<LeakStatus> {
187-
common::recv_ttl_responses(self, &opt.interface).await
188-
}
189-
}
190-
191-
impl AsyncUdpSocket for AsyncUdpSocketWindows {
192-
fn from_socket2(socket: socket2::Socket) -> Self {
193-
// HACK: Wrap the socket in a tokio::net::UdpSocket to be able to use it async
194-
let udp_socket = unsafe { std::net::UdpSocket::from_raw_socket(socket.into_raw_socket()) };
195-
let udp_socket = tokio::net::UdpSocket::from_std(udp_socket).unwrap();
196-
AsyncUdpSocketWindows(udp_socket)
197-
}
198-
199-
fn set_ttl(&self, ttl: u32) -> anyhow::Result<()> {
200-
self.0
201-
.set_ttl(ttl)
202-
.context("Failed to set TTL value for UDP socket")
203-
}
204-
205-
async fn send_to(
206-
&self,
207-
packet: &[u8],
208-
destination: impl Into<SocketAddr>,
209-
) -> std::io::Result<usize> {
210-
self.0.send_to(packet, destination.into()).await
211-
}
212-
}
213-
214-
/// Configure the raw socket we use for listening to ICMP responses.
215-
///
216-
/// This will set the `SIO_RCVALL`-option.
217-
pub fn configure_icmp_socket(socket: &Socket) -> anyhow::Result<()> {
218-
let j = 1;
219-
let mut _in: u32 = 0;
220-
let result = unsafe {
221-
WSAIoctl(
222-
socket.as_raw_socket() as SOCKET,
223-
SIO_RCVALL,
224-
&j as *const _ as *const c_void,
225-
size_of_val(&j) as u32,
226-
null_mut(),
227-
0,
228-
&mut _in as *mut u32,
229-
null_mut(),
230-
None,
231-
)
232-
};
233-
234-
if result == SOCKET_ERROR {
235-
let code = unsafe { WSAGetLastError() };
236-
bail!("Failed to call WSAIoctl(listen_socket, SIO_RCVALL, ...), code = {code}");
237-
}
238-
239-
Ok(())
240-
}
241-
*/

0 commit comments

Comments
 (0)