Skip to content

Commit b14a80e

Browse files
authored
Merge pull request #33 from r2d4/leases
Use last entry when parsing DHCP status file
2 parents dc9207e + e5724f2 commit b14a80e

File tree

1 file changed

+8
-3
lines changed

1 file changed

+8
-3
lines changed

kvm.go

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -638,13 +638,18 @@ func (d *Driver) getIPByMacFromSettings(mac string) (string, error) {
638638
log.Warnf("Failed to decode dnsmasq lease status: %s", err)
639639
return "", err
640640
}
641+
ipAddr := ""
641642
for _, value := range s {
642643
if strings.ToLower(value.Mac_address) == strings.ToLower(mac) {
643-
log.Debugf("IP address: %s", value.Ip_address)
644-
return value.Ip_address, nil
644+
// If there are multiple entries,
645+
// the last one is the most current
646+
ipAddr = value.Ip_address
645647
}
646648
}
647-
return "", nil
649+
if ipAddr != "" {
650+
log.Debugf("IP address: %s", ipAddr)
651+
}
652+
return ipAddr, nil
648653
}
649654

650655
func (d *Driver) GetIP() (string, error) {

0 commit comments

Comments
 (0)