Skip to content

Commit

Permalink
Add stop_filter to SndRcvHandler (#4361)
Browse files Browse the repository at this point in the history
* #4360: Add stop_filter parameter to SndRcvHandler

Added stop_filter param to SndRcvHandler.__init__().
Pass stop_filter to AsyncSniffer._run in SndRcvHandler._sndrcv_rcv.
Check if SndRcvHandler.sniffer is running before stopping in SndRcvHandler._process_packet.
Updated _DOC_SNDRCV_PARAMS documentation to include new parameter.

* Resolve code style errors
  • Loading branch information
bsullivan19 committed Apr 27, 2024
1 parent 6ea71ea commit 78b7c24
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions scapy/sendrecv.py
Expand Up @@ -93,6 +93,8 @@ class debug:
:param threaded: if True, packets will be sent in an individual thread
:param session: a flow decoder used to handle stream of packets
:param chainEX: if True, exceptions during send will be forwarded
:param stop_filter: Python function applied to each packet to determine if
we have to stop the capture after this packet.
"""


Expand Down Expand Up @@ -127,7 +129,8 @@ def __init__(self,
_flood=None, # type: Optional[_FloodGenerator]
threaded=False, # type: bool
session=None, # type: Optional[_GlobSessionType]
chainEX=False # type: bool
chainEX=False, # type: bool
stop_filter=None # type: Optional[Callable[[Packet], bool]]
):
# type: (...) -> None
# Instantiate all arguments
Expand All @@ -148,6 +151,7 @@ def __init__(self,
self.timeout = timeout
self.session = session
self.chainEX = chainEX
self.stop_filter = stop_filter
self._send_done = False
self.notans = 0
self.noans = 0
Expand Down Expand Up @@ -294,7 +298,7 @@ def _process_packet(self, r):
sentpkt._answered = 1
break
if self._send_done and self.noans >= self.notans and not self.multi:
if self.sniffer:
if self.sniffer and self.sniffer.running:
self.sniffer.stop(join=False)
if not ok:
if self.verbose > 1:
Expand All @@ -315,6 +319,7 @@ def _sndrcv_rcv(self, callback):
store=False,
opened_socket=self.rcv_pks,
session=self.session,
stop_filter=self.stop_filter,
started_callback=callback,
chainCC=self.chainCC,
)
Expand Down

0 comments on commit 78b7c24

Please sign in to comment.