github.com/netdata/go.d.plugin@v0.58.1/pkg/iprange/pool.go (about) 1 // SPDX-License-Identifier: GPL-3.0-or-later 2 3 package iprange 4 5 import ( 6 "math/big" 7 "net" 8 "strings" 9 ) 10 11 // Pool is a collection of IP Ranges. 12 type Pool []Range 13 14 // String returns the string form of the pool. 15 func (p Pool) String() string { 16 var b strings.Builder 17 for _, r := range p { 18 b.WriteString(r.String() + " ") 19 } 20 return strings.TrimSpace(b.String()) 21 } 22 23 // Size reports the number of IP addresses in the pool. 24 func (p Pool) Size() *big.Int { 25 size := big.NewInt(0) 26 for _, r := range p { 27 size.Add(size, r.Size()) 28 } 29 return size 30 } 31 32 // Contains reports whether the pool includes IP. 33 func (p Pool) Contains(ip net.IP) bool { 34 for _, r := range p { 35 if r.Contains(ip) { 36 return true 37 } 38 } 39 return false 40 }