-
Notifications
You must be signed in to change notification settings - Fork 0
/
ipprotocol.go
50 lines (41 loc) · 843 Bytes
/
ipprotocol.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
package ios
import "fmt"
func parseIPProtocol(s string) (IPProtocol, error) {
switch s {
case IP.name:
return IP, nil
case ICMP.name:
return ICMP, nil
case UDP.name:
return UDP, nil
case ESP.name:
return ESP, nil
default:
return IPProtocol{}, fmt.Errorf("%s is not a known IP protocol", s)
}
}
type IPProtocol struct {
name string
number int8
}
func (p IPProtocol) String() string {
return p.name
}
func (p IPProtocol) Integer() int8 {
return p.number
}
func (p IPProtocol) Equals(o IPProtocol) bool {
return p.number == o.number
}
func (p IPProtocol) Gter(o IPProtocol) bool {
return p.number > o.number
}
func (p IPProtocol) Lter(o IPProtocol) bool {
return p.number < o.number
}
var (
IP = IPProtocol{"ip", 0}
ICMP = IPProtocol{"icmp", 1}
UDP = IPProtocol{"udp", 17}
ESP = IPProtocol{"esp", 50}
)