Skip to content

Add Windows support#4

Merged
ibigbug merged 5 commits intomasterfrom
copilot/add-windows-support
Nov 6, 2025
Merged

Add Windows support#4
ibigbug merged 5 commits intomasterfrom
copilot/add-windows-support

Conversation

Copy link
Contributor

Copilot AI commented Nov 6, 2025

Closes #[issue_number]

Implements socket-to-process resolution for Windows using IP Helper API.

Implementation

Core API Integration:

  • GetExtendedTcpTable / GetExtendedUdpTable enumerate connections with PIDs (IPv4/IPv6, TCP/UDP)
  • QueryFullProcessImageNameW retrieves process executable paths
  • Network byte order conversion (u32::from_be, u16::from_be) per Windows API spec

Platform Module:

  • Added src/platform/windows.rs (387 lines)
  • Conditional compilation in src/platform/mod.rs
  • windows-sys = "0.52" with Win32 IpHelper, Threading, WinSock features

CI:

  • Added windows-latest to test matrix

Tradeoffs

Windows UDP tables lack remote address/port fields—destination matching unsupported for UDP (API limitation, not implementation choice).

Example

use sock2proc::{find_process_name, NetworkProtocol};
use std::net::SocketAddr;

let addr = "192.168.1.100:8080".parse::<SocketAddr>().unwrap();
let process = find_process_name(Some(addr), None, NetworkProtocol::TCP);
// Returns process path on Windows, Linux, and macOS
Original prompt

This section details on the original issue you should resolve

<issue_title>windows support</issue_title>
<issue_description></issue_description>

<agent_instructions>implement windows support and add tests</agent_instructions>

Comments on the Issue (you are @copilot in this section)


✨ Let Copilot coding agent set things up for you — coding agent works faster and does higher quality work when set up for your repo.

Copilot AI and others added 4 commits November 6, 2025 16:07
Co-authored-by: ibigbug <543405+ibigbug@users.noreply.github.com>
Co-authored-by: ibigbug <543405+ibigbug@users.noreply.github.com>
Co-authored-by: ibigbug <543405+ibigbug@users.noreply.github.com>
…ATH constant

Co-authored-by: ibigbug <543405+ibigbug@users.noreply.github.com>
Copilot AI changed the title [WIP] Implement Windows support and add tests Add Windows support Nov 6, 2025
Copilot AI requested a review from ibigbug November 6, 2025 16:21
@ibigbug ibigbug marked this pull request as ready for review November 6, 2025 16:22
@ibigbug ibigbug requested a review from Copilot November 6, 2025 16:22
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR implements Windows support for socket-to-process resolution using the Windows IP Helper API, enabling the library to work cross-platform on Linux, macOS, and Windows.

Key Changes:

  • Added Windows-specific implementation using GetExtendedTcpTable/GetExtendedUdpTable APIs for IPv4/IPv6 TCP/UDP connection enumeration
  • Integrated process path retrieval via QueryFullProcessImageNameW
  • Extended CI pipeline to include Windows testing

Reviewed Changes

Copilot reviewed 4 out of 5 changed files in this pull request and generated 9 comments.

File Description
src/platform/windows.rs Core Windows implementation with TCP/UDP v4/v6 socket-to-PID resolution and process path lookup
src/platform/mod.rs Conditional compilation directives to include Windows platform module
Cargo.toml Added windows-sys dependency with required Win32 API features
.github/workflows/rust.yml Added windows-latest to CI test matrix

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

dst: Option<SocketAddr>,
) -> Result<u32, io::Error> {
let mut size: u32 = 0;

Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on line 67. Remove the extra spaces for consistency with coding standards.

Suggested change

Copilot uses AI. Check for mistakes.
// Parse the table
let table = unsafe { &*(buffer.as_ptr() as *const MIB_TCPTABLE_OWNER_PID) };
let num_entries = table.dwNumEntries as usize;

Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on line 104. Remove the extra spaces for consistency with coding standards.

Suggested change

Copilot uses AI. Check for mistakes.
dst: Option<SocketAddr>,
) -> Result<u32, io::Error> {
let mut size: u32 = 0;

Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on line 144. Remove the extra spaces for consistency with coding standards.

Suggested change

Copilot uses AI. Check for mistakes.
// Parse the table
let table = unsafe { &*(buffer.as_ptr() as *const MIB_TCP6TABLE_OWNER_PID) };
let num_entries = table.dwNumEntries as usize;

Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on line 181. Remove the extra spaces for consistency with coding standards.

Suggested change

Copilot uses AI. Check for mistakes.
dst: Option<SocketAddr>,
) -> Result<u32, io::Error> {
let mut size: u32 = 0;

Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on line 221. Remove the extra spaces for consistency with coding standards.

Suggested change

Copilot uses AI. Check for mistakes.
// Parse the table
let table = unsafe { &*(buffer.as_ptr() as *const MIB_UDPTABLE_OWNER_PID) };
let num_entries = table.dwNumEntries as usize;

Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on line 258. Remove the extra spaces for consistency with coding standards.

Suggested change

Copilot uses AI. Check for mistakes.
dst: Option<SocketAddr>,
) -> Result<u32, io::Error> {
let mut size: u32 = 0;

Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on line 295. Remove the extra spaces for consistency with coding standards.

Suggested change

Copilot uses AI. Check for mistakes.
// Parse the table
let table = unsafe { &*(buffer.as_ptr() as *const MIB_UDP6TABLE_OWNER_PID) };
let num_entries = table.dwNumEntries as usize;

Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on line 332. Remove the extra spaces for consistency with coding standards.

Suggested change

Copilot uses AI. Check for mistakes.
let mut size = buffer.len() as u32;

let result = QueryFullProcessImageNameW(handle, 0, buffer.as_mut_ptr(), &mut size);

Copy link

Copilot AI Nov 6, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trailing whitespace on line 375. Remove the extra spaces for consistency with coding standards.

Suggested change

Copilot uses AI. Check for mistakes.
@ibigbug ibigbug merged commit 9f9e630 into master Nov 6, 2025
6 checks passed
@ibigbug ibigbug deleted the copilot/add-windows-support branch November 6, 2025 16:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

windows support

2 participants