blob: 48ba5689bf5c777d37b5ccdaa745b14001fd0732 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
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
}
|