Skip to content

Conversation

piersoh
Copy link
Contributor

@piersoh piersoh commented Dec 21, 2020

This minor patch allows for providing a PacketList tosniff(offline=my_packet_list). The existing behaviour is to fail ("AttributeError: 'list' object has no attribute 'read'") when provided with a PacketList.

The test suit runs against it ok.

@piersoh piersoh force-pushed the offline-packetlist-fix branch from 9a64e23 to 9eb66c0 Compare December 21, 2020 17:54
@codecov
Copy link

codecov bot commented Dec 21, 2020

Codecov Report

Merging #3026 (85acb7d) into master (2a8733a) will decrease coverage by 0.01%.
The diff coverage is 100.00%.

@@            Coverage Diff             @@
##           master    #3026      +/-   ##
==========================================
- Coverage   85.37%   85.35%   -0.02%     
==========================================
  Files         255      256       +1     
  Lines       53968    54135     +167     
==========================================
+ Hits        46075    46209     +134     
- Misses       7893     7926      +33     
Impacted Files Coverage Δ
scapy/sendrecv.py 84.46% <100.00%> (ø)
scapy/contrib/automotive/bmw/hsfz.py 53.22% <0.00%> (-1.78%) ⬇️
scapy/layers/can.py 94.63% <0.00%> (-1.45%) ⬇️
scapy/arch/windows/__init__.py 67.73% <0.00%> (-1.09%) ⬇️
scapy/data.py 87.85% <0.00%> (-0.52%) ⬇️
scapy/contrib/automotive/gm/gmlanutils.py 88.26% <0.00%> (-0.50%) ⬇️
scapy/arch/linux.py 0.73% <0.00%> (-0.50%) ⬇️
scapy/contrib/automotive/gm/gmlan.py 92.33% <0.00%> (-0.36%) ⬇️
scapy/fields.py 91.20% <0.00%> (-0.29%) ⬇️
scapy/utils.py 78.70% <0.00%> (-0.20%) ⬇️
... and 15 more

Copy link
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.

elif isinstance(offline, list) and \
elif (isinstance(offline, list) or
isinstance(offline, PacketList)) and \
all(isinstance(elt, Packet) for elt in offline):
Copy link
Member

Choose a reason for hiding this comment

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

We need to find something more efficient than this. We can probably just check the first element and assume the type list is consistent..

Copy link
Contributor Author

@piersoh piersoh Jan 5, 2021

Choose a reason for hiding this comment

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

Howabout: isinstance(offline, (list, PacketList)) ?

%timeit isinstance(pktlist, (list, PacketList))
191 ns ± 1.59 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

%timeit isinstance(pktlist, list)
150 ns ± 3.02 ns per loop (mean ± std. dev. of 7 runs, 10000000 loops each)

%timeit isinstance(pktlist, list) or isinstance(pktlist, PacketList)
220 ns ± 5.1 ns per loop (mean ± std. dev. of 7 runs, 1000000 loops each)

Copy link
Member

Choose a reason for hiding this comment

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

I think @gpotter2 was actually talking about the next check (all(...))

Copy link
Member

Choose a reason for hiding this comment

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

I agree with you @gpotter2 but that's not related to this PR. The proposed patch looks good to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ah ok thanks. Agree all() check can be a bit of a delay - Looking at where the call graph goes it ends in calling PcapWriter() whilst it checks for None type one could just add a Packet type check there...

@p-l- p-l- merged commit ef4937f into secdev:master Jan 14, 2021
bzalkilani pushed a commit to bzalkilani/scapy that referenced this pull request Jun 12, 2022
bzalkilani pushed a commit to bzalkilani/scapy that referenced this pull request Jun 14, 2022
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.

4 participants