overflow_discovery/discovery/ipv4/service_udp.go

38 lines
1004 B
Go
Raw Normal View History

2017-11-22 10:04:04 +00:00
package ipv4
import (
2017-12-04 09:37:39 +00:00
"fmt"
cnsm "git.loafle.net/commons_go/network_service_matcher"
cuej "git.loafle.net/commons_go/util/encoding/json"
discoveryM "git.loafle.net/overflow/overflow_commons_go/modules/discovery/model"
"git.loafle.net/overflow/overflow_discovery/matcher"
2017-11-22 10:04:04 +00:00
)
2017-12-04 09:37:39 +00:00
func scanServiceUDP(port *discoveryM.Port, ds *discoveryM.DiscoveryService, 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
}
2017-11-22 10:04:04 +00:00
2017-12-04 09:37:39 +00:00
ms := matcher.GetUDPMatchers()
mi := cnsm.NewMatchInfo(port.Host.IP, portNumber)
2017-11-22 10:04:04 +00:00
for i := 0; i < len(ms); i++ {
m := ms[i]
2017-12-04 09:37:39 +00:00
p := cnsm.NewPacket(port.UDPLayer.LayerPayload(), len(port.UDPLayer.LayerPayload()))
2017-11-22 10:04:04 +00:00
if m.Match(mi, 0, p) {
2017-12-04 09:37:39 +00:00
s := &discoveryM.Service{
2017-11-22 10:04:04 +00:00
ServiceName: m.ServiceName(),
}
s.Port = port
resultChan <- s
return true
}
}
return false
}