mirror of
https://github.com/AdguardTeam/AdGuardHome.git
synced 2024-11-22 13:05:36 +03:00
+ dhcp: FindIPbyMAC()
This commit is contained in:
parent
3f89335ed2
commit
4bb7b654ab
1 changed files with 13 additions and 0 deletions
|
@ -540,6 +540,19 @@ func (s *Server) printLeases() {
|
|||
}
|
||||
}
|
||||
|
||||
// FindIPbyMAC finds an IP address by MAC address in the currently active DHCP leases
|
||||
func (s *Server) FindIPbyMAC(mac net.HardwareAddr) net.IP {
|
||||
now := time.Now().Unix()
|
||||
s.RLock()
|
||||
defer s.RUnlock()
|
||||
for _, l := range s.leases {
|
||||
if l.Expiry.Unix() > now && bytes.Equal(mac, l.HWAddr) {
|
||||
return l.IP
|
||||
}
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
||||
// Reset internal state
|
||||
func (s *Server) reset() {
|
||||
s.Lock()
|
||||
|
|
Loading…
Reference in a new issue