Skip to content

Fix sniffer join waiting indefinitely #4781

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions scapy/sendrecv.py
Original file line number Diff line number Diff line change
Expand Up @@ -1150,7 +1150,7 @@ def __init__(self, *args, **kwargs):
self.thread = None # type: Optional[Thread]
self.results = None # type: Optional[PacketList]
self.exception = None # type: Optional[Exception]
self.stop_cb = lambda: None # type: Callable[[], None]
self.stop_cb = lambda: None # type: Callable[[], Optional[bool]]

def _setup_thread(self):
# type: () -> None
Expand Down Expand Up @@ -1295,16 +1295,18 @@ def _run(self,
sniff_sockets[close_pipe] = "control_socket" # type: ignore

def stop_cb():
# type: () -> None
# type: () -> bool
if self.running and close_pipe:
close_pipe.send(None)
self.continue_sniff = False
return True
self.stop_cb = stop_cb
else:
# select is non blocking
def stop_cb():
# type: () -> None
# type: () -> bool
self.continue_sniff = False
return True
self.stop_cb = stop_cb

try:
Expand Down Expand Up @@ -1400,9 +1402,7 @@ def stop(self, join=True):
# type: (bool) -> Optional[PacketList]
"""Stops AsyncSniffer if not in async mode"""
if self.running:
try:
self.stop_cb()
except AttributeError:
if not self.stop_cb():
raise Scapy_Exception(
"Unsupported (offline or unsupported socket)"
)
Expand Down