Back to index

natlog  0.91.0
pcap.h
Go to the documentation of this file.
00001 #ifndef INCLUDED_PCAP_
00002 #define INCLUDED_PCAP_
00003 
00004 #include <iosfwd>
00005 #include <pcap/pcap.h>
00006 
00007 class Pcap
00008 {
00009     pcap_t *d_pcap;
00010     struct bpf_program d_pcapFilter;    
00011     bpf_u_int32 d_net;
00012     int d_shift;
00013 
00014     public:
00015         Pcap(char const *device, bool promisc = false, size_t snapLen = 1500, 
00016              size_t timeOutMs = 1000);
00017 
00018         void filter(std::string const &filterExpr, bool optimize = true);
00019         void loop(u_char *user, pcap_handler callback);
00020         void stop();
00021 
00022         int shiftPacketBegin() const;
00023 
00024     private:
00025         void computeShift(char const *device);  // from Pcap(): sets d_shift
00026 };
00027 
00028 inline void Pcap::stop()
00029 {
00030     pcap_breakloop(d_pcap);
00031 }
00032 
00033 inline int Pcap::shiftPacketBegin() const
00034 {
00035     return d_shift;
00036 }
00037 
00038 #endif
00039 
00040 
00041 
00042 
00043