Skip to content

Compile and test the library on native Windows (+CI leg) - #141

Merged
lance0 merged 3 commits into
lance0:masterfrom
athallajovian9-cyber:windows-compile-tests
Oct 15, 2026
Merged

lance0 merged 3 commits into
lance0:masterfrom
athallajovian9-cyber:windows-compile-tests

Conversation

@athallajovian9-cyber

Copy link
Copy Markdown
Contributor

The library is documented as "Windows (native) | Not supported", and it was: cargo test on a Windows host failed with 25 compile errors and the test binary never linked (pnet's datalink feature demands libpcap's Packet.lib).

This PR makes the library compile, link, and pass its full lib test suite natively on Windows, without touching any unix behavior.

What actually blocked Windows

  1. pnet umbrella crate — only packet parsing is used, but the crate unconditional re-exports pnet_datalink, which links libpcap on Windows. Fix: pnet_base + pnet_packet as direct deps, pnet_datalink moved under [target.'cfg(unix)'.dependencies] (interface.rs's datalink usage is unix-gated with explicit-error Windows arms for validate_interface/bind_socket_to_interface/get_interface_source_ip).
  2. set_dont_fragment had linux/netbsd/macos+freebsd arms — Windows supports both options (IP_DONTFRAGMENT / IPV6_DONTFRAG), implemented via ws2_32 (socket2 does not expose them yet).
  3. set_dscp used socket2::set_tclass_v6 (unix-only API surface) — Windows arm uses IP_TOS / IPV6_TCLASS.
  4. recv_icmp_with_ttl / enable_recv_ttl — cmsg TTL parsing is unix-only; the Windows receive path uses socket2 recv_from with the peer decoded by SocketAddr and reports response_ttl: None until the IPHelper backend lands (callers already treat TTL as optional/best-effort).
  5. --source-ip zone validation — if_nametoindex exists on Windows too, via iphlpapi.dll; implemented instead of the previous "not supported on this platform" refusal.

CI

build-windows job: build + cargo test --lib + cargo clippy --lib -D warnings on windows-latest.

Scope statement

The probe send/receive paths for a native Windows traceroute (IPHelper API instead of raw sockets) are a follow-up, not this PR — this PR is the compile/test/CI foundation that makes that work verifiable.

Proof

  • cargo test --lib on native Windows: 300 passed, 0 failed
  • cargo build (full binary) now links — no Packet.lib
  • Unix behavior untouched: same code paths on unix, no unix file gates loosened;'

@lance0

lance0 commented Oct 15, 2026

Copy link
Copy Markdown
Owner

Hi there thanks for the PR I will take a look as soon as I can.

athallajovian9-cyber and others added 2 commits October 15, 2026 11:41
The suite did not compile on Windows: probe/trace code was unix-only
with no fallback, and the pnet dependency linked libpcap's Packet.lib
through pnet_datalink even though only packet parsing is used.

- probe/socket.rs: real Windows arms for set_dont_fragment
  (IP_DONTFRAGMENT/IPV6_DONTFRAG via ws2_32), set_dscp (IP_TOS and
  IPV6_TCLASS), enable_recv_ttl (best-effort no-op), and
  recv_icmp_with_ttl (socket2 recv_from with the peer decoded by
  SocketAddr; the ancillary TTL arrives with the IPHelper backend)
- probe/rawip.rs: set_ip_hdrincl and raw-socket creation use ws2_32
  IP_HDRINCL on Windows, which supports it natively
- probe/interface.rs: datalink enumeration is unix-only (pcap); Windows
  arms return explicit errors and the datalink tests stay unix-gated
- cli.rs: --source-ip zone resolution uses iphlpapi if_nametoindex on
  Windows instead of refusing the platform
- Cargo.toml: pnet split into pnet_base/pnet_packet (parsing only) with
  pnet_datalink under the unix target - removes the Packet.lib link
  requirement entirely
- ci.yml: build-windows job runs the lib tests and clippy on windows-latest

Proof: cargo test --lib on native Windows = 300 passed, 0 failed; the
full binary now links (no Packet.lib); the unix legs are unchanged.
- Windows Don't Fragment used IP_HDRINCL's value (2) for IPv4 and 42 for
  IPv6; both options are 14. Constants now come from windows-sys, with a
  readback test.
- Windows recv mapped timeouts to a string error, so the receiver counted
  every idle poll as a failure and gave up; io::Error now propagates.
- check_permissions refuses on Windows with a pointer to WSL2 instead of
  falling through to the Linux raw-socket path and setcap advice.
- IP_HDRINCL via socket2's set_header_included_v4 on all platforms;
  IPV6_TCLASS / DF via one windows-sys setsockopt helper (SAFETY noted).
- Drop unused pnet_base; consistent cfg(unix)/cfg(windows) gates; drop
  stubs the shared code already covers; revert unrelated cli.rs changes.
- CI: run the full test suite and clippy --all-targets on Windows.
- CHANGELOG, README platform table, CONTRIBUTING, ROADMAP.
@lance0
lance0 force-pushed the windows-compile-tests branch from 02c5b95 to 5095db8 Compare October 15, 2026 15:45
@lance0
lance0 merged commit 28d0b46 into lance0:master Oct 15, 2026
6 checks passed
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.

2 participants