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-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-04-27 16:56:47 +00:00
|
|
|
mi := csm.NewMatchInfo(port.Host.IPV4, 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-04-19 11:36:56 +00:00
|
|
|
ServiceName: m.Name(),
|
|
|
|
}
|
|
|
|
s.Port = port
|
|
|
|
resultChan <- s
|
|
|
|
return true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false
|
|
|
|
}
|