mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-22 13:05:36 +03:00
b74b92fc27
Merge in DNS/adguard-home from imp-build-tags to master Squashed commit of the following: commit c15793e04c08097835692568a598b8a8d15f57f4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:25:20 2022 +0300 home: imp build tags commit 2b9b68e9fe6942422951f50d90c70143a3509401 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:23:56 2022 +0300 version: imp build tags commit c0ade3d6ae8885c596fc31312360b25fe992d1e4 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:20:48 2022 +0300 dhcpd: imp build tags commit 0ca2a73b7c3b721400a0cc6383cc9e60f4961f22 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:17:22 2022 +0300 aghos: imp build tags commit 733a685b24b56153b96d59cb97c174ad322ff841 Author: Eugene Burkov <E.Burkov@AdGuard.COM> Date: Tue Sep 13 19:13:11 2022 +0300 aghnet: imp build tags
50 lines
983 B
Go
50 lines
983 B
Go
//go:build freebsd || openbsd
|
|
|
|
package dhcpd
|
|
|
|
import (
|
|
"bytes"
|
|
"net"
|
|
"testing"
|
|
|
|
"github.com/insomniacslk/dhcp/dhcpv4"
|
|
"github.com/stretchr/testify/assert"
|
|
"github.com/stretchr/testify/require"
|
|
)
|
|
|
|
func TestDHCPConn_Broadcast(t *testing.T) {
|
|
b := &bytes.Buffer{}
|
|
var peer *net.UDPAddr
|
|
|
|
udpConn := &fakePacketConn{
|
|
writeTo: func(p []byte, addr net.Addr) (n int, err error) {
|
|
udpPeer, ok := addr.(*net.UDPAddr)
|
|
require.True(t, ok)
|
|
|
|
peer = cloneUDPAddr(udpPeer)
|
|
|
|
n, err = b.Write(p)
|
|
require.NoError(t, err)
|
|
|
|
return n, nil
|
|
},
|
|
}
|
|
conn := &dhcpConn{
|
|
udpConn: udpConn,
|
|
bcastIP: net.IP{1, 2, 3, 255},
|
|
}
|
|
defaultPeer := &net.UDPAddr{
|
|
IP: net.IP{1, 2, 3, 4},
|
|
// Use neither client nor server port.
|
|
Port: 1234,
|
|
}
|
|
respData := (&dhcpv4.DHCPv4{}).ToBytes()
|
|
|
|
_, _ = conn.broadcast(respData, cloneUDPAddr(defaultPeer))
|
|
|
|
assert.EqualValues(t, respData, b.Bytes())
|
|
assert.Equal(t, &net.UDPAddr{
|
|
IP: conn.bcastIP,
|
|
Port: defaultPeer.Port,
|
|
}, peer)
|
|
}
|