Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support Windows #521

Open
QQ2017 opened this issue Jan 18, 2024 · 3 comments
Open

Support Windows #521

QQ2017 opened this issue Jan 18, 2024 · 3 comments

Comments

@QQ2017
Copy link

QQ2017 commented Jan 18, 2024

The DHCP4 server prompts "not implemented on Windows" when running on Windows system. Can it support Windows? Thanks

@pmazzini
Copy link
Collaborator

It looks to be a dup of #497

@QQ2017
Copy link
Author

QQ2017 commented Feb 11, 2024

@pmazzini
Hello, here is the code of \dhcpv4\server4\conn_windows.go

// +build windows

package server4

import (
	"fmt"
	"net"
)

// NewIPv4UDPConn returns a UDP connection bound to both the interface and port
// given based on a IPv4 UDP socket. The UDP connection allows broadcasting.
func NewIPv4UDPConn(iface string, addr *net.UDPAddr) (*net.UDPConn, error) {
	// For Windows, we use the ListenPacket method to create a UDP connection.
	// This method automatically handles socket creation and configuration.
	laddr := net.UDPAddr{
		IP:   net.IPv4zero, // Use IPv4zero for listening on all interfaces.
		Port: addr.Port,
	}
	conn, err := net.ListenPacket("udp4", laddr.String())
	if err != nil {
		return nil, fmt.Errorf("cannot create UDP listener: %v", err)
	}
	udpConn, ok := conn.(*net.UDPConn)
	if !ok {
		return nil, fmt.Errorf("incorrect connection type: %T, expected *net.UDPConn", conn)
	}
	// On Windows, binding to a specific interface is not as straightforward
	// as on Unix-based systems. It might require additional steps or be
	// managed differently depending on the use case and network configuration.
	// Setting socket options like SO_BROADCAST is not directly exposed in the
	// net package, but the ListenPacket should create a socket that is
	// capable of broadcasting by default.
	return udpConn, nil
}

@pmazzini
Copy link
Collaborator

Can you create a pull request?

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

No branches or pull requests

2 participants