dhcpd: fixed a bug in discovery

This commit is contained in:
nadoo committed 2022-02-24 18:41:03 +08:00
1 parent c261e5989c
commit 9f6e5ebb98
14 files changed
+188 -129

No files matched your search

+5 -10
View File
@@ -11,16 +11,15 @@ import (
)
func discovery(intf *net.Interface) (found bool) {
lc := &net.ListenConfig{}
lc.Control = sockopt.BindControl(intf)
lc := &net.ListenConfig{Control: sockopt.Control(sockopt.Bind(intf), sockopt.ReuseAddr())}
pc, err := lc.ListenPacket(context.Background(), "udp4", "255.255.255.255:68")
pc, err := lc.ListenPacket(context.Background(), "udp4", ":68")
if err != nil {
return
}
defer pc.Close()
discovery, err := dhcpv4.NewDiscovery(intf.HardwareAddr, dhcpv4.WithBroadcast(true))
discovery, err := dhcpv4.NewDiscovery(intf.HardwareAddr, dhcpv4.WithBroadcast(true), dhcpv4.WithRequestedOptions(dhcpv4.OptionDomainNameServer))
if err != nil {
return
}
@@ -37,10 +36,6 @@ func discovery(intf *net.Interface) (found bool) {
return
}
msg, err := dhcpv4.FromBytes(buf[:n])
if err != nil || msg.TransactionID != discovery.TransactionID {
return
}
return true
_, err = dhcpv4.FromBytes(buf[:n])
return err == nil
}