29 lines
486 B
Go
29 lines
486 B
Go
package iptools
|
|
|
|
import (
|
|
"fmt"
|
|
)
|
|
|
|
func enumerateRange(name string, r *Range, startFromOne bool) []*LeaseInfo {
|
|
start := r.Start
|
|
cur := start
|
|
lenfmt := fmt.Sprintf("%%s%%0%dd", len(fmt.Sprintf("%d", r.numHosts())))
|
|
i := 0
|
|
if startFromOne {
|
|
i++
|
|
}
|
|
leases := []*LeaseInfo{}
|
|
|
|
for r.End.Compare(cur) >= 0 {
|
|
hostName := fmt.Sprintf(lenfmt, name, i)
|
|
leases = append(leases, &LeaseInfo{
|
|
HostName: hostName,
|
|
Addr: cur,
|
|
})
|
|
i++
|
|
cur = cur.Next()
|
|
}
|
|
|
|
return leases
|
|
}
|