00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PCAP_DESCRIPTOR_HH_
00023 # define PCAP_DESCRIPTOR_HH_
00024
00025 # include <string>
00026
00027 # include <boost/optional.hpp>
00028 # include <boost/shared_ptr.hpp>
00029
00030 # include <trace-tools/tool/iterator_base.hh>
00031 # include <trace-tools/tool/iterable.hh>
00032 # include <trace-tools/pcap/frame_iterator.hh>
00033 # include <trace-tools/pcap/typedefs.hh>
00034 # include <trace-tools/pcap/dumper.hh>
00035
00037 namespace pcapxx
00038 {
00039
00040 template <class D>
00041 struct descriptor;
00042
00043 }
00044
00045 namespace tool
00046 {
00047
00049 template <class B>
00050 struct types< pcapxx::descriptor<B> >
00051 {
00053 typedef pcapxx::internals::frame_iterator<B, bottom> iterator;
00054 };
00055
00056 }
00057
00058 namespace pcapxx
00059 {
00060
00085 template <class Bottom = tool::bottom>
00086 struct descriptor: tt_inherit(public tool::iterable, descriptor<Bottom>)
00087 {
00096 descriptor(const std::string& device, int snaplen, int promisc, int to_ms);
00097
00099 descriptor(const std::string& fname);
00100
00107 descriptor(int linktype, int snaplen);
00108
00114 int datalink() const;
00115
00117 bool is_swapped() const;
00118
00120 std::string error() const;
00121
00123 pcapxx::dumper dumper(const std::string& fname) const;
00124
00133 template <handler Callback>
00134 int
00135 loop(void* user = 0, int cnt = -1);
00136
00137 private:
00138
00140 struct wrapper_data
00141 {
00143 descriptor* desc;
00144
00146 void* user;
00147 };
00148
00150 template <handler H>
00151 static
00152 void
00153 handler_wrapper(u_char*, const pcap_pkthdr*, const u_char*);
00154
00156 struct shared_data
00157 {
00158 shared_data(pcap_t*);
00159 ~shared_data();
00160
00161 pcap_t* desc;
00162 unsigned curr;
00163 };
00164
00165 boost::shared_ptr<shared_data> d_;
00166 };
00167
00168 }
00169
00170 # include "descriptor.hxx"
00171
00172 #endif // ! PCAP_DESCRITPOR_HH_