PCAP-NG Dumper¶
pcapkit.dumpkit.pcapng is the dumper for the PCAP-NG format, like those in
dictdumper.
- class pcapkit.dumpkit.pcapng.PCAPNGIO(fname, *, protocol=None, byteorder=sys.byteorder, nanosecond=False, snaplen=0, **kwargs)[source]¶
Bases:
DumperBasePCAP-NG file dumper.
It writes one Section Header Block, an Interface Description Block for each distinct interface, and an Enhanced Packet Block per frame.
- Parameters:
fname (
str) – output file nameprotocol (
LinkType|IntEnum|aenum.IntEnum|str|int|None) – data link type of a frame that names no interfacebyteorder (
Literal['big','little']) – section byte ordernanosecond (
bool) – nanosecond-resolution flag of that frame’s interfacesnaplen (
int) – snapshot length of that frame’s interface,0for no limit**kwargs (
Any) – arbitrary keyword arguments
Added in version 1.7.0.
Properties
Data Models
- __init__(fname, *, protocol=None, byteorder=sys.byteorder, nanosecond=False, snaplen=0, **kwargs)[source]¶
Initialise dumper.
- Parameters:
fname (
str) – output file nameprotocol (
LinkType|IntEnum|aenum.IntEnum|str|int|None) – data link type of a frame that names no interfacebyteorder (
Literal['big','little']) – section byte ordernanosecond (
bool) – nanosecond-resolution flag of that frame’s interfacesnaplen (
int) – snapshot length of that frame’s interface,0for no limit**kwargs (
Any) – arbitrary keyword arguments
Methods
Utilities
- _append_value(value, file, name)[source]¶
Call this function to write contents.
- Parameters:
Notes
valueis one of:a PCAP-NG block, as the
PCAPNGengine hands it: a packet block – EPB, SPB or obsolete Packet Block – is written as an EPB with its own options, an Interface Description Block as itself, and any other block not at all;a frame, written as an EPB on the interface
block2frame()kept, with the block’s options, or else on one ofprotocol,snaplenandnanosecond;a PCAP global header, not written.
An interface is written before the first block on it, and those whose IDBs would be the same octets share one. Each keeps its options,
if_tsresolandif_tsoffsetamong them, so timestamps are written exactly. Captured Packet Length is the octets written, as forPCAPIO._append_value.Every block is made by
PCAPNG.make; an EPB is packed byPCAPNG.packalone, without dissecting the frame again.
- _interface_id(file, interface)[source]¶
Interface ID of an interface in the output, writing its IDB if new.
- Parameters:
interface (
InterfaceDescriptionBlock|None) – the interface, orNonefor the one ofprotocol,snaplenandnanosecond
- Return type:
- Returns:
Index of the interface’s IDB in the output section.
- Raises:
FormatError – If
interfaceisNoneand the dumper was given noprotocol.