container_discovery/internal/discoverer/ipv4/service_udp.go

41 lines
1.0 KiB
Go
Raw Normal View History

2018-04-19 11:36:56 +00:00
package ipv4
import (
"fmt"
csm "git.loafle.net/commons/service_matcher-go"
cuej "git.loafle.net/commons/util-go/encoding/json"
2018-05-11 02:44:47 +00:00
occu "git.loafle.net/overflow/commons-go/core/util"
2018-04-26 09:00:24 +00:00
ocmd "git.loafle.net/overflow/commons-go/model/discovery"
2018-04-19 11:36:56 +00:00
"git.loafle.net/overflow/container_discovery/internal/matcher"
)
2018-04-27 16:20:01 +00:00
func scanServiceUDP(port *ocmd.Port, ds *ocmd.DiscoverService, resultChan chan interface{}, errChan chan error, stopChan chan struct{}) bool {
2018-04-19 11:36:56 +00:00
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()
2018-06-13 10:20:14 +00:00
mi := csm.NewMatchInfo(port.Host.Address, portNumber)
2018-04-19 11:36:56 +00:00
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) {
2018-04-26 09:00:24 +00:00
s := &ocmd.Service{
2018-06-13 10:20:14 +00:00
Name: m.Name(),
2018-05-11 02:44:47 +00:00
Port: port,
DiscoveredDate: occu.NowPtr(),
2018-04-19 11:36:56 +00:00
}
2018-05-11 02:44:47 +00:00
2018-04-19 11:36:56 +00:00
resultChan <- s
return true
}
}
return false
}