Back to index

natlog  0.91.0
pcapfilter.h
Go to the documentation of this file.
00001 #ifndef INCLUDED_PCAPFILTER_
00002 #define INCLUDED_PCAPFILTER_
00003 
00004 #include <string>
00005 #include <mutex>
00006 
00007 #include "../signal/signal.h"
00008 
00009 #include "../pcap/pcap.h"
00010 #include "../pcaprecord/pcaprecord.h"
00011 
00012 struct PcapFilter: public SignalHandler
00013 {
00014     typedef PcapRecord::Type Type;
00015 
00016     private:
00017         std::string d_device;
00018         PcapRecord &d_record;
00019         Type d_type;
00020         Pcap d_pcap;
00021 
00022         static char s_filterExpr[];
00023         static std::mutex s_recordMutex;
00024 
00025     public:
00026         PcapFilter(char const *device, PcapRecord &record, Type type);
00027         void operator()();
00028         
00029     private:
00030         void inDevice(PcapPacket const &packet);
00031         void outDevice(PcapPacket const &packet);
00032 
00033         void saveAdd(PcapPacket const &packet);
00034         void saveRemove(PcapPacket const &packet);
00035 
00036 
00037         static void callback(PcapFilter *pf, struct pcap_pkthdr const *hdr,
00038                              u_char const *bytes);
00039         int shiftPacketBegin() const;
00040 
00041         virtual void signaled(size_t signum) override;
00042 };
00043 
00044 #endif
00045 
00046 
00047 
00048 
00049