ing
This commit is contained in:
parent
e1f698cc1c
commit
a8d61c6657
|
@ -16,10 +16,11 @@ import (
|
||||||
"github.com/google/gopacket/layers"
|
"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()
|
ps := discoverySession.PCapScanner()
|
||||||
if nil == ps {
|
if nil == ps {
|
||||||
return fmt.Errorf("Cannot retain pcap instance")
|
err = fmt.Errorf("Cannot retain pcap instance")
|
||||||
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
tcpChan := ps.OpenTCP(targetHost.Address)
|
tcpChan := ps.OpenTCP(targetHost.Address)
|
||||||
|
@ -31,6 +32,9 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
|
||||||
stopChan := make(chan struct{})
|
stopChan := make(chan struct{})
|
||||||
defer close(stopChan)
|
defer close(stopChan)
|
||||||
|
|
||||||
|
var sendComplete atomic.Value
|
||||||
|
sendComplete.Store(false)
|
||||||
|
|
||||||
go func() {
|
go func() {
|
||||||
defer func() {
|
defer func() {
|
||||||
close(timerStopped)
|
close(timerStopped)
|
||||||
|
@ -39,7 +43,7 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
|
||||||
|
|
||||||
var delay atomic.Value
|
var delay atomic.Value
|
||||||
delay.Store(false)
|
delay.Store(false)
|
||||||
ticker := time.NewTicker(time.Millisecond * 20000)
|
ticker := time.NewTicker(time.Millisecond * 5000)
|
||||||
defer func() {
|
defer func() {
|
||||||
ticker.Stop()
|
ticker.Stop()
|
||||||
}()
|
}()
|
||||||
|
@ -55,6 +59,10 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
|
||||||
go discoverySession.AddPort(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPSyn), p, nil)
|
go discoverySession.AddPort(omm.ToMetaDiscovererType(omm.MetaDiscovererTypeEnumTCPSyn), p, nil)
|
||||||
}
|
}
|
||||||
case <-ticker.C:
|
case <-ticker.C:
|
||||||
|
if false == sendComplete.Load().(bool) {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if false == delay.Load().(bool) {
|
if false == delay.Load().(bool) {
|
||||||
return
|
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)
|
log.Printf("sendTCP %v", err)
|
||||||
return nil
|
return
|
||||||
}
|
}
|
||||||
log.Print("sendTCP4 Complete:", targetHost.Address)
|
sendComplete.Store(true)
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case <-timerStopped:
|
case <-timerStopped:
|
||||||
log.Print("timerStopped:", targetHost.Address)
|
|
||||||
return nil
|
return nil
|
||||||
case <-discoverySession.StopChan():
|
case <-discoverySession.StopChan():
|
||||||
return nil
|
return nil
|
||||||
|
|
Loading…
Reference in New Issue
Block a user