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)#

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]

abstract property name: str#

Protocol name of current reassembly object.

property count: int#

Total number of reassembled packets.

property datagram: tuple[DT, ...]#

Reassembled datagram.

abstract property protocol: Type[Protocol]#

Protocol of current reassembly object.

abstract reassembly(info)#

Reassembly procedure.

Parameters:

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

Return type:

None

abstract submit(buf, **kwargs)#

Submit reassembled payload.

Parameters:
  • buf (TypeVar(BT, bound= Info)) – buffer dict of reassembled packets

  • **kwargs (Any) – arbitrary keyword arguments

Return type:

list[TypeVar(DT, bound= Info)]

fetch()#

Fetch datagram.

Return type:

tuple[TypeVar(DT, bound= Info), ...]

Returns:

Tuple of reassembled datagrams.

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)#

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)#

Run automatically.

Parameters:

packets (list[TypeVar(PT, bound= Info)]) – list of packet dicts to be reassembled

Return type:

None

_buffer: dict[TypeVar(IT, bound= tuple), TypeVar(BT, bound= Info)]#

Dict buffer field.

Type:

dict[IT, BT]

_dtgram: list[TypeVar(DT, bound= Info)]#

List reassembled datagram.

Type:

list[DT]

_strflg: bool#

Strict mode flag.

Type:

bool

_newflg: bool#

New datagram flag.

Type:

bool

__call__(packet)#

Call packet reassembly.

Parameters:

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

Return type:

None