Skip to content

Support Multiple Comments in Packet Object#4798

Merged
gpotter2 merged 13 commits into
secdev:masterfrom
bkayranci:master
Sep 4, 2025
Merged

Support Multiple Comments in Packet Object#4798
gpotter2 merged 13 commits into
secdev:masterfrom
bkayranci:master

Conversation

@bkayranci
Copy link
Copy Markdown
Contributor

The pcapng format specification explicitly allows for multiple comments to be associated with a packet via repeated opt_comment fields. This change brings Scapy closer to that standard, making it easier to work with multi-comment pcapng traces and enabling richer annotations in packet analysis.

Checklist:

  • If you are new to Scapy: I have checked CONTRIBUTING.md (esp. section submitting-pull-requests)
  • I squashed commits belonging together
  • I added unit tests or explained why they are not relevant
  • I executed the regression tests (using cd test && ./run_tests or tox)
  • If the PR is still not finished, please create a Draft Pull Request

@bkayranci
Copy link
Copy Markdown
Contributor Author

Hi @gpotter2 , this is my first contribution to the repo. Could you please review this PR? Let me know if there's anything I should fix. Thanks!

@codecov
Copy link
Copy Markdown

codecov Bot commented Jul 21, 2025

Codecov Report

❌ Patch coverage is 91.42857% with 3 lines in your changes missing coverage. Please review.
✅ Project coverage is 80.90%. Comparing base (b54fdb7) to head (ecab9a6).
⚠️ Report is 24 commits behind head on master.

Files with missing lines Patch % Lines
scapy/utils.py 86.36% 3 Missing ⚠️
Additional details and impacted files
@@            Coverage Diff             @@
##           master    #4798      +/-   ##
==========================================
+ Coverage   80.08%   80.90%   +0.82%     
==========================================
  Files         365      366       +1     
  Lines       89027    90158    +1131     
==========================================
+ Hits        71296    72946    +1650     
+ Misses      17731    17212     -519     
Files with missing lines Coverage Δ
scapy/packet.py 84.66% <100.00%> (+0.10%) ⬆️
scapy/utils.py 73.54% <86.36%> (-0.33%) ⬇️

... and 52 files with indirect coverage changes

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

@bkayranci
Copy link
Copy Markdown
Contributor Author

Hi again @gpotter2, just following up on this PR. We have a need for this feature in our project, so I’d really appreciate a review when you have the time. Please let me know if any changes are needed. Thanks in advance!

Comment thread scapy/utils.py Outdated
Comment thread scapy/utils.py
Comment thread scapy/utils.py Outdated
@gpotter2
Copy link
Copy Markdown
Member

Thanks for the PR and sorry for the delay of review. I have a few questions regarding the code.
Cheers !

@bkayranci
Copy link
Copy Markdown
Contributor Author

Thanks for the PR and sorry for the delay of review. I have a few questions regarding the code.
Cheers !

Let me know if there's anything else I should take care of before this can be merged. Appreciate your time!

Comment thread scapy/utils.py Outdated
Comment thread scapy/utils.py Outdated
Comment thread scapy/utils.py Outdated
Comment thread scapy/utils.py Outdated
@gpotter2
Copy link
Copy Markdown
Member

gpotter2 commented Aug 1, 2025

I also personally would have kept comments in the same argument index as comment, rather than adding it at the end.

@bkayranci
Copy link
Copy Markdown
Contributor Author

I also personally would have kept comments in the same argument index as comment, rather than adding it at the end.

That's a fair point, and I understand the value of maintaining positional consistency. In this case, since we changed both the name and the type (comment: Optional[str] to comments: Optional[List[bytes]]), we felt that reusing the same argument position might introduce subtle bugs or make mistakes harder to catch during refactoring. especially if any code still relies on the previous positional usage. Placing comments at the end was a cautious choice to reduce the risk of silent errors. Open to refactor if you think it’s worth aligning for clarity.

@bkayranci
Copy link
Copy Markdown
Contributor Author

@gpotter2 I hope all is well. I wanted to gently follow up on my comment on the PR. I'd be grateful for your thoughts whenever you get a chance.

Copy link
Copy Markdown
Member

@guedou guedou left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR. I made a second review.

Comment thread scapy/packet.py Outdated
Comment thread scapy/packet.py Outdated
Comment thread scapy/packet.py
Comment thread scapy/utils.py Outdated
Comment thread scapy/utils.py Outdated
Comment thread scapy/utils.py Outdated
Comment thread scapy/utils.py Outdated
Comment thread scapy/utils.py Outdated
Comment thread scapy/utils.py Outdated
Comment thread scapy/utils.py
gpotter2
gpotter2 previously approved these changes Aug 22, 2025
@gpotter2
Copy link
Copy Markdown
Member

LGTM although tests don't pass.

@guedou guedou dismissed gpotter2’s stale review August 22, 2025 07:26

A change is still needed

@bkayranci
Copy link
Copy Markdown
Contributor Author

LGTM although tests don't pass.

I fixed typing and linting issues.

I noticed a few # type: ignore lines — that makes sense here since mypy can’t infer the types, but according to the pcapng spec we know they are bytes or List[bytes]

Comment thread scapy/utils.py Outdated
Comment thread scapy/utils.py
Comment thread scapy/utils.py
Comment thread scapy/utils.py
@guedou
Copy link
Copy Markdown
Member

guedou commented Aug 28, 2025

@bkayranci please keep comments at the same location as comment in the methods.

Co-authored-by: Guillaume Valadon <guillaume@valadon.net>
Copy link
Copy Markdown
Member

@gpotter2 gpotter2 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the PR & sorry for the back and forth. Have a good week

@gpotter2 gpotter2 enabled auto-merge (squash) September 3, 2025 16:50
@gpotter2 gpotter2 merged commit d73bbc1 into secdev:master Sep 4, 2025
42 of 44 checks passed
@gpotter2 gpotter2 added this to the 2.7.0 milestone Nov 2, 2025
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.

3 participants