libDwm-0.9.45
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.
 
int SetBufferSize (int bufferSize)
 
bool OpenLive (const std::string &device, int snaplen, bool promisc, int timeout_msecs)
 Open device for live packet capture.
 
bool SetDirection (pcap_direction_t direction)
 Specify whether to capture incoming packets, outgoing packets, or both.
 
bool OpenOffline (const std::string &fname)
 Opens the file fname for reading.
 
bool SetFilter (const std::string &filter, bool optimize)
 Sets the filter for the capture device.
 
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.
 
void BreakLoop ()
 A wrapper for pcap_breakloop().
 
bool Close ()
 Closes the capture device.
 
const std::string & LastError () const
 Returns the last error string from a failed OpenLive() or OpenOffline() call.
 
int DataLinkOffset () const
 Returns the length of the link layer header for the capture device.
 

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.

◆ 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.

◆ SetDirection()

bool Dwm::Pcap::SetDirection ( pcap_direction_t direction)

Specify whether to capture incoming packets, outgoing packets, or both.

See the pcap(3) manpage for details. Returns true on success, false on failure. Note this function is only supported for live packet captures.

◆ 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: