ing
This commit is contained in:
parent
dee29f34d9
commit
6f6d62f409
|
@ -47,13 +47,10 @@ func scanV4(discoverySession session.DiscoverySession, targetHost *omd.Host) err
|
|||
return
|
||||
}
|
||||
delay.Store(true)
|
||||
// go func(packet *layers.TCP) {
|
||||
if p := handlePacketTCP4(discoverySession, targetHost, ports, packet); nil != p {
|
||||
discoverySession.AddPort(p)
|
||||
log.Print(p)
|
||||
}
|
||||
|
||||
// }(packet)
|
||||
case <-ticker.C:
|
||||
if false == delay.Load().(bool) {
|
||||
ticker.Stop()
|
||||
|
|
|
@ -1,6 +1,8 @@
|
|||
package pcap
|
||||
|
||||
import (
|
||||
"log"
|
||||
|
||||
"github.com/google/gopacket"
|
||||
"github.com/google/gopacket/layers"
|
||||
)
|
||||
|
@ -75,7 +77,11 @@ func handlePacketARP(ps *pCapScan, packet gopacket.Packet) {
|
|||
arp := arpLayer.(*layers.ARP)
|
||||
|
||||
for _, ch := range ps.arpListenerChans {
|
||||
ch <- arp
|
||||
select {
|
||||
case ch <- arp:
|
||||
default:
|
||||
log.Print("handlePacketARP cannot send to channel")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -87,7 +93,11 @@ func handlePacketICMP4(ps *pCapScan, packet gopacket.Packet) {
|
|||
// icmp4 := icmp4Layer.(*layers.ICMPv4)
|
||||
|
||||
for _, ch := range ps.icmp4ListenerChans {
|
||||
ch <- packet
|
||||
select {
|
||||
case ch <- packet:
|
||||
default:
|
||||
log.Print("handlePacketICMP4 cannot send to channel")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -99,7 +109,11 @@ func handlePacketICMP6(ps *pCapScan, packet gopacket.Packet) {
|
|||
// icmp6 := icmp6Layer.(*layers.ICMPv6)
|
||||
|
||||
for _, ch := range ps.icmp6ListenerChans {
|
||||
ch <- packet
|
||||
select {
|
||||
case ch <- packet:
|
||||
default:
|
||||
log.Print("handlePacketICMP6 cannot send to channel")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -120,16 +134,13 @@ func handlePacketTCP(ps *pCapScan, packet gopacket.Packet) {
|
|||
|
||||
chs, ok := ps.tcpListenerChans[ip]
|
||||
if ok {
|
||||
// for _, ch := range chs {
|
||||
// ch <- tcp
|
||||
// }
|
||||
for _, ch := range chs {
|
||||
select {
|
||||
case ch <- tcp:
|
||||
default:
|
||||
log.Print("handlePacketTCP cannot send to channel")
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -147,7 +158,11 @@ func handlePacketUDP(ps *pCapScan, packet gopacket.Packet) {
|
|||
chs, ok := ps.udpListenerChans[ip]
|
||||
if ok {
|
||||
for _, ch := range chs {
|
||||
ch <- packet
|
||||
select {
|
||||
case ch <- packet:
|
||||
default:
|
||||
log.Print("handlePacketUDP cannot send to channel")
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -191,7 +191,7 @@ func (ps *pCapScan) OpenTCP(ip string) chan *layers.TCP {
|
|||
ps.tcpListenerChans[ip] = make([]chan *layers.TCP, 0)
|
||||
}
|
||||
|
||||
ch := make(chan *layers.TCP, 1024)
|
||||
ch := make(chan *layers.TCP, 2048)
|
||||
ps.tcpListenerChans[ip] = append(ps.tcpListenerChans[ip], ch)
|
||||
|
||||
return ch
|
||||
|
@ -319,7 +319,7 @@ func handleReceive(ps *pCapScan) {
|
|||
for {
|
||||
select {
|
||||
case packet := <-inPacket:
|
||||
go handlePacket(ps, packet)
|
||||
handlePacket(ps, packet)
|
||||
case <-ps.stopChan:
|
||||
ps.destroy()
|
||||
return
|
||||
|
|
Loading…
Reference in New Issue
Block a user