mirror of
https://github.com/mfontanini/libtins
synced 2026-01-30 13:34:27 +01:00
Added 1000ms as the default read timeout used when calling pcap_open_live. Added BaseSniffer::set_timeout to modify this parameter.
This commit is contained in:
@@ -192,6 +192,14 @@ namespace Tins {
|
|||||||
*/
|
*/
|
||||||
int get_fd();
|
int get_fd();
|
||||||
|
|
||||||
|
/**
|
||||||
|
* \brief Sets the read timeout for this sniffer.
|
||||||
|
*
|
||||||
|
* This calls pcap_set_timeout using the provided parameter.
|
||||||
|
* \param ms The amount of milliseconds.
|
||||||
|
*/
|
||||||
|
void set_timeout(int ms);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* \brief Retrieves this sniffer's link type.
|
* \brief Retrieves this sniffer's link type.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -178,6 +178,10 @@ bool BaseSniffer::set_filter(const std::string &filter) {
|
|||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void BaseSniffer::set_timeout(int ms) {
|
||||||
|
pcap_set_timeout(handle, ms);
|
||||||
|
}
|
||||||
|
|
||||||
// ****************************** Sniffer ******************************
|
// ****************************** Sniffer ******************************
|
||||||
|
|
||||||
Sniffer::Sniffer(const string &device, unsigned max_packet_size,
|
Sniffer::Sniffer(const string &device, unsigned max_packet_size,
|
||||||
@@ -201,7 +205,7 @@ void Sniffer::init_sniffer(const std::string &device, unsigned max_packet_size,
|
|||||||
ip = 0;
|
ip = 0;
|
||||||
if_mask = 0;
|
if_mask = 0;
|
||||||
}
|
}
|
||||||
pcap_t *phandle = pcap_open_live(device.c_str(), max_packet_size, promisc, 0, error);
|
pcap_t *phandle = pcap_open_live(device.c_str(), max_packet_size, promisc, 1000, error);
|
||||||
if(!phandle)
|
if(!phandle)
|
||||||
throw runtime_error(error);
|
throw runtime_error(error);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user