Change: use uint16 for Metadata SrcPort and DstPort

This commit is contained in:
Dreamacro
2023-08-03 23:20:40 +08:00
parent 47b6eb1700
commit c0e51f8556
13 changed files with 63 additions and 58 deletions

View File

@ -17,7 +17,7 @@ const (
type Port struct {
adapter string
port string
port C.Port
portType PortType
}
@ -41,7 +41,7 @@ func (p *Port) Match(metadata *C.Metadata) bool {
case PortTypeDest:
return metadata.DstPort == p.port
case PortTypeInbound:
return metadata.InboundPort == p.port
return metadata.InboundPort == uint16(p.port)
default:
panic(fmt.Errorf("unknown port type: %v", p.portType))
}
@ -52,7 +52,7 @@ func (p *Port) Adapter() string {
}
func (p *Port) Payload() string {
return p.port
return p.port.String()
}
func (p *Port) ShouldResolveIP() bool {
@ -64,13 +64,13 @@ func (p *Port) ShouldFindProcess() bool {
}
func NewPort(port string, adapter string, portType PortType) (*Port, error) {
_, err := strconv.ParseUint(port, 10, 16)
p, err := strconv.ParseUint(port, 10, 16)
if err != nil {
return nil, errPayload
}
return &Port{
adapter: adapter,
port: port,
port: C.Port(p),
portType: portType,
}, nil
}