From e9484209fc38e9cb0c6081d770ef3fa59cebc4f1 Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Mon, 12 Mar 2012 09:47:30 -0300 Subject: [PATCH] Added timeout to Sniffer class. --- include/sniffer.h | 3 ++- src/sniffer.cpp | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/include/sniffer.h b/include/sniffer.h index 7e1ebbe..d59100c 100644 --- a/include/sniffer.h +++ b/include/sniffer.h @@ -66,9 +66,10 @@ namespace Tins { * \brief Creates an instance of sniffer. * \param device The device which will be sniffed. * \param max_packet_size The maximum packet size to be read. + * \param timeout The time in seconds to wait for a packet. * \param filter A capture filter to compile and use for sniffing sessions.(optional); */ - Sniffer(const std::string &device, unsigned max_packet_size, const std::string &filter = "") throw(std::runtime_error); + Sniffer(const std::string &device, unsigned max_packet_size, unsigned timeout = 0, const std::string &filter = "") throw(std::runtime_error); /** * \brief Sniffer destructor. diff --git a/src/sniffer.cpp b/src/sniffer.cpp index b494f35..1ecba9e 100644 --- a/src/sniffer.cpp +++ b/src/sniffer.cpp @@ -40,13 +40,13 @@ struct LoopData { /** \endcond */ -Tins::Sniffer::Sniffer(const string &device, unsigned max_packet_size, const string &filter) throw(std::runtime_error) { +Tins::Sniffer::Sniffer(const string &device, unsigned max_packet_size, unsigned timeout, const string &filter) throw(std::runtime_error) { char error[PCAP_ERRBUF_SIZE]; if (pcap_lookupnet(device.c_str(), &ip, &mask, error) == -1) { ip = 0; mask = 0; } - handle = pcap_open_live(device.c_str(), max_packet_size, 0, 0, error); + handle = pcap_open_live(device.c_str(), max_packet_size, 0, timeout, error); if(!handle) throw runtime_error(error); wired = (pcap_datalink (handle) != DLT_IEEE802_11_RADIO); //better plx