probe/discoverer/ipv4/service_udp.go

45 lines
1.2 KiB
Go
Raw Normal View History

2018-08-13 07:19:59 +00:00
package ipv4
import (
"fmt"
cuej "git.loafle.net/commons/util-go/encoding/json"
omd "git.loafle.net/overflow/model/discovery"
omm "git.loafle.net/overflow/model/meta"
omu "git.loafle.net/overflow/model/util"
2018-08-15 07:46:52 +00:00
osm "git.loafle.net/overflow/service_matcher-go"
2018-08-13 07:19:59 +00:00
"git.loafle.net/overflow_scanner/probe/matcher"
)
func scanServiceUDP(port *omd.Port, ds *omd.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()
2018-08-15 07:46:52 +00:00
mi := osm.NewMatchInfo(port.Host.Address, portNumber)
2018-08-13 07:19:59 +00:00
for i := 0; i < len(ms); i++ {
m := ms[i]
2018-08-15 07:46:52 +00:00
p := osm.NewPacket(port.UDPLayer.LayerPayload(), len(port.UDPLayer.LayerPayload()))
2018-08-13 07:19:59 +00:00
if err := m.Match(mi, 0, p); err == nil {
s := &omd.Service{
Key: m.Key(),
Port: port,
MetaCryptoType: omm.ToMetaCryptoType(omm.MetaCryptoTypeEnumNONE),
DiscoveredDate: omu.NowPtr(),
2018-08-13 08:16:28 +00:00
Metadata: m.Meta(),
Name: m.Name(),
2018-08-13 07:19:59 +00:00
}
resultChan <- s
return true
}
}
return false
}