container_discovery/internal/discoverer/ipv4/service_udp.go
crusader c65fd4ab7d ing
2018-06-13 19:20:14 +09:00

41 lines
1.0 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"
"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,
DiscoveredDate: occu.NowPtr(),
}
resultChan <- s
return true
}
}
return false
}