+ dhcp: FindIPbyMAC()
This commit is contained in:
parent
3f89335ed2
commit
4bb7b654ab
|
@ -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
|
// Reset internal state
|
||||||
func (s *Server) reset() {
|
func (s *Server) reset() {
|
||||||
s.Lock()
|
s.Lock()
|
||||||
|
|
Loading…
Reference in New Issue