You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

29 lines
475 B

package common
import ipa "inet.af/netaddr"
func RangeIterate(ips interface{}) chan *ipa.IP {
var addrs ipa.IPRange
switch ips.(type) {
case ipa.IPRange:
addrs = ips.(ipa.IPRange)
case ipa.IPPrefix:
addrs = ips.(ipa.IPPrefix).Range()
}
ch := make(chan *ipa.IP)
go func() {
var head ipa.IP
head = addrs.From()
end := addrs.To()
for head != end {
if !head.IsUnspecified() {
ch <- &head
}
head = head.Next()
}
close(ch)
}()
return ch
}