-
Notifications
You must be signed in to change notification settings - Fork 271
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 method to match layers by type. #282
Conversation
This patch depends on the previous one, will rebase when the other is merged. |
Using the new .get() method you can quickly find the IP layer in a packet. With the .getall() method you can retrieve a list, in case there are multiple. It would have been nice to use the __getitem__ interface, but it is already used for another purpose. Fixes: kbandla#165
So I really like @obormot suggestion on #165 to use the contains and getitem methods, which would mean this kind of intuitive usage.
Right now dpkt.py already overloads the getitem method for getting an attribute...
I don't actually like the the current getitem functionality. dpkt has attribute based classes and that's how everyone uses it. So retrieving the attributes with a 'dictionary' interface just muddies the waters (BTW: all 132 dpkt tests pass fine without the getitem interface). This is a big change, so I'll like @kbandla and @obormot to weigh in here, but for my $0.02 I'm going to suggest something mildly radical.
Also no matter what we do I don't like the 'getall' functionality, it seems superfluous and I feel like code using it will want to know/differentiate between the 'outer' IP packet and the 'inner' IP packet, so for example.. I feel like this snippet below is intuitive and natural, I'm not sure how I would code this up with a list of 2 IPs from getall()
|
@brifordwylie I agree completely, this is how scapy does it BTW. I think we want
|
Using the new .get() method you can quickly find the IP layer in a packet.
With the .getall() method you can retrieve a list, in case there are
multiple.
It would have been nice to use the getitem interface, but it is already
used for another purpose.
Fixes: #165