Base Class

pcapkit.foundation.reassembly.reassembly contains Reassembly only, which is an abstract base class for all reassembly classes, bases on algorithms described in RFC 791 and RFC 815, implements datagram reassembly of IP and TCP packets.

class pcapkit.foundation.reassembly.reassembly.Reassembly(*, strict=True)[source]

Bases: Generic[PT, DT, IT, BT]

Base class for reassembly procedure.

Parameters
  • strict (bool) – if return all datagrams (including those not implemented) when submit

  • *args (Any) – Arbitrary positional arguments.

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

Return type

Reassembly[PT, DT, IT, BT]

__init__(*, strict=True)[source]

Initialise packet reassembly.

Parameters

strict (bool) – if return all datagrams (including those not implemented) when submit

Return type

None

__call__(packet)[source]

Call packet reassembly.

Parameters

packet (TypeVar(PT, bound= Info)) – packet dict to be reassembled (detailed format described in corresponding protocol)

Return type

None

abstract property name: str

Protocol name of current reassembly object.

Return type

str

property count: int

Total number of reassembled packets.

Return type

int

property datagram: tuple[DT, ...]

Reassembled datagram.

abstract property protocol: Type[Protocol]

Protocol of current reassembly object.

Return type

Type[Protocol]

abstract reassembly(info)[source]

Reassembly procedure.

Parameters

info (TypeVar(PT, bound= Info)) – info dict of packets to be reassembled

Return type

None

abstract submit(buf, **kwargs)[source]

Submit reassembled payload.

Parameters
  • buf (BT) – buffer dict of reassembled packets

  • **kwargs (Any) – arbitrary keyword arguments

Return type

list[DT]

fetch()[source]

Fetch datagram.

Returns

Tuple of reassembled datagrams.

Return type

tuple[DT, …]

Fetch reassembled datagrams from _dtgram and returns a tuple of such datagrams.

If no cache found, the method will call submit() to forcedly obtain newly reassembled payload. Otherwise, the already calculated _dtgram will be returned.

index(pkt_num)[source]

Return datagram index.

Parameters

pkt_num (int) – index of packet

Return type

Optional[int]

Returns

Reassembled datagram index which was from No. pkt_num packet; if not found, returns None.

run(packets)[source]

Run automatically.

Parameters

packets (list[PT]) – list of packet dicts to be reassembled

Return type

None

_buffer: dict[IT, BT]

Dict buffer field.

Type

dict[IT, BT]

_dtgram: list[DT]

List reassembled datagram.

Type

list[DT]