summaryrefslogtreecommitdiffhomepage
path: root/dhcpv4/server4
diff options
context:
space:
mode:
Diffstat (limited to 'dhcpv4/server4')
-rw-r--r--dhcpv4/server4/server_test.go18
1 files changed, 6 insertions, 12 deletions
diff --git a/dhcpv4/server4/server_test.go b/dhcpv4/server4/server_test.go
index e64be09..da2b199 100644
--- a/dhcpv4/server4/server_test.go
+++ b/dhcpv4/server4/server_test.go
@@ -22,13 +22,6 @@ func init() {
rand.Seed(time.Now().UTC().UnixNano())
}
-func randPort() int {
- // can't use port 0 with raw sockets, so until we implement
- // a non-raw-sockets client for non-static ports, we have to
- // deal with this "randomness"
- return 32*1024 + rand.Intn(65536-32*1024)
-}
-
// DORAHandler is a server handler suitable for DORA transactions
func DORAHandler(conn net.PacketConn, peer net.Addr, m *dhcpv4.DHCPv4) {
if m == nil {
@@ -65,27 +58,28 @@ func DORAHandler(conn net.PacketConn, peer net.Addr, m *dhcpv4.DHCPv4) {
func setUpClientAndServer(t *testing.T, iface net.Interface, handler Handler) (*nclient4.Client, *Server) {
// strong assumption, I know
loAddr := net.ParseIP("127.0.0.1")
- saddr := net.UDPAddr{
+ saddr := &net.UDPAddr{
IP: loAddr,
- Port: randPort(),
+ Port: 0,
}
caddr := net.UDPAddr{
IP: loAddr,
- Port: randPort(),
+ Port: 0,
}
- s, err := NewServer("", &saddr, handler)
+ s, err := NewServer("", saddr, handler)
if err != nil {
t.Fatal(err)
}
go func() {
_ = s.Serve()
}()
+ saddr = s.conn.LocalAddr().(*net.UDPAddr)
clientConn, err := NewIPv4UDPConn("", &caddr)
if err != nil {
t.Fatal(err)
}
- c, err := nclient4.NewWithConn(clientConn, iface.HardwareAddr, nclient4.WithServerAddr(&saddr))
+ c, err := nclient4.NewWithConn(clientConn, iface.HardwareAddr, nclient4.WithServerAddr(saddr))
if err != nil {
t.Fatal(err)
}