-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathaddress_type.go
57 lines (47 loc) · 1.14 KB
/
address_type.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
45
46
47
48
49
50
51
52
53
54
55
56
57
package goip
// addrType keeps track of which address divisions and groups
// of address divisions can be converted to higher-level types.
type addrType byte
const (
zeroType addrType = 0 // no segments
ipv4Type addrType = 1 // ipv4 segments
ipv6Type addrType = 2 // ipv6 segments
ipv6v4MixedType addrType = 3 // ipv6-v4 mixed segments
macType addrType = 4 // mac segments
)
func (a addrType) isIPv4() bool {
return a == ipv4Type
}
func (a addrType) isIPv6() bool {
return a == ipv6Type
}
func (a addrType) isIPv6v4Mixed() bool {
return a == ipv6v4MixedType
}
func (a addrType) isIP() bool {
return a.isIPv4() || a.isIPv6()
}
func (a addrType) isMAC() bool {
return a == macType
}
func (a addrType) isZeroSegments() bool {
return a == zeroType
}
func (a addrType) getIPNetwork() (network IPAddressNetwork) {
if a.isIPv6() {
network = ipv6Network
} else if a.isIPv4() {
network = ipv4Network
}
return
}
func (a addrType) getNetwork() (network addressNetwork) {
if a.isIPv6() {
network = ipv6Network
} else if a.isIPv4() {
network = ipv4Network
} else if a.isMAC() {
network = macNetwork
}
return
}