SatCat5
satcat5::io::WritePcap Class Reference

Detailed Description

Store packet stream to a file.

Definition at line 88 of file file_pcap.h.

#include <file_pcap.h>

Inheritance diagram for satcat5::io::WritePcap:
[legend]
Collaboration diagram for satcat5::io::WritePcap:
[legend]

Public Member Functions

 WritePcap (bool pcapng=true)
 Create the capture object and set PCAP or PCAPNG mode. More...
 
void close ()
 Close the current file, if any.
 
u32 add_interface (const char *name, u16 type=LINKTYPE_ETHERNET)
 Write a new interface description block (PCAPNG only). More...
 
void set_interface (u32 id)
 Set interface ID number for the next call to write_finalize. More...
 
void set_passthrough (satcat5::io::Writeable *wr)
 Passthrough mode carbon-copies each packet to another Writeable object, using the internal working buffer.
 
bool write_finalize () override
 Override end-of-packet handling.
 
unsigned get_write_space () const override
 How many bytes can be written without blocking? More...
 
void write_abort () override
 If possible, abort the current partially-written packet. More...
 
void write_overflow () override
 Optional error handling for write overflow. More...
 
const u8 * buffer () const
 Read-only access to the working buffer.
 
unsigned written_len () const
 Report total length after write_finalize() is called.
 
void write_u8 (u8 data)
 One of many functions for writing integer/floating point values, see details. More...
 
virtual void write_bytes (unsigned nbytes, const void *src)
 Write 0 or more bytes from a buffer. More...
 
void write_str (const char *str)
 Write the contents of a null-terminated string. More...
 
template<class T >
void write_obj (const T &obj)
 Templated wrapper for any object with the following method: void write_to(satcat5::io::Writeable* wr) const;
 
void open (const char *filename, u16 type=LINKTYPE_ETHERNET)
 Open the specified file, and optionally specify LinkType.
 
void open (const std::string &filename, u16 type=LINKTYPE_ETHERNET)
 Open the specified file, and optionally specify LinkType.
 

Protected Attributes

satcat5::datetime::Clock m_clock
 
satcat5::io::FileWriter m_file
 
satcat5::io::Writeablem_pass
 
const bool m_mode_ng
 
u32 m_interface_count
 
u32 m_interface_next
 
u8 m_buff [SATCAT5_PCAP_BUFFSIZE]
 
friend LimitedWrite
 
friend WriteableBroadcast
 
friend WriteableRedirect
 

Private Member Functions

void write_next (u8 data) override
 Write the next byte to the underlying buffer or device. More...
 

Private Attributes

u8 *const m_dst
 
const unsigned m_len
 
bool m_ovr
 
unsigned m_wridx
 
unsigned m_wrlen
 

Constructor & Destructor Documentation

◆ WritePcap()

WritePcap::WritePcap ( bool  pcapng = true)
explicit

Create the capture object and set PCAP or PCAPNG mode.

Timestamps are drawn from the system time by default, or from a user-provided timer for simulations.

Definition at line 274 of file file_pcap.cc.

Member Function Documentation

◆ add_interface()

u32 WritePcap::add_interface ( const char *  name,
u16  type = LINKTYPE_ETHERNET 
)

Write a new interface description block (PCAPNG only).

An interface description block is required for each capture interface. The default (ID = 0) is created by open.

Returns
The interface-ID for the newly-created interface.

Definition at line 317 of file file_pcap.cc.

◆ get_write_space()

unsigned ArrayWrite::get_write_space ( ) const
overridevirtualinherited

How many bytes can be written without blocking?

Child objects of io::Writeable MUST override this method.

Implements satcat5::io::Writeable.

Definition at line 189 of file io_writeable.cc.

◆ set_interface()

void satcat5::io::WritePcap::set_interface ( u32  id)
inline

Set interface ID number for the next call to write_finalize.

Interfaces with ID > 0 must call this method for each frame.

Definition at line 114 of file file_pcap.h.

◆ write_abort()

void ArrayWrite::write_abort ( )
overridevirtualinherited

If possible, abort the current partially-written packet.

Child objects of io::Writeable SHOULD override this method if it is practical to prevent in-progress data from being relayed downstream.

Reimplemented from satcat5::io::Writeable.

Definition at line 193 of file io_writeable.cc.

◆ write_bytes()

void Writeable::write_bytes ( unsigned  nbytes,
const void *  src 
)
virtualinherited

◆ write_next()

void ArrayWrite::write_next ( u8  data)
overrideprivatevirtualinherited

Write the next byte to the underlying buffer or device.

Child objects of io::Writeable MUST override this method.

Implements satcat5::io::Writeable.

Definition at line 211 of file io_writeable.cc.

◆ write_overflow()

void ArrayWrite::write_overflow ( )
overridevirtualinherited

Optional error handling for write overflow.

Child objects of io::Writeable MAY override this method for error handling.

Reimplemented from satcat5::io::Writeable.

Definition at line 207 of file io_writeable.cc.

◆ write_str()

void Writeable::write_str ( const char *  str)
inherited

Write the contents of a null-terminated string.

Note: Null-termination is not copied to the output.

Definition at line 180 of file io_writeable.cc.

◆ write_u8()

void Writeable::write_u8 ( u8  data)
inherited

One of many functions for writing integer/floating point values, see details.

Several functions are provided for reading and writing scalar types to/from io::Readable and io::Writeable instances. Since there are many of these that are frequently inherited, they are hidden from documentation. These functions follow a shared template:

  • read_ or write_ prefix.
  • u for unsigned, s for signed, f for floating-point.
  • Data-type width in bits.
    • Available widths for ints: 8/16/24/32/48/64.
    • Available widths for floats: 32/64.
  • l suffix if little-endian, no suffix if big-endian.

Example: write_s48l is "Write 48 bits (6 bytes) to this io::Writeable as a signed value in little-endian order".

Definition at line 20 of file io_writeable.cc.


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