-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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
Refactor offline sniff
code
#2559
Conversation
cb6a6df
to
31abcad
Compare
Codecov Report
@@ Coverage Diff @@
## master #2559 +/- ##
==========================================
+ Coverage 88.28% 89.00% +0.71%
==========================================
Files 243 246 +3
Lines 51006 54457 +3451
==========================================
+ Hits 45032 48470 +3438
- Misses 5974 5987 +13
|
31abcad
to
81b4141
Compare
047e1f1
to
a6c2707
Compare
About the pipeline failures - Codacy - I can understand the problem, but the problem was before as well (PcapReader never set the Scapy unit tests 3.7 - It failed in ARPingResult, and it seems that the problem isn't related to me, as I don't see any filter in this test. It is really hard to debug the failure in this one.. In [8]: ar = ARPingResult([(None, Ether(src='70:ee:50:50:ee:70')/ARP(psrc='192.168.0.1'))])
In [9]: with ContextManagerCaptureOutput() as cmco:
ar.show()
result_ar = cmco.get_output()
...:
In [10]: result_ar.startswith(" 70:ee:50:50:ee:70 Netatmo 192.168.0.1")
Out[10]: True So.. i'm not sure what's going on. |
Unrelated random failure. |
a6c2707
to
77128be
Compare
Few fixes: 1. _write_to_pcap: - should use `packets_list`, but instead uses the "global" offline variable. So changed it to `packets_list`. - Returns `filename` twice. Changed it so it returns just once. 2. in the `isinstance` checks part: - _write_to_pcap doesn't return `offline`. it returns the temp pcap file. - We do not check `isinstance(offline, PacketList)`, which works as well, and should be exposed as an option for the user. Now it is. 3. In case `offline` is a handle/path to a pcap file, the usage of the variable `offline` is misleading. Now it is more clearified. 4. Update the comment of `offline` - this attribute can recieve also Packet, A list of Packets and a PacketList (not only pcap files). This should be mentioned as this feature is very usefull for these cases too (for example, filter packets that were sniffed using a raw socket).
77128be
to
9305cb3
Compare
71dae7d
to
9305cb3
Compare
if isinstance(offline, Packet) or \ | ||
isinstance(offline, PacketList) or \ | ||
(isinstance(offline, list) and | ||
all(isinstance(elt, Packet) for elt in offline)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If it's a list of something else than packets what happens? If the answer is "it crashes" then this line is unnecessary
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @gpotter2
It doesn't crash, though the result can be considered "weird" - (The counter of Other
will be equal to the list's length). I guess the right thing to do is to raise a TypeError or something.. I just copied the same type checks from the previous version to my changes.
if isinstance(offline, Packet) or \ | ||
isinstance(offline, PacketList) or \ | ||
(isinstance(offline, list) and | ||
all(isinstance(elt, Packet) for elt in offline)): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
if isinstance(offline, Packet) or \ | |
isinstance(offline, PacketList) or \ | |
(isinstance(offline, list) and | |
all(isinstance(elt, Packet) for elt in offline)): | |
if isinstance(offline, (Packet, PacketList)) or \ | |
(isinstance(offline, list) and | |
all(isinstance(elt, Packet) for elt in offline)): |
Made obsolete by #3055 |
Few fixes:
packets_list
, but instead uses the "global"offline variable. So changed it to
packets_list
.filename
twice. Changed it so it returns just once.isinstance
checks part:offline
. it returns the temp pcap file.isinstance(offline, PacketList)
, which works as well,and should be exposed as an option for the user. Now it is.
In case
offline
is a handle/path to a pcap file, the usage of the variableoffline
is misleading. Now it is more clearified.Update the comment of
offline
- this attributecan recieve also Packet, A list of Packets and a PacketList (not only pcap files).
This should be mentioned as this feature is very usefull for these cases too (for example,
filter packets that were sniffed using a raw socket).
In addition, I've noticed that when invalid bpf filter is passed to
filter
, wrong/misleading exception message is being raised (Not a supported capture file
), so i've added the addition of (or invalid filter
), so the user won't get confused.