libDwm-0.6.0
Dwm::Pcap Class Reference

This is a pcap wrapper/utility class. More...

#include <DwmPcap.hh>

Public Member Functions

 Pcap ()
 Constructor.
 
 ~Pcap ()
 Destructor. Will close the contained pcap device if it's open.
 
bool OpenLive (const std::string &device, int snaplen, bool promisc, int timeout_msecs)
 Open device for live packet capture. More...
 
bool OpenOffline (const std::string &fname)
 Opens the file fname for reading. More...
 
bool SetFilter (const std::string &filter, bool optimize)
 Sets the filter for the capture device. More...
 
int Dispatch (int count, pcap_handler callback, uint8_t *user)
 A wrapper for pcap_dispatch(). See the pcap(3) manpage.
 
int Loop (int count, pcap_handler callback, uint8_t *user)
 A wrapper for pcap_loop(). See the pcap(3) manpage.
 
bool Close ()
 Closes the capture device. More...
 
const std::string & LastError () const
 Returns the last error string from a failed OpenLive() or OpenOffline() call. More...
 
int DataLinkOffset () const
 Returns the length of the link layer header for the capture device. More...
 

Detailed Description

This is a pcap wrapper/utility class.

Member Function Documentation

◆ Close()

bool Dwm::Pcap::Close ( )

Closes the capture device.

Returns true if the device was open, false if it was already closed.

◆ DataLinkOffset()

int Dwm::Pcap::DataLinkOffset ( ) const

Returns the length of the link layer header for the capture device.

This lets us skip over it to get to the network layer. Returns -1 if we don't know the length of the link layer header.

◆ LastError()

const std::string& Dwm::Pcap::LastError ( ) const

Returns the last error string from a failed OpenLive() or OpenOffline() call.

◆ OpenLive()

bool Dwm::Pcap::OpenLive ( const std::string &  device,
int  snaplen,
bool  promisc,
int  timeout_msecs 
)

Open device for live packet capture.

Will capture no more than snaplen from each packet. Will set the device in promiscuous mode if promisc is true. timeout_msecs specifies the read timeout in milliseconds. See the pcap(3) manpage for details. Returns true on success, false on failure.

◆ OpenOffline()

bool Dwm::Pcap::OpenOffline ( const std::string &  fname)

Opens the file fname for reading.

Returns true on success, false on failure.

◆ SetFilter()

bool Dwm::Pcap::SetFilter ( const std::string &  filter,
bool  optimize 
)

Sets the filter for the capture device.

filter is the usual pcap filter string syntax. If optimize is true, the resulting compiled filter will be optimized.


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