This commit is contained in:
crusader 2018-09-28 17:50:57 +09:00
parent e1f698cc1c
commit a8d61c6657

View File

@ -16,10 +16,11 @@ import (
"github.com/google/gopacket/layers"
)
func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) error {
func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) (err error) {
ps := discoverySession.PCapScanner()
if nil == ps {
return fmt.Errorf("Cannot retain pcap instance")
err = fmt.Errorf("Cannot retain pcap instance")
return
}
tcpChan := ps.OpenTCP(targetHost.Address)
@ -31,6 +32,9 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
stopChan := make(chan struct{})
defer close(stopChan)
var sendComplete atomic.Value
sendComplete.Store(false)
go func() {
defer func() {
close(timerStopped)
@ -39,7 +43,7 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
var delay atomic.Value
delay.Store(false)
ticker := time.NewTicker(time.Millisecond * 20000)
ticker := time.NewTicker(time.Millisecond * 5000)
defer func() {
ticker.Stop()
}()
@ -55,6 +59,10 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
go discoverySession.AddPort(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPSyn), p, nil)
}
case <-ticker.C:
if false == sendComplete.Load().(bool) {
continue
}
if false == delay.Load().(bool) {
return
}
@ -63,15 +71,14 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
}
}()
if err := sendTCP4(discoverySession, ps, targetHost, stopChan); nil != err {
if err = sendTCP4(discoverySession, ps, targetHost, stopChan); nil != err {
log.Printf("sendTCP %v", err)
return nil
return
}
log.Print("sendTCP4 Complete:", targetHost.Address)
sendComplete.Store(true)
select {
case <-timerStopped:
log.Print("timerStopped:", targetHost.Address)
return nil
case <-discoverySession.StopChan():
return nil