forked from Crosse/godivert
-
Notifications
You must be signed in to change notification settings - Fork 0
/
header.go
49 lines (43 loc) · 953 Bytes
/
header.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
package header
import "net/netip"
// Represents a IPv4 or IPv6 Header
type IPHeader interface {
String() string
Version() int
HeaderLen() uint8
NextHeader() uint8
SrcIP() netip.Addr
DstIP() netip.Addr
SetSrcIP(netip.Addr)
SetDstIP(netip.Addr)
Checksum() (uint16, error)
NeedNewChecksum() bool
}
// Represents a protocol header
// Supported headers are TCP, UDP, ICMPv4, ICMPv6
type ProtocolHeader interface {
String() string
HeaderLen() int
Checksum() uint16
SrcPort() (uint16, error)
DstPort() (uint16, error)
SetSrcPort(uint16) error
SetDstPort(uint16) error
NeedNewChecksum() bool
}
// Returns the name of the given protocol number
// See : https://en.wikipedia.org/wiki/List_of_IP_protocol_numbers
func ProtocolName(protocol uint8) string {
switch protocol {
case ICMPv4:
return "ICMPv4"
case TCP:
return "TCP"
case UDP:
return "UDP"
case ICMPv6:
return "ICMPv6"
default:
return "Unimplemented Protocol"
}
}