From 6fd0c14b456a8aaf260be8dfd09eb1951445576b Mon Sep 17 00:00:00 2001 From: Matias Fontanini Date: Wed, 15 Aug 2012 08:36:37 -0300 Subject: [PATCH] Fixed Sniffer::sniff_loop argument types. --- include/sniffer.h | 27 +++++++++++++++++++++++++-- 1 file changed, 25 insertions(+), 2 deletions(-) diff --git a/include/sniffer.h b/include/sniffer.h index f8fccd6..389ae77 100644 --- a/include/sniffer.h +++ b/include/sniffer.h @@ -91,7 +91,7 @@ namespace Tins { * \param max_packets The maximum amount of packets to sniff. 0 == infinite. */ template - void sniff_loop(const Functor &function, uint32_t max_packets = 0); + void sniff_loop(Functor function, uint32_t max_packets = 0); /** * \brief Sets a filter on this sniffer. @@ -130,7 +130,7 @@ namespace Tins { }; template - void Tins::Sniffer::sniff_loop(const Functor &function, uint32_t max_packets) { + void Tins::Sniffer::sniff_loop(Functor function, uint32_t max_packets) { LoopData data(handle, function, wired); pcap_loop(handle, max_packets, &Sniffer::callback_handler, (u_char*)&data); } @@ -153,6 +153,29 @@ namespace Tins { } } + + template + class HandlerProxy { + public: + typedef T* ptr_type; + typedef bool (T::*fun_type)(PDU*) ; + + HandlerProxy(ptr_type ptr, fun_type function) + : object(ptr), fun(function) {} + + bool operator()(PDU *pdu) { + return (object->*fun)(pdu); + } + private: + ptr_type object; + fun_type fun; + }; + + template + HandlerProxy make_sniffer_handler(T *ptr, typename HandlerProxy::fun_type function) + { + return HandlerProxy(ptr, function); + } }; #endif // TINS_SNIFFER_H