diff options
Diffstat (limited to 'dhcpv4')
-rw-r--r-- | dhcpv4/nclient4/client_test.go | 2 | ||||
-rw-r--r-- | dhcpv4/server4/server.go | 17 |
2 files changed, 16 insertions, 3 deletions
diff --git a/dhcpv4/nclient4/client_test.go b/dhcpv4/nclient4/client_test.go index 274c94b..c299697 100644 --- a/dhcpv4/nclient4/client_test.go +++ b/dhcpv4/nclient4/client_test.go @@ -50,7 +50,7 @@ func serveAndClient(ctx context.Context, responses [][]*dhcpv4.DHCPv4, opts ...C panic(err) } - clientConn := NewBroadcastUDPConn(clientRawConn, &net.UDPAddr{IP: net.IPv4zero, Port: ClientPort}) + clientConn := NewBroadcastUDPConn(clientRawConn, &net.UDPAddr{Port: ClientPort}) serverConn := NewBroadcastUDPConn(serverRawConn, &net.UDPAddr{Port: ServerPort}) o := []ClientOpt{WithRetry(1), WithTimeout(2 * time.Second)} diff --git a/dhcpv4/server4/server.go b/dhcpv4/server4/server.go index 3a2aee0..5567bae 100644 --- a/dhcpv4/server4/server.go +++ b/dhcpv4/server4/server.go @@ -90,11 +90,24 @@ func (s *Server) Serve() error { log.Printf("Error parsing DHCPv4 request: %v", err) continue } - go s.Handler(s.conn, peer, m) + + upeer, ok := peer.(*net.UDPAddr) + if !ok { + log.Printf("Not a UDP connection? Peer is %s", peer) + continue + } + // Set peer to broadcast if the client did not have an IP. + if upeer.IP == nil || upeer.IP.Equal(net.IPv4zero) { + upeer = &net.UDPAddr{ + IP: net.IPv4bcast, + Port: upeer.Port, + } + } + go s.Handler(s.conn, upeer, m) } } -// Close sends a termination request to the server, and closes the UDP listener +// Close sends a termination request to the server, and closes the UDP listener. func (s *Server) Close() error { return s.conn.Close() } |