libtins  3.4
 All Classes Namespaces Functions Variables Typedefs Enumerations Enumerator Friends Pages
Public Types | Public Member Functions | Friends | List of all members
Tins::Sniffer Class Reference

Sniffs packets from a network interface. More...

#include <sniffer.h>

Inheritance diagram for Tins::Sniffer:
Tins::BaseSniffer

Public Types

enum  promisc_type { NON_PROMISC, PROMISC }
 
- Public Types inherited from Tins::BaseSniffer
typedef SnifferIterator iterator
 

Public Member Functions

 Sniffer (const std::string &device, const SnifferConfiguration &configuration)
 Constructs an instance of Sniffer using the provided configuration. More...
 
 Sniffer (const std::string &device, unsigned max_packet_size, bool promisc=false, const std::string &filter="", bool rfmon=false)
 Constructs an instance of Sniffer. More...
 
 Sniffer (const std::string &device, promisc_type promisc=NON_PROMISC, const std::string &filter="", bool rfmon=false)
 Constructs an instance of Sniffer. More...
 
- Public Member Functions inherited from Tins::BaseSniffer
 BaseSniffer (BaseSniffer &&rhs) TINS_NOEXCEPT
 Move constructor. This constructor is available only in C++11.
 
BaseSnifferoperator= (BaseSniffer &&rhs) TINS_NOEXCEPT
 Move assignment operator. This operator is available only in C++11.
 
virtual ~BaseSniffer ()
 Sniffer destructor. This frees all memory used by the pcap handle.
 
PtrPacket next_packet ()
 Compiles a filter and uses it to capture one packet. More...
 
template<typename Functor >
void sniff_loop (Functor function, uint32_t max_packets=0)
 Starts a sniffing loop, using a callback functor for every sniffed packet. More...
 
bool set_filter (const std::string &filter)
 Sets a filter on this sniffer. More...
 
void stop_sniff ()
 Stops sniffing loops. More...
 
int get_fd ()
 Gets the file descriptor associated with the sniffer.
 
bool set_direction (pcap_direction_t d)
 Sets direction for the sniffer. More...
 
void set_timeout (int ms)
 Sets the read timeout for this sniffer. More...
 
void set_extract_raw_pdus (bool value)
 Sets whether to extract RawPDUs or fully parsed packets. More...
 
int link_type () const
 Retrieves this sniffer's link type. More...
 
iterator begin ()
 
iterator end ()
 
pcap_t * get_pcap_handle ()
 
const pcap_t * get_pcap_handle () const
 

Friends

class SnifferConfiguration
 

Additional Inherited Members

- Protected Member Functions inherited from Tins::BaseSniffer
 BaseSniffer ()
 
void set_pcap_handle (pcap_t *pcap_handle)
 
void set_if_mask (bpf_u_int32 if_mask)
 
bpf_u_int32 get_if_mask () const
 

Detailed Description

Sniffs packets from a network interface.

Member Enumeration Documentation

Deprecated:
This enum is no longer necessary. You should use the Sniffer(const std::string&, const SnifferConfiguration&) constructor.

Constructor & Destructor Documentation

Tins::Sniffer::Sniffer ( const std::string &  device,
const SnifferConfiguration configuration 
)

Constructs an instance of Sniffer using the provided configuration.

This constructor was added as a way to improve the parameter bloat introduced by the other ones available. You should create an instance of SnifferConfiguration, set the desired parameters, and then use it when constructing a Sniffer object.

See Also
SnifferConfiguration
Parameters
deviceThe device which will be sniffed.
configurationThe configuration object to use to setup the sniffer.
Tins::Sniffer::Sniffer ( const std::string &  device,
unsigned  max_packet_size,
bool  promisc = false,
const std::string &  filter = "",
bool  rfmon = false 
)

Constructs an instance of Sniffer.

By default the interface won't be put into promiscuous mode, and won't be put into monitor mode.

Deprecated:
Use the Sniffer(const std::string&, const SnifferConfiguration&) constructor.
Parameters
deviceThe device which will be sniffed.
max_packet_sizeThe maximum packet size to be read.
promiscbool indicating whether to put the interface in promiscuous mode.(optional)
filterA capture filter to be used on the sniffing session.(optional);
rfmonIndicates if the interface should be put in monitor mode.(optional);
Tins::Sniffer::Sniffer ( const std::string &  device,
promisc_type  promisc = NON_PROMISC,
const std::string &  filter = "",
bool  rfmon = false 
)

Constructs an instance of Sniffer.

The maximum capture size is set to 65535. By default the interface won't be put into promiscuous mode, and won't be put into monitor mode.

Deprecated:
Use the Sniffer(const std::string&, const SnifferConfiguration&) constructor.
Parameters
deviceThe device which will be sniffed.
promiscIndicates if the interface should be put in promiscuous mode.
filterA capture filter to be used on the sniffing session.(optional);
rfmonIndicates if the interface should be put in monitor mode.(optional);

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