Base Protocol#

pcapkit.protocols.transport.transport contains Transport, which is a base class for transport layer protocols, eg. TCP and UDP.

class pcapkit.protocols.transport.transport.Transport(file=None, length=None, **kwargs)[source]#

Bases: ProtocolBase[_PT, _ST], Generic[_PT, _ST]

Abstract base class for transport layer protocol family.

property layer: Literal['Transport']#

Protocol layer.

classmethod register(code, protocol)[source]#

Register a new protocol class.

Notes

The full qualified class name of the new protocol class should be as {protocol.module}.{protocol.name}.

Parameters:
Return type:

None

Important

This method must be called from a non-abstract class, as the protocol map should be associated directly with specific transport layer protocol type.

classmethod analyze(ports, payload, **kwargs)[source]#

Analyse packet payload.

Parameters:
  • ports (tuple[int, int]) – Source & destination port numbers.

  • payload (bytes) – Packet payload.

  • **kwargs (Any) – Arbitrary keyword arguments.

Return type:

ProtocolBase

Returns:

Parsed payload as a Protocol instance.

_decode_next_layer(dict_, ports, length=None, *, packet=None)[source]#

Decode next layer protocol.

The method will check if the next layer protocol is supported based on the source and destination port numbers. We will use the lower port number from both ports as the primary key to lookup the next layer.

Parameters:
Return type:

TypeVar(_PT, bound= Data)

Returns:

Current protocol with next layer extracted.

__layer__: Literal['Transport']#

Layer of protocol.

__proto__: DefaultDict[int, ModuleDescriptor[Protocol] | Type[Protocol]]#

Protocol index mapping for decoding next layer, c.f. self._decode_next_layer & self._import_next_layer.

Important

The attribute must be defined and maintained in subclass.