Miscellaneous Protocols

Raw Packet Data

pcapkit.protocols.raw contains Raw only, which implements extractor for unknown protocol, and constructs a Protocol like object.

class pcapkit.protocols.raw.Raw(file=None, length=None, **kwargs)[source]

Bases: pcapkit.protocols.protocol.Protocol

This class implements universal unknown protocol.

classmethod __index__()[source]

Numeral registry index of the protocol.

Raises

UnsupportedCall – This protocol has no registry entry.

__post_init__(file, length=None, *, error=None, **kwargs)[source]

Post initialisation hook.

Parameters
  • file (io.BytesIO) – Source packet stream.

  • length (Optional[int]) – Length of packet data.

Keyword Arguments
  • error (Optional[str]) – Parsing errors if any (for parsing).

  • **kwargs – Arbitrary keyword arguments.

Would pcapkit encounter malformed packets, the original parsing error message will be provided as in error.

See also

For construction argument, please refer to make().

make(**kwargs)[source]

Make raw packet data.

Keyword Arguments
  • packet (bytes) – Raw packet data.

  • **kwargs – Arbitrary keyword arguments.

Returns

Constructed packet data.

Return type

bytes

read(length=None, *, error=None, **kwargs)[source]

Read raw packet data.

Parameters

length (Optional[int]) – Length of packet data.

Keyword Arguments
  • error (Optional[str]) – Parsing errors if any.

  • **kwargs – Arbitrary keyword arguments.

Returns

The parsed packet data.

Return type

DataType_Raw

property length

Header length of current protocol.

Raises

UnsupportedCall – This protocol doesn’t support length.

property name

Name of current protocol.

Return type

Literal[‘Unknown’]

property protocol

Name of next layer protocol.

Raises

UnsupportedCall – This protocol doesn’t support protocol.

Data Structure

Important

Following classes are only for documentation purpose. They do NOT exist in the pcapkit module.

class pcapkit.protocols.raw.DataType_Raw
Bases

TypedDict

Raw packet data.

packet: bytes

raw packet data

error: Optional[str]

optional error message

No-Payload Packet

pcapkit.protocols.null contains NoPayload only, which implements a Protocol like object whose payload is recursively NoPayload itself.

class pcapkit.protocols.null.NoPayload(file=None, length=None, **kwargs)[source]

Bases: pcapkit.protocols.protocol.Protocol

This class implements no-payload protocol.

classmethod __index__()[source]

Numeral registry index of the protocol.

Raises

UnsupportedCall – This protocol has no registry entry.

__post_init__(file=None, length=None, **kwargs)[source]

Post initialisation hook.

Parameters
  • file (Optional[io.BytesIO]) – Source packet stream.

  • length (Optional[int]) – Length of packet data.

Keyword Arguments

**kwargs – Arbitrary keyword arguments.

_decode_next_layer(*args, **kwargs)[source]

Decode next layer protocol.

Parameters

*args – arbitrary positional arguments

Keyword Arguments

**kwargs – arbitrary keyword arguments

Raises

UnsupportedCall – This protocol doesn’t support _decode_next_layer().

_import_next_layer(*args, **kwargs)[source]

Import next layer extractor.

Parameters

*args – arbitrary positional arguments

Keyword Arguments

**kwargs – arbitrary keyword arguments

Raises

UnsupportedCall – This protocol doesn’t support _import_next_layer().

make(**kwargs)[source]

Make (construct) packet data.

Keyword Arguments

**kwargs – Arbitrary keyword arguments.

Returns

Constructed packet data.

Return type

bytes

read(length=None, **kwargs)[source]

Read (parse) packet data.

Parameters

length (Optional[int]) – Length of packet data.

Keyword Arguments

**kwargs – Arbitrary keyword arguments.

Returns

Parsed packet data.

Return type

dict

property length

Header length of current protocol.

Raises

UnsupportedCall – This protocol doesn’t support length.

property name

Name of current protocol.

Return type

Literal[‘Null’]

property protocol

Name of next layer protocol.

Raises

UnsupportedCall – This protocol doesn’t support protocol.