Returns the packet list from a given layer. See ``Packet.getlayer`` for more info. :param cls: search for a layer that is an instance of ``cls`` :type cls: Type[scapy.packet.Packet] :param nb: return the nb^th layer that is an instance of ``cls`` :type nb:
(self, cls, # type: Packet
nb=None, # type: Optional[int]
flt=None, # type: Optional[Dict[str, Any]]
name=None, # type: Optional[str]
stats=None # type: Optional[List[Type[Packet]]]
)
| 690 | return x |
| 691 | |
| 692 | def getlayer(self, cls, # type: Packet |
| 693 | nb=None, # type: Optional[int] |
| 694 | flt=None, # type: Optional[Dict[str, Any]] |
| 695 | name=None, # type: Optional[str] |
| 696 | stats=None # type: Optional[List[Type[Packet]]] |
| 697 | ): |
| 698 | # type: (...) -> PacketList |
| 699 | """Returns the packet list from a given layer. |
| 700 | |
| 701 | See ``Packet.getlayer`` for more info. |
| 702 | |
| 703 | :param cls: search for a layer that is an instance of ``cls`` |
| 704 | :type cls: Type[scapy.packet.Packet] |
| 705 | |
| 706 | :param nb: return the nb^th layer that is an instance of ``cls`` |
| 707 | :type nb: Optional[int] |
| 708 | |
| 709 | :param flt: filter parameters for ``Packet.getlayer`` |
| 710 | :type flt: Optional[Dict[str, Any]] |
| 711 | |
| 712 | :param name: optional name for the new PacketList |
| 713 | :type name: Optional[str] |
| 714 | |
| 715 | :param stats: optional list of protocols to give stats on; if not |
| 716 | specified, inherits from this PacketList. |
| 717 | :type stats: Optional[List[Type[scapy.packet.Packet]]] |
| 718 | :rtype: scapy.plist.PacketList |
| 719 | """ |
| 720 | if name is None: |
| 721 | name = "{} layer {}".format(self.listname, cls.__name__) |
| 722 | if stats is None: |
| 723 | stats = self.stats |
| 724 | |
| 725 | getlayer_arg = {} # type: Dict[str, Any] |
| 726 | if flt is not None: |
| 727 | getlayer_arg.update(flt) |
| 728 | getlayer_arg['cls'] = cls |
| 729 | if nb is not None: |
| 730 | getlayer_arg['nb'] = nb |
| 731 | |
| 732 | # Only return non-None getlayer results |
| 733 | return PacketList([ |
| 734 | pc for pc in ( |
| 735 | self._elt2pkt(p).getlayer(**getlayer_arg) for p in self.res |
| 736 | ) if pc is not None], |
| 737 | name, stats |
| 738 | ) |
| 739 | |
| 740 | |
| 741 | class PacketList(_PacketList[Packet], |