container_discovery/internal/discoverer/ipv4/service.go
crusader 5f80794d28 ing
2018-06-21 19:54:31 +09:00

53 lines
1.7 KiB
Go

package ipv4
import (
"fmt"
cuej "git.loafle.net/commons/util-go/encoding/json"
occu "git.loafle.net/overflow/commons-go/core/util"
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
ocmm "git.loafle.net/overflow/commons-go/model/meta"
"github.com/google/gopacket/layers"
)
func ScanService(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) {
portNumber, err := cuej.NumberToInt(port.PortNumber)
if err != nil {
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)
return
}
switch ocmm.ToMetaPortTypeEnum(port.MetaPortType) {
case ocmm.MetaPortTypeEnumTCP:
if !scanServiceTCP(port, ds, resultChan, errChan, stopChan) {
if dName, ok := layers.TCPPortNames[layers.TCPPort(portNumber)]; ok {
description := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
s := &ocmd.Service{
Key: ocmm.MetaTargetServiceTypeEnumUNKNOWN.String(),
Description: description,
DiscoveredDate: occu.NowPtr(),
Port: port,
MetaCryptoType: ocmm.ToMetaCryptoType(ocmm.MetaCryptoTypeEnumUNKNOWN),
}
resultChan <- s
}
}
case ocmm.MetaPortTypeEnumUDP:
if !scanServiceUDP(port, ds, resultChan, errChan, stopChan) {
if dName, ok := layers.UDPPortNames[layers.UDPPort(portNumber)]; ok {
description := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
s := &ocmd.Service{
Key: ocmm.MetaTargetServiceTypeEnumUNKNOWN.String(),
Description: description,
DiscoveredDate: occu.NowPtr(),
Port: port,
MetaCryptoType: ocmm.ToMetaCryptoType(ocmm.MetaCryptoTypeEnumUNKNOWN),
}
resultChan <- s
}
}
}
}