Politician 1.0.0
WiFi Auditing Library for ESP32
Loading...
Searching...
No Matches
politician::storage::PcapngFileLogger Class Reference

Helper for writing HandshakeRecords and raw packets to a standard PCAPNG file. More...

#include <PoliticianStorage.h>

Public Member Functions

 PcapngFileLogger ()
 
 ~PcapngFileLogger ()
 
bool open (fs::FS &fs, const char *path)
 Opens the PCAPNG file for streaming writes.
 
bool write (const HandshakeRecord &rec)
 Writes a HandshakeRecord to the open file.
 
bool writePacket (const uint8_t *payload, uint16_t len, int8_t rssi, uint8_t channel, uint32_t ts_usec)
 Writes a raw 802.11 sniffer frame to the open file.
 
void close ()
 Closes the underlying file handle.
 
bool isOpen () const
 Returns true if the file is currently open for streaming.
 

Static Public Member Functions

static bool append (fs::FS &fs, const char *path, const HandshakeRecord &rec)
 Appends a HandshakeRecord to a file as PCAPNG (opens and closes per call).
 
static bool appendPacket (fs::FS &fs, const char *path, const uint8_t *payload, uint16_t len, int8_t rssi, uint8_t channel, uint32_t ts_usec)
 Appends a raw 802.11 sniffer frame to a PCAPNG file (opens and closes per call).
 

Detailed Description

Helper for writing HandshakeRecords and raw packets to a standard PCAPNG file.

Two usage modes:

  • Streaming (recommended for continuous capture): call open() once, write()/writePacket() repeatedly, then close(). The file handle stays open across writes, avoiding repeated open/close overhead and SD wear.
  • One-shot (legacy): use the static append() / appendPacket() helpers which open and close the file on every call.

Definition at line 44 of file PoliticianStorage.h.

Constructor & Destructor Documentation

◆ PcapngFileLogger()

politician::storage::PcapngFileLogger::PcapngFileLogger ( )
inline

Definition at line 46 of file PoliticianStorage.h.

◆ ~PcapngFileLogger()

politician::storage::PcapngFileLogger::~PcapngFileLogger ( )
inline

Definition at line 48 of file PoliticianStorage.h.

References close().

Member Function Documentation

◆ append()

static bool politician::storage::PcapngFileLogger::append ( fs::FS &  fs,
const char *  path,
const HandshakeRecord rec 
)
inlinestatic

Appends a HandshakeRecord to a file as PCAPNG (opens and closes per call).

Prefer the streaming API (open/write/close) for continuous capture.

Definition at line 118 of file PoliticianStorage.h.

References open(), and write().

◆ appendPacket()

static bool politician::storage::PcapngFileLogger::appendPacket ( fs::FS &  fs,
const char *  path,
const uint8_t *  payload,
uint16_t  len,
int8_t  rssi,
uint8_t  channel,
uint32_t  ts_usec 
)
inlinestatic

Appends a raw 802.11 sniffer frame to a PCAPNG file (opens and closes per call).

Prefer the streaming API (open/writePacket/close) for continuous capture.

Definition at line 127 of file PoliticianStorage.h.

References open(), and writePacket().

◆ close()

void politician::storage::PcapngFileLogger::close ( )
inline

Closes the underlying file handle.

Safe to call multiple times.

Definition at line 105 of file PoliticianStorage.h.

Referenced by open(), and ~PcapngFileLogger().

◆ isOpen()

bool politician::storage::PcapngFileLogger::isOpen ( ) const
inline

Returns true if the file is currently open for streaming.

Definition at line 110 of file PoliticianStorage.h.

◆ open()

bool politician::storage::PcapngFileLogger::open ( fs::FS &  fs,
const char *  path 
)
inline

Opens the PCAPNG file for streaming writes.

Writes the global Section Header Block if the file is new or empty.

Parameters
fsThe filesystem (e.g., SD, LittleFS)
pathThe file path (e.g., "/captures.pcapng")
Returns
true if the file was opened successfully

Definition at line 58 of file PoliticianStorage.h.

References close(), and politician::format::writePcapngGlobalHeader().

Referenced by append(), and appendPacket().

◆ write()

bool politician::storage::PcapngFileLogger::write ( const HandshakeRecord rec)
inline

Writes a HandshakeRecord to the open file.

Returns
true if data was written, false if the logger is not open or serialization failed

Definition at line 84 of file PoliticianStorage.h.

References politician::format::writePcapngRecord().

Referenced by append().

◆ writePacket()

bool politician::storage::PcapngFileLogger::writePacket ( const uint8_t *  payload,
uint16_t  len,
int8_t  rssi,
uint8_t  channel,
uint32_t  ts_usec 
)
inline

Writes a raw 802.11 sniffer frame to the open file.

Returns
true if data was written, false if the logger is not open or serialization failed

Definition at line 96 of file PoliticianStorage.h.

References politician::format::writePcapngPacket().

Referenced by appendPacket().


The documentation for this class was generated from the following file: