diff options
Diffstat (limited to 'src/go/collectors/go.d.plugin/pkg/iprange/pool.go')
-rw-r--r-- | src/go/collectors/go.d.plugin/pkg/iprange/pool.go | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/go/collectors/go.d.plugin/pkg/iprange/pool.go b/src/go/collectors/go.d.plugin/pkg/iprange/pool.go new file mode 100644 index 000000000..48ba5689b --- /dev/null +++ b/src/go/collectors/go.d.plugin/pkg/iprange/pool.go @@ -0,0 +1,40 @@ +// SPDX-License-Identifier: GPL-3.0-or-later + +package iprange + +import ( + "math/big" + "net" + "strings" +) + +// Pool is a collection of IP Ranges. +type Pool []Range + +// String returns the string form of the pool. +func (p Pool) String() string { + var b strings.Builder + for _, r := range p { + b.WriteString(r.String() + " ") + } + return strings.TrimSpace(b.String()) +} + +// Size reports the number of IP addresses in the pool. +func (p Pool) Size() *big.Int { + size := big.NewInt(0) + for _, r := range p { + size.Add(size, r.Size()) + } + return size +} + +// Contains reports whether the pool includes IP. +func (p Pool) Contains(ip net.IP) bool { + for _, r := range p { + if r.Contains(ip) { + return true + } + } + return false +} |