Skip to content

Commit

Permalink
Basic windows listening
Browse files Browse the repository at this point in the history
A very basic implementation of listening UDP connections in Windows.

It is based on

#521 (comment)

It works good enough. There is probably something missing, but a windows
binary using it is capable at listening.

Signed-off-by: Gonzalo Fernandez-Victorio <[email protected]>
  • Loading branch information
gonfva committed Nov 30, 2024
1 parent a3a4c1f commit 8aeff6e
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions dhcpv4/server4/conn_windows.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
//go:build windows

package server4

import (
"errors"
"fmt"
"net"
)

// NewIPv4UDPConn fails on Windows. Use WithConn() to pass the connection.
// NewIPv4UDPConn returns an UDPv4 connection bound to the IP and port provider
func NewIPv4UDPConn(iface string, addr *net.UDPAddr) (*net.UDPConn, error) {
return nil, errors.New("not implemented on Windows")
connection, err := net.ListenPacket("udp4", addr.String())
if err != nil {
return nil, fmt.Errorf("We cannot listen on %s and port %d: %v", addr.IP, addr.Port, err)
}
udpConn, ok := connection.(*net.UDPConn)
if !ok {
return nil, fmt.Errorf("The connection is not of the proper type")
}
return udpConn, nil
}

0 comments on commit 8aeff6e

Please sign in to comment.