container_discovery/internal/discoverer/ipv4/service_udp.go
crusader b2bd7528c8 ing
2018-06-20 21:08:53 +09:00

43 lines
1.2 KiB
Go

package ipv4
import (
"fmt"
csm "git.loafle.net/commons/service_matcher-go"
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"
"git.loafle.net/overflow/container_discovery/internal/matcher"
)
func scanServiceUDP(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
portNumber, err := cuej.NumberToInt(port.PortNumber)
if err != nil {
errChan <- fmt.Errorf("Discovery: Service scan port[%s] error %v ", port.PortNumber, err)
return false
}
ms := matcher.GetUDPMatchers()
mi := csm.NewMatchInfo(port.Host.Address, portNumber)
for i := 0; i < len(ms); i++ {
m := ms[i]
p := csm.NewPacket(port.UDPLayer.LayerPayload(), len(port.UDPLayer.LayerPayload()))
if m.Match(mi, 0, p) {
s := &ocmd.Service{
Name: m.Name(),
Port: port,
MetaCryptoType: ocmm.ToMetaCryptoType(ocmm.MetaCryptoTypeEnumNONE),
DiscoveredDate: occu.NowPtr(),
}
resultChan <- s
return true
}
}
return false
}