-
Notifications
You must be signed in to change notification settings - Fork 3
/
v6.go
44 lines (35 loc) · 811 Bytes
/
v6.go
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
41
42
43
44
package cidr
import (
"math/big"
"net"
)
func (p *ParsedCIDR) getLastIPv6() net.IP {
if p.IsIPv6 != true {
return nil
}
ip := make(net.IP, 16)
ip = p.LastIPv6().Bytes()
return ip
}
// FirstIPv6 return Decimal FirstIP
func (p *ParsedCIDR) FirstIPv6() *big.Int {
if p.IsIPv6 != true {
return nil
}
IPInt := big.NewInt(0)
return IPInt.SetBytes(p.FirstIP.To16())
}
// HostCountIPv6 return number of IPs on the parsed range
func (p *ParsedCIDR) HostCountIPv6() *big.Int {
ones, bits := p.IPNet.Mask.Size()
var max = big.NewInt(1)
return max.Lsh(max, uint(bits-ones))
}
// LastIPv6 return Decimal LastIP
func (p *ParsedCIDR) LastIPv6() *big.Int {
if p.IsIPv6 != true {
return nil
}
IPInt := p.FirstIPv6()
return IPInt.Add(IPInt, big.NewInt(0).Sub(p.HostCountIPv6(), big.NewInt(1)))
}