fix: fixed a bug in net.sniff and wifi.recon that caused stop operations to hang on pcap_close

This commit is contained in:
evilsocket 2019-01-29 13:47:20 +01:00
commit 44fddfa455
No known key found for this signature in database
GPG key ID: 1564D7F30393A456
3 changed files with 25 additions and 2 deletions

View file

@ -4,6 +4,7 @@ import (
"fmt"
"time"
"github.com/bettercap/bettercap/log"
"github.com/bettercap/bettercap/session"
"github.com/google/gopacket"
@ -170,6 +171,7 @@ func (s *Sniffer) Start() error {
s.pktSourceChan = src.Packets()
for packet := range s.pktSourceChan {
if !s.Running() {
log.Debug("end pkt loop (pkt=%v filter='%s')", packet, s.Ctx.Filter)
break
}
@ -209,9 +211,14 @@ func (s *Sniffer) Start() error {
func (s *Sniffer) Stop() error {
return s.SetRunning(false, func() {
log.Debug("stopping sniffer")
if s.pktSourceChan != nil {
log.Debug("sending nil")
s.pktSourceChan <- nil
log.Debug("nil sent")
}
log.Debug("closing ctx")
s.Ctx.Close()
log.Debug("ctx closed")
})
}