container_discovery/internal/discoverer/ipv4/service.go

47 lines
1.3 KiB
Go
Raw Normal View History

2018-04-19 11:36:56 +00:00
package ipv4
import (
"fmt"
cuej "git.loafle.net/commons/util-go/encoding/json"
occc "git.loafle.net/overflow/commons-go/core/constants"
ocdm "git.loafle.net/overflow/commons-go/discovery/model"
"github.com/google/gopacket/layers"
)
func ScanService(port *ocdm.Port, ds *ocdm.DiscoveryService, 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 port.PortType {
case occc.PortTypeTCP:
if !scanServiceTCP(port, ds, resultChan, errChan, stopChan) {
if dName, ok := layers.TCPPortNames[layers.TCPPort(portNumber)]; ok {
sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
s := &ocdm.Service{
ServiceName: sName,
}
s.Port = port
resultChan <- s
}
}
case occc.PortTypeUDP:
if !scanServiceUDP(port, ds, resultChan, errChan, stopChan) {
if dName, ok := layers.UDPPortNames[layers.UDPPort(portNumber)]; ok {
sName := fmt.Sprintf("Not Supported Service. Perhaps %s[%d]", dName, portNumber)
s := &ocdm.Service{
ServiceName: sName,
}
s.Port = port
resultChan <- s
}
}
}
}