34 std::expected<void, std::string>
open(
const std::filesystem::path& path);
37 std::expected<void, std::string>
write(int64_t timestampNs, std::span<const uint8_t>
bytes);
43 std::FILE* file_ =
nullptr;
51std::expected<std::vector<Record>, std::string>
parsePcap(std::span<const uint8_t>
bytes);
55std::expected<std::vector<Record>, std::string>
readPcap(
const std::filesystem::path& path);
Writes records to a pcap file as they arrive.
Definition pcap.h:26
~PcapWriter()
Definition pcap.cc:45
std::expected< void, std::string > write(int64_t timestampNs, std::span< const uint8_t > bytes)
Appends one frame.
Definition pcap.cc:68
PcapWriter & operator=(const PcapWriter &)=delete
std::expected< void, std::string > open(const std::filesystem::path &path)
Creates path and writes the file header, with nanosecond timestamps.
Definition pcap.cc:47
PcapWriter(const PcapWriter &)=delete
void close()
Flushes and closes the file. Called by the destructor when not called before.
Definition pcap.cc:85
std::expected< std::vector< Record >, std::string > parsePcap(std::span< const uint8_t > bytes)
Reads every record of a pcap file held in memory.
Definition pcap.cc:92
std::expected< std::vector< Record >, std::string > readPcap(const std::filesystem::path &path)
Reads every record of a pcap file into memory. See parsePcap for what is accepted.
Definition pcap.cc:133
std::size_t bytes
Definition spoe_connection.cc:24
One captured frame.
Definition pcap.h:20
int64_t timestampNs
Nanoseconds since the Unix epoch, from the kernel.
Definition pcap.h:21
std::vector< uint8_t > bytes
The frame from the Ethernet header on.
Definition pcap.h:22