Skip to content

Commit 87a7310

Browse files
committed
use GetExtended tables method from windows crate
1 parent c6aae13 commit 87a7310

5 files changed

Lines changed: 14 additions & 45 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ windows = { version = "0.62", features = [
1717
"Win32_Foundation",
1818
"Win32_System_Diagnostics_ToolHelp",
1919
"Win32_System_Threading",
20+
"Win32_NetworkManagement_IpHelper"
2021
] }
2122

2223
[target.'cfg(target_os = "macos")'.dependencies]

src/platform/windows/c_iphlpapi.rs

Lines changed: 0 additions & 27 deletions
This file was deleted.

src/platform/windows/mod.rs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,6 @@ use proto_listener::{PidNamePathCache, ProtoListener, pname_ppath};
44

55
use crate::{Listener, Process, Protocol};
66

7-
mod c_iphlpapi;
87
mod proto_listener;
98
mod socket_table;
109
mod statics;

src/platform/windows/socket_table.rs

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,17 @@
11
use std::ffi::{c_ulong, c_void};
22
use std::net::{IpAddr, Ipv4Addr, Ipv6Addr};
33

4+
use super::statics::UDP_TABLE_OWNER_PID;
45
use crate::Protocol;
5-
use crate::platform::target_os::c_iphlpapi::GetExtendedTcpTable;
66
use crate::platform::target_os::proto_listener::ProtoListener;
7-
use crate::platform::target_os::statics::FALSE;
87
use crate::platform::windows::statics::{
98
AF_INET, AF_INET6, ERROR_INSUFFICIENT_BUFFER, NO_ERROR, TCP_TABLE_OWNER_PID_ALL,
109
};
1110
use crate::platform::windows::tcp_table::TcpTable;
1211
use crate::platform::windows::tcp6_table::Tcp6Table;
1312
use crate::platform::windows::udp_table::UdpTable;
1413
use crate::platform::windows::udp6_table::Udp6Table;
15-
16-
use super::c_iphlpapi::GetExtendedUdpTable;
17-
use super::statics::UDP_TABLE_OWNER_PID;
14+
use windows::Win32::NetworkManagement::IpHelper::{GetExtendedTcpTable, GetExtendedUdpTable};
1815

1916
pub(super) trait SocketTable {
2017
fn get_table() -> crate::Result<Vec<u8>>;
@@ -178,9 +175,9 @@ fn get_udp_table(address_family: c_ulong) -> crate::Result<Vec<u8>> {
178175
let mut table_size: c_ulong = 0;
179176
let mut err_code = unsafe {
180177
GetExtendedUdpTable(
181-
std::ptr::null_mut(),
178+
None,
182179
&raw mut table_size,
183-
FALSE,
180+
false,
184181
address_family,
185182
UDP_TABLE_OWNER_PID,
186183
0,
@@ -192,9 +189,9 @@ fn get_udp_table(address_family: c_ulong) -> crate::Result<Vec<u8>> {
192189
table = Vec::<u8>::with_capacity(table_size as usize);
193190
err_code = unsafe {
194191
GetExtendedUdpTable(
195-
table.as_mut_ptr().cast::<c_void>(),
192+
Some(table.as_mut_ptr().cast::<c_void>()),
196193
&raw mut table_size,
197-
FALSE,
194+
false,
198195
address_family,
199196
UDP_TABLE_OWNER_PID,
200197
0,
@@ -216,9 +213,9 @@ fn get_tcp_table(address_family: c_ulong) -> crate::Result<Vec<u8>> {
216213
let mut table_size: c_ulong = 0;
217214
let mut err_code = unsafe {
218215
GetExtendedTcpTable(
219-
std::ptr::null_mut(),
216+
None,
220217
&raw mut table_size,
221-
FALSE,
218+
false,
222219
address_family,
223220
TCP_TABLE_OWNER_PID_ALL,
224221
0,
@@ -230,9 +227,9 @@ fn get_tcp_table(address_family: c_ulong) -> crate::Result<Vec<u8>> {
230227
table = Vec::<u8>::with_capacity(table_size as usize);
231228
err_code = unsafe {
232229
GetExtendedTcpTable(
233-
table.as_mut_ptr().cast::<c_void>(),
230+
Some(table.as_mut_ptr().cast::<c_void>()),
234231
&raw mut table_size,
235-
FALSE,
232+
false,
236233
address_family,
237234
TCP_TABLE_OWNER_PID_ALL,
238235
0,

src/platform/windows/statics.rs

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
use std::ffi::{c_int, c_ulong};
2+
use windows::Win32::NetworkManegement::IpHelper::{TCP_TABLE_CLASS, UDP_TABLE_CLASS};
23

3-
pub(super) const TCP_TABLE_OWNER_PID_ALL: c_ulong = 5;
4-
pub(super) const UDP_TABLE_OWNER_PID: c_ulong = 1;
5-
pub(super) const FALSE: c_int = 0;
4+
pub(super) const TCP_TABLE_OWNER_PID_ALL: TCP_TABLE_CLASS = TCP_TABLE_CLASS(5);
5+
pub(super) const UDP_TABLE_OWNER_PID: UDP_TABLE_CLASS = UDP_TABLE_CLASS(1);
66
pub(super) const ERROR_INSUFFICIENT_BUFFER: c_ulong = 0x7A;
77
pub(super) const NO_ERROR: c_ulong = 0;
88
pub(super) const AF_INET: c_ulong = 2;
99
pub(super) const AF_INET6: c_ulong = 23;
10-
// pub(super) const LISTEN: c_ulong = 2;

0 commit comments

Comments
 (0)