mirror of
https://github.com/mfontanini/libtins
synced 2026-01-28 04:34:27 +01:00
Added another Sniffer constructor.
This commit is contained in:
@@ -246,8 +246,13 @@ namespace Tins {
|
||||
*/
|
||||
class Sniffer : public BaseSniffer {
|
||||
public:
|
||||
enum promisc_type {
|
||||
NON_PROMISC,
|
||||
PROMISC
|
||||
};
|
||||
|
||||
/**
|
||||
* \brief Constructs an instance of Sniffer.
|
||||
* Constructs an instance of Sniffer.
|
||||
* \param device The device which will be sniffed.
|
||||
* \param max_packet_size The maximum packet size to be read.
|
||||
* \param promisc bool indicating wether to put the interface in promiscuous mode.(optional)
|
||||
@@ -255,6 +260,22 @@ namespace Tins {
|
||||
*/
|
||||
Sniffer(const std::string &device, unsigned max_packet_size,
|
||||
bool promisc = false, const std::string &filter = "");
|
||||
|
||||
/**
|
||||
* \brief Constructs an instance of Sniffer.
|
||||
*
|
||||
* The maximum capture size is set to 65535. By default the interface won't
|
||||
* be put into promiscuous mode.
|
||||
*
|
||||
* \param device The device which will be sniffed.
|
||||
* \param promisc Indicates if the interface should be put in promiscuous mode.
|
||||
* \param filter A capture filter to be used on the sniffing session.(optional);
|
||||
*/
|
||||
Sniffer(const std::string &device, promisc_type promisc = NON_PROMISC,
|
||||
const std::string &filter = "");
|
||||
private:
|
||||
void init_sniffer(const std::string &device, unsigned max_packet_size,
|
||||
bool promisc = false, const std::string &filter = "");
|
||||
};
|
||||
|
||||
/**
|
||||
|
||||
@@ -165,7 +165,19 @@ bool BaseSniffer::set_filter(const std::string &filter) {
|
||||
Sniffer::Sniffer(const string &device, unsigned max_packet_size,
|
||||
bool promisc, const string &filter)
|
||||
{
|
||||
char error[PCAP_ERRBUF_SIZE];
|
||||
init_sniffer(device, max_packet_size, promisc, filter);
|
||||
}
|
||||
|
||||
Sniffer::Sniffer(const std::string &device, promisc_type promisc,
|
||||
const std::string &filter)
|
||||
{
|
||||
init_sniffer(device, 65535, promisc == PROMISC, filter);
|
||||
}
|
||||
|
||||
void Sniffer::init_sniffer(const std::string &device, unsigned max_packet_size,
|
||||
bool promisc, const std::string &filter)
|
||||
{
|
||||
char error[PCAP_ERRBUF_SIZE];
|
||||
bpf_u_int32 ip, if_mask;
|
||||
if (pcap_lookupnet(device.c_str(), &ip, &if_mask, error) == -1) {
|
||||
ip = 0;
|
||||
@@ -178,6 +190,7 @@ Sniffer::Sniffer(const string &device, unsigned max_packet_size,
|
||||
init(phandle, filter, if_mask);
|
||||
}
|
||||
|
||||
|
||||
// **************************** FileSniffer ****************************
|
||||
|
||||
FileSniffer::FileSniffer(const string &file_name, const string &filter) {
|
||||
|
||||
Reference in New Issue
Block a user