-
Notifications
You must be signed in to change notification settings - Fork 0
/
base_sniffer.go
48 lines (38 loc) · 1.06 KB
/
base_sniffer.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
package sniffer
import (
"errors"
"github.com/qauzy/netat/common/utils"
"github.com/qauzy/netat/constant"
"github.com/qauzy/netat/constant/sniffer"
)
type SnifferConfig struct {
OverrideDest bool
Ports utils.IntRanges[uint16]
}
type BaseSniffer struct {
ports utils.IntRanges[uint16]
supportNetworkType constant.NetWork
}
// Protocol implements sniffer.Sniffer
func (*BaseSniffer) Protocol() string {
return "unknown"
}
// SniffTCP implements sniffer.Sniffer
func (*BaseSniffer) SniffTCP(bytes []byte) (string, error) {
return "", errors.New("TODO")
}
// SupportNetwork implements sniffer.Sniffer
func (bs *BaseSniffer) SupportNetwork() constant.NetWork {
return bs.supportNetworkType
}
// SupportPort implements sniffer.Sniffer
func (bs *BaseSniffer) SupportPort(port uint16) bool {
return bs.ports.Check(port)
}
func NewBaseSniffer(ports utils.IntRanges[uint16], networkType constant.NetWork) *BaseSniffer {
return &BaseSniffer{
ports: ports,
supportNetworkType: networkType,
}
}
var _ sniffer.Sniffer = (*BaseSniffer)(nil)