Class PcapReader

Inheritance Relationships

Derived Type

Class Documentation

class PcapReader

Class for dealing with reading pcap files.

Subclassed by ouster::sdk::pcap::IndexedPcapReader

Public Functions

explicit PcapReader(const std::string &file)
Parameters:

file[in] – A filepath of the pcap to read

PcapReader(const PcapReader &other) = delete
PcapReader(PcapReader &&other)

Move construct from one PcapReader to a new PcapReader.

Parameters:

other[in] – The other PcapReader to move from.

PcapReader &operator=(PcapReader &other) = delete
PcapReader &operator=(PcapReader &&other)

Assign move resources from one PcapReader to another.

Parameters:

other[in] – The other PcapReader to move from.

virtual ~PcapReader()

Destructor for cleaning up after PcapReader.

size_t next_packet()

Advances to the next packet and returns the size of that packet.

Will also populate data and info for next_packet(), current_data(), current_length(), and current_info()

Returns:

The size of the packet payload

const uint8_t *current_data() const

Return the current packets data.

To advance to a new packet please use next_packet() To get the size of the data use current_length()

Returns:

A pointer to a byte array containing the packet data

size_t current_length() const

Return the current packets data size.

To advance to a new packet please use next_packet()

Returns:

The size of the byte array

const PacketInfo &current_info() const

Return the current packets info.

To advance to a new packet please use next_packet()

Returns:

A packet_info object on the current packet

int64_t file_size() const
Returns:

The size of the PCAP file in bytes

void reset()

Return the read position to the start of the PCAP file.

void seek(uint64_t offset)

Seek to the position in the file represented by the number of bytes from the beginning of the file.

Parameters:

offset[in] – The position to seek to in bytes, starting from the beginning of the file.

Pre:

offset must be the offset of a PCAP record header. If any other value is provided, subsequent packet reads from this PcapReader will be invalid until PcapReader::reset is called.

int64_t current_offset() const
Throws:

std::runtime_error – if ftell() or fclose() fails.

Returns:

The current read position (in bytes) within the PCAP file stream.