Skip to content
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ futures = { version = "0.3", optional = true }
gat-std = { version = "0.1.1", optional = true }

[target.'cfg(target_os = "windows")'.dependencies]
windows-sys = { version = "0.36.1", features = ["Win32_Foundation", "Win32_Networking_WinSock"] }
windows-sys = { version = "0.59.0", features = ["Win32_Foundation", "Win32_Networking_WinSock"] }

[dev-dependencies]
etherparse = "0.13.0"
Expand All @@ -32,7 +32,7 @@ tempfile = "3.10"

[target.'cfg(target_os = "windows")'.dev-dependencies]
eui48 = { version = "1.1", default-features = false }
windows-sys = { version = "0.36.1", features = ["Win32_System_Threading"] }
windows-sys = { version = "0.59.0", features = ["Win32_System_Threading"] }

[target.'cfg(not(target_os = "windows"))'.dev-dependencies]
tun-tap = "0.1.3"
Expand Down
4 changes: 2 additions & 2 deletions src/capture/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -282,10 +282,10 @@ mod tests {
let ctx = raw::pcap_getevent_context();
ctx.expect()
.withf_st(move |arg1| *arg1 == pcap)
.return_once(|_| 5);
.return_once(|_| 5 as *mut std::ffi::c_void);

let handle = unsafe { capture.get_event() };
assert_eq!(handle, 5);
assert_eq!(handle, 5 as *mut std::ffi::c_void);
}

#[test]
Expand Down
6 changes: 3 additions & 3 deletions src/device.rs
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ impl Address {
return None;
}

match (*ptr).sa_family as u32 {
match (*ptr).sa_family {
WinSock::AF_INET => {
let ptr: *const WinSock::SOCKADDR_IN = std::mem::transmute(ptr);
let addr: [u8; 4] = ((*ptr).sin_addr.S_un.S_addr).to_ne_bytes();
Expand Down Expand Up @@ -372,7 +372,7 @@ mod tests {
fn new() -> Self {
let mut addr: Self = unsafe { std::mem::zeroed() };
// The cast is only necessary due to a bug in windows_sys@v0.36.1
addr.sin_family = WinSock::AF_INET as u16;
addr.sin_family = WinSock::AF_INET;
addr
}

Expand Down Expand Up @@ -418,7 +418,7 @@ mod tests {
fn new() -> Self {
let mut addr: Self = unsafe { std::mem::zeroed() };
// The cast is only necessary due to a bug in windows_sys@v0.36.1
addr.sin6_family = WinSock::AF_INET6 as u16;
addr.sin6_family = WinSock::AF_INET6;
unsafe {
addr.sin6_addr.u.Byte[0] = 0xFE;
addr.sin6_addr.u.Byte[1] = 0x80;
Expand Down
15 changes: 13 additions & 2 deletions src/stream/windows.rs
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,16 @@ struct EventHandle {
state: EventHandleState,
}

// SAFETY: EventHandle is Send automatically if not for HANDLE, which is a [non-autotrait'ed] pointer since windows-sys was updated to 0.59.
Comment thread
qrnch-jan marked this conversation as resolved.
Outdated
// The capture device owns the original handle,
// As long as the capture device isn't released before the EventHandle, this should be good.
unsafe impl Send for EventHandle {}

/// Newtype used to wrap `HANDLE` to make it `Send`:able
struct InternalHandle(HANDLE);

unsafe impl Send for InternalHandle {}

enum EventHandleState {
/// We haven't started waiting for an event yet.
Init,
Expand All @@ -98,12 +108,13 @@ impl EventHandle {
loop {
match self.state {
EventHandleState::Init => {
let handle = self.handle;
let handle = InternalHandle(self.handle);
self.state =
EventHandleState::Polling(tokio::task::spawn_blocking(move || {
const INFINITE: u32 = !0;
let handle = handle; // avoid partial closure capture problems
unsafe {
WaitForSingleObject(handle, INFINITE);
WaitForSingleObject(handle.0, INFINITE);
}
}));
}
Expand Down