Skip to content
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

Add stop_filter parameter to SndRcvHandler #4360

Closed
bsullivan19 opened this issue Apr 23, 2024 · 0 comments · Fixed by #4361
Closed

Add stop_filter parameter to SndRcvHandler #4360

bsullivan19 opened this issue Apr 23, 2024 · 0 comments · Fixed by #4361

Comments

@bsullivan19
Copy link
Contributor

Brief description

SndRcvHandler has a field multi to enable receiving multiple answer to a single Packet. Currently, if multi is set, the only way to stop sniffing for more answers is to specify a timeout and wait for it to expire, or to give a KeyboardInterrupt. Waiting for a specified timeout is not very feasibly for a few reasons: the timeout to receive an answer may not always come in a reliably consistent amount of time, and waiting for a timeout may result in decreased responsiveness for applications using Scapy.

AsyncSniffer already has a field stop_filter for a callback fn which takes a Packet and returns True if the AsyncSniffer should be stopped early.

I'm proposing adding a field stop_filter to SndRcvHandler.__init__() to allow sr() related functions to pass the stop_filter to the AsyncSniffer in SndRcvHandler()._sndrcv_rcv()

Scapy version

2.5.0

Python version

3.12.2

Operating system

Windows 10

Additional environment information

No response

How to reproduce

pkt: Packet = ...
sr(pkt, multi=1, timeout=1)

Actual result

No response

Expected result

No response

Related resources

No response

bsullivan19 added a commit to bsullivan19/scapy-sndrcv-stop-filter that referenced this issue Apr 23, 2024
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.
gpotter2 pushed a commit that referenced this issue Apr 27, 2024
* #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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant