source: trunk/ETSI-Testsuites/ETSI_auto_IOT/adapter/src/Capture/PCAPCapture.h @ 35

Last change on this file since 35 was 22, checked in by rings, 14 years ago
  • Property svn:executable set to *
File size: 2.2 KB
Line 
1/**
2 * @file PCAPCapture.h
3 * This header file defines the PCAPCapture class.
4 * @author Tomas Urban
5 * @version 0.2
6 * @date 22/07/2009
7 */
8#ifndef PCAP_CAPTURE_H
9#define PCAP_CAPTURE_H
10
11#include "GenericCapture.h"
12#include <boost/thread/mutex.hpp>
13#include <boost/thread/condition.hpp>
14
15#define HAVE_REMOTE
16#include "pcap/pcap.h"
17
18/**
19 * This abstract class describes capturing based on the pcap library.
20 */
21class PCAPCapture :     public GenericCapture
22{
23private:
24        static const int SNAP_LEN = 0x1000;
25        pcap_t ** m_fp; //array of pcap handles
26        int m_nHandleCount;
27        bool * m_threadRunning;
28        static void DispatcherHandler(u_char * temp1, const struct pcap_pkthdr *header, const u_char *pkt_data);
29        boost::mutex m_mutex;
30        boost::condition m_threadClosed;
31        bool m_bRunning;
32        pcap_dumper_t ** m_dumpFiles;
33        void CloseCaptureFile();       
34        class CapturingThread
35        {
36        public:
37                PCAPCapture * m_pCapture;
38                int m_nHandleIndex;
39                CapturingThread(PCAPCapture * pCapture, int nHandleIndex);
40                void operator()();
41        };
42protected:
43        PCAPCapture(); 
44        /**
45         * Saves supplied array of pcap sources for later use. This method is usually called
46         * by the #OpenDevice method of child classes.
47         * @param srcBuf Source array
48         * @param nLen Number of elements in the source array
49         */
50        void SetPcapHandles(pcap_t ** srcBuf, int nLen);
51        /**
52         * Helper method for opening a pcap data source
53         * @return Pointer to the pcap source or \c NULL if the operation is not successful.
54         */
55        pcap_t * OpenPcapSource(const std::string sSource);
56        /**
57         * Helper method for setting up data saving into a file. It is used by child classes
58         * that allow data saving into a file.
59         * @param sFile Path to the capture file
60         */
61        bool InitCaptureFile(const std::string sFile);
62public:
63        virtual ~PCAPCapture(void);
64        virtual ECaptureType GetCaptureType() { return ECaptureType_PCAP; }
65        /**
66         * Sets a traffic filter. The filter must follow pcap library syntax for filtering expressions.
67         * @param sFilter Filtering data in pcap format
68         * @return \c true if the operation was successful, \c false otherwise (e.g. in case
69         * of invalid filter format)
70         */
71        virtual bool SetFilter(const std::string sFilter);
72        virtual void CloseDevice();
73        virtual bool StartCapture();
74        virtual bool StopCapture();
75};
76
77#endif
Note: See TracBrowser for help on using the repository browser.