Skip to content

Add ScapyNotRunningException - #5258

Merged
gpotter2 merged 1 commit into
secdev:masterfrom
hedrok:add-scapy-not-running-exception
Nov 2, 2026
Merged

gpotter2 merged 1 commit into
secdev:masterfrom
hedrok:add-scapy-not-running-exception

Conversation

@hedrok

@hedrok hedrok commented Oct 28, 2026

Copy link
Copy Markdown
Contributor

Description

Add ScapyNotRunningException

Currently when stopping AsyncSniffer there is no easy way to tell whether the sniffer just was already stopped or some other error occured. Add separate ScapyNotRunningException for that.

I have to use

        try:
            sniffer.stop()
        except Scapy_Exception as e:
            if e.args[0] != "Not running ! (check .running attr)":
                raise

Very not nice and fragile...

Maybe I've missed some better way?

I've put AI-Assisted: no as I used Claude Opus 5.5 only as reviewer and I expect that it is needed to discern generated code, not review etc. It would be helpful if more details are given in CONTRIBUTING.md, please write if I'm mistaken.

Currently when stopping AsyncSniffer there is no easy way to tell
whether the sniffer just was already stopped or some other error
occured. Add separate ScapyNotRunningException for that.

AI-Assisted: no
@codecov

codecov Bot commented Oct 29, 2026 •

Copy link
Copy Markdown

Codecov Report

❌ Patch coverage is 75.00000% with 1 line in your changes missing coverage. Please review.
✅ Project coverage is 80.55%. Comparing base (c388704) to head (a91736d).
⚠️ Report is 1 commits behind head on master.

Files with missing lines Patch % Lines
scapy/sendrecv.py 50.00% 1 Missing ⚠️
Additional details and impacted files
@@           Coverage Diff           @@
##           master    #5258   +/-   ##
=======================================
  Coverage   80.54%   80.55%           
=======================================
  Files         375      375           
  Lines       98399    98401    +2     
=======================================
+ Hits        79259    79265    +6     
+ Misses      19140    19136    -4     
Files with missing lines Coverage Δ
scapy/error.py 97.10% <100.00%> (+0.08%) ⬆️
scapy/sendrecv.py 87.03% <50.00%> (-0.14%) ⬇️

... and 3 files with indirect coverage changes

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.

@gpotter2
gpotter2 merged commit bb941fa into secdev:master Nov 2, 2026
23 checks passed
@gpotter2

gpotter2 commented Nov 2, 2026

Copy link
Copy Markdown
Member

Thanks for the PR !

@hedrok

hedrok commented Nov 3, 2026

Copy link
Copy Markdown
Contributor Author

Thanks for merging! :)

In case you are interested, I've added wrapper around AsyncSniffer with the following additional features:

  1. wait_on_start - when calling start wait for capture to start, with timeout.
  2. ignore_stopped in stop - simple try/except (that can be done even simpler after this PR) that ignores error that it is not running. In my use case that would be logical behaviour: start sniffer with count=5, join with timeout expecting that the thread will exit, but when I run stop after that I don't know - was test successful and sniffer stopped after 5 packets or not and it is still running?.. Just a useful parameter in my opinion.
  3. Support of network namespaces. This one was covered (and basically rejected) here: Scapy doesn't find the correct interface when sending from Linux NetNS #3467 so probably you don't want to have that, but as you can see in the PR, it is not so hard to add, and five years passed, so possibly you've changed your mind. At least could you open the issue so that I could add comment with up-to-date workaround?.. Workaround in the issue has problems.

External project PR with this wrapper: https://github.com/FRRouting/frr/pull/24141/changes#diff-76696c6d13f53dab66fa5322c6675b8d6246dca94ddc7754de725fcee9ffafdc

I can open PRs to scapy with any (or all) of above, if you could write which of items are useful, I'll create them.

Thanks for Scapy! :)

@hedrok
hedrok deleted the add-scapy-not-running-exception branch November 3, 2026 14:53
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 this pull request may close these issues.

2 participants