PacketListField represents a list containing a series of Packet instances that might occur right in the middle of another Packet field. This field type may also be used to indicate that a series of Packet instances have a sibling semantic instead of a parent/child relationship (i.e.
| 1620 | |
| 1621 | |
| 1622 | class PacketListField(_PacketField[List[BasePacket]]): |
| 1623 | """PacketListField represents a list containing a series of Packet instances |
| 1624 | that might occur right in the middle of another Packet field. |
| 1625 | This field type may also be used to indicate that a series of Packet |
| 1626 | instances have a sibling semantic instead of a parent/child relationship |
| 1627 | (i.e. a stack of layers). All elements in PacketListField have current |
| 1628 | packet referenced in parent field. |
| 1629 | """ |
| 1630 | __slots__ = ["count_from", "length_from", "next_cls_cb", "max_count"] |
| 1631 | islist = 1 |
| 1632 | |
| 1633 | def __init__( |
| 1634 | self, |
| 1635 | name, # type: str |
| 1636 | default, # type: Optional[List[BasePacket]] |
| 1637 | pkt_cls=None, # type: Optional[Union[Callable[[bytes], Packet], Type[Packet]]] # noqa: E501 |
| 1638 | count_from=None, # type: Optional[Callable[[Packet], int]] |
| 1639 | length_from=None, # type: Optional[Callable[[Packet], int]] |
| 1640 | next_cls_cb=None, # type: Optional[Callable[[Packet, List[BasePacket], Optional[Packet], bytes], Optional[Type[Packet]]]] # noqa: E501 |
| 1641 | max_count=None, # type: Optional[int] |
| 1642 | ): |
| 1643 | # type: (...) -> None |
| 1644 | """ |
| 1645 | The number of Packet instances that are dissected by this field can |
| 1646 | be parametrized using one of three different mechanisms/parameters: |
| 1647 | |
| 1648 | * count_from: a callback that returns the number of Packet |
| 1649 | instances to dissect. The callback prototype is:: |
| 1650 | |
| 1651 | count_from(pkt:Packet) -> int |
| 1652 | |
| 1653 | * length_from: a callback that returns the number of bytes that |
| 1654 | must be dissected by this field. The callback prototype is:: |
| 1655 | |
| 1656 | length_from(pkt:Packet) -> int |
| 1657 | |
| 1658 | * next_cls_cb: a callback that enables a Scapy developer to |
| 1659 | dynamically discover if another Packet instance should be |
| 1660 | dissected or not. See below for this callback prototype. |
| 1661 | |
| 1662 | The bytes that are not consumed during the dissection of this field |
| 1663 | are passed to the next field of the current packet. |
| 1664 | |
| 1665 | For the serialization of such a field, the list of Packets that are |
| 1666 | contained in a PacketListField can be heterogeneous and is |
| 1667 | unrestricted. |
| 1668 | |
| 1669 | The type of the Packet instances that are dissected with this field is |
| 1670 | specified or discovered using one of the following mechanism: |
| 1671 | |
| 1672 | * the pkt_cls parameter may contain a callable that returns an |
| 1673 | instance of the dissected Packet. This may either be a |
| 1674 | reference of a Packet subclass (e.g. DNSRROPT in layers/dns.py) |
| 1675 | to generate an homogeneous PacketListField or a function |
| 1676 | deciding the type of the Packet instance |
| 1677 | (e.g. _CDPGuessAddrRecord in contrib/cdp.py) |
| 1678 | |
| 1679 | * the pkt_cls parameter may contain a class object with a defined |
no outgoing calls
no test coverage detected