From 295ebb679ca1c786da86673c7dfd1c77bbaeac2f Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Tue, 19 Nov 2013 20:51:58 -0300 Subject: [PATCH] Added 1000ms as the default read timeout used when calling pcap_open_live. Added BaseSniffer::set_timeout to modify this parameter. --- include/sniffer.h | 8 ++++++++ src/sniffer.cpp | 6 +++++- 2 files changed, 13 insertions(+), 1 deletion(-) diff --git a/include/sniffer.h b/include/sniffer.h index 005c8e6..b588ac6 100644 --- a/include/sniffer.h +++ b/include/sniffer.h @@ -192,6 +192,14 @@ namespace Tins { */ 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. * diff --git a/src/sniffer.cpp b/src/sniffer.cpp index cedef83..d813407 100644 --- a/src/sniffer.cpp +++ b/src/sniffer.cpp @@ -178,6 +178,10 @@ bool BaseSniffer::set_filter(const std::string &filter) { return result; } +void BaseSniffer::set_timeout(int ms) { + pcap_set_timeout(handle, ms); +} + // ****************************** Sniffer ****************************** 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; 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) throw runtime_error(error);