Skip to content

Conversation

@QQ2017
Copy link

@QQ2017 QQ2017 commented Dec 19, 2025

Description
This PR adds Windows platform support for the DHCPv4 client packages (client4 and nclient4), as well as necessary supporting changes to xsocket, netboot, and interfaces packages.

Background
The library previously relied heavily on Unix-specific APIs (AF_PACKET, SOCK_RAW, unix.Socket, SO_BINDTODEVICE, etc.) which are not available on Windows. This prevented the library from being compiled or used on Windows.

Changes

  1. internal/xsocket
    Added //go:build !windows constraint to existing Unix files
    Created xsocket_windows.go with stub implementation
  2. dhcpv4/client4
    Added //go:build !windows constraint to client.go
    Created client_windows.go using standard net.ListenUDP for DHCP exchange
  3. dhcpv4/nclient4
    Created conn_windows.go using standard net.ListenUDP
  4. netboot
    Added //go:build !windows constraint to netconf.go
    Created netconf_windows.go with:
    Full implementation of GetNetConfFromPacketv4 and GetNetConfFromPacketv6
    IfUp using net.InterfaceByName
    ConfigureInterface stub (returning error, as this requires Windows-specific APIs)
  5. interfaces
    Modified bindtodevice_windows.go to return nil (no-op) instead of an error, since Windows implementation uses transaction ID filtering rather than interface binding

Technical Notes
Important: The Windows implementation uses standard UDP sockets (net.ListenUDP) instead of raw sockets with ipv4.PacketConn.SetControlMessage, because SetControlMessage is not implemented on Windows in the golang.org/x/net/ipv4 package.

This means:

The client listens on all interfaces (binding to 0.0.0.0)
Responses are filtered by Transaction ID (which is the standard DHCP behavior)
This is functionally correct for most use cases

Testing
Tested on Windows 10/11 with DHCPv4:

✅ Compilation successful
✅ DORA exchange (Discover → Offer → Request → Ack) works correctly
✅ IP address obtained from DHCP server
Attempt 1 of 4
DISCOVER → server
OFFER ← 10.180.2.11
REQUEST → server
ACK ← 10.180.2.11 ✅

Compatibility
No breaking changes for existing Unix/Linux/macOS users
All existing tests should continue to pass on Unix platforms
server4 already had Windows support (conn_windows.go), so no changes needed there

Related
Fixes compilation on Windows
Enables DHCPv4 client usage on Windows without external dependencies (no Npcap/WinPcap required)

Signed-off-by: QQ2017 [email protected]

@QQ2017 QQ2017 marked this pull request as draft December 19, 2025 09:13
@QQ2017 QQ2017 marked this pull request as ready for review December 19, 2025 09:13
@QQ2017
Copy link
Author

QQ2017 commented Dec 19, 2025

@pmazzini
Help me review this PR

@QQ2017
Copy link
Author

QQ2017 commented Dec 24, 2025

@insomniacslk

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.

1 participant