Skip to content

Commit

Permalink
Merge pull request dbus2#587 from zeenix/improv-win32-code
Browse files Browse the repository at this point in the history
🎨 zb,internal: Improve slice handling in win32 code
  • Loading branch information
zeenix authored Feb 12, 2024
2 parents 7e60915 + 4f932a4 commit 25876f3
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions zbus/src/win32.rs
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,13 @@ pub fn socket_addr_get_pid(addr: &SocketAddr) -> Result<u32, Error> {
}

let tcp_table = tcp_table.as_mut_ptr().cast::<MIB_TCPTABLE2>();
let num_entries = unsafe { (*tcp_table).dwNumEntries };
for i in 0..num_entries {
let entry = unsafe { *(*tcp_table).table.as_ptr().add(i as usize) };
let entries = unsafe {
std::slice::from_raw_parts(
(*tcp_table).table.as_ptr(),
(*tcp_table).dwNumEntries as usize,
)
};
for entry in entries {
let port = (entry.dwLocalPort & 0xFFFF) as u16;
let port = u16::from_be(port);

Expand Down

0 comments on commit 25876f3

Please sign in to comment.