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: Protocol[PT], Generic[PT]

Abstract base class for transport layer protocol family.

Parameters
  • *args (Any) – Arbitrary positional arguments.

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

Return type

Protocol[PT]

property layer: Literal['Transport']

Protocol layer.

Return type

Literal[‘Transport’]

classmethod register(code, module, class_)[source]

Register a new protocol class.

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.

Parameters
  • code (int) – port number

  • module (str) – module name

  • class – class name

  • class_ (str) –

Return type

None

Notes

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

Return type

None

Parameters
  • code (int) –

  • module (str) –

  • class_ (str) –

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.

Returns

Parsed payload as a Protocol instance.

Return type

Protocol

_decode_next_layer(dict_, ports, length=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
  • dict – info buffer

  • ports (tuple[int, int]) – source & destination port numbers

  • length (Optional[int]) – valid (non-padding) length

  • dict_ (PT) –

Returns

Current protocol with next layer extracted.

Return type

PT

__layer__: Optional[Literal['Link', 'Internet', 'Transport', 'Application']] = 'Transport'

Layer of protocol.

__proto__: DefaultDict[int, tuple[str, str]]

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.