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 extern "C"
00026 {
00027 # include <inttypes.h>
00028 }
00029 # include <vector>
00030 # include <ios>
00031 # include <string>
00032 # include <cstdlib>
00033
00034 # include <wipal/tool/options.hh>
00035 # include <wipal/pcap/frame_iterator.hh>
00036 # include <wipal/tool/iterable.hh>
00037 # include <wipal/pcap/dumper.hh>
00038
00057 namespace pcapxx
00058 {
00059
00060 template <class D>
00061 struct descriptor;
00062
00063 }
00064
00065 namespace tool
00066 {
00067
00069 template <class B>
00070 struct types< pcapxx::descriptor<B> >
00071 {
00073 typedef WP_GET_EXACT(B, pcapxx::descriptor<B>) exact_type;
00074
00076 typedef pcapxx::internals::frame_iterator<exact_type> iterator;
00077 };
00078
00079 }
00080
00081 namespace pcapxx
00082 {
00083
00108 template <class Bottom = tool::bottom>
00109 struct descriptor: WP_INHERIT(public tool::iterable, descriptor<Bottom>)
00110 {
00112
00113 typedef WP_GET_EXACT(Bottom, descriptor<Bottom>) exact_type;
00114 typedef tool::iterable<exact_type> super_type;
00116
00118 typedef WP_TYPE(iterator, exact_type) iterator;
00119 typedef iterator const_iterator;
00120
00128 typedef std::vector<std::streampos> index_type;
00129
00130 enum
00131 {
00142 mark_step = 4096,
00143
00153 junk_len = 4096
00154 };
00155
00157 enum link_type
00158 {
00159 LOOP = 0,
00160 EN10MB = 1,
00161 EN3MB = 2,
00162 AX25 = 3,
00163 PRONET = 4,
00164 CHAOS = 5,
00165 IEEE802 = 6,
00166 ARCNET = 7,
00167 SLIP = 8,
00168 PPP = 9,
00169 FDDI = 10,
00170 IEEE802_11 = 105,
00171 PRISM_HEADER = 119,
00172 IEEE802_11_RADIO = 127,
00173 IEEE802_11_RADIO_AVS = 163
00174 };
00175
00177 descriptor(const std::string& filename, bool build_index = false);
00178
00183 descriptor(const std::string& filename,
00184 const index_type& marks,
00185 unsigned pkt_count);
00186
00203 template <typename ProgressInfoSetupType,
00204 typename ProgressInfoUpdateType>
00205 descriptor(const std::string& filename,
00206 ProgressInfoSetupType& pi_setup,
00207 ProgressInfoUpdateType& pi_update);
00208
00210 iterator operator [] (size_t);
00211
00213 size_t size() const;
00214
00216 bool swapped() const;
00217
00219 int32_t zone() const;
00220
00222 int32_t snaplen() const;
00223
00225 link_type linktype() const;
00226
00231 void expect(link_type l) const;
00232
00234 std::streampos file_size() const;
00235
00237 const std::string& file_name() const;
00238
00240 pcapxx::dumper dumper(const std::string& fname) const;
00241
00248 tool::opt::list& metadata();
00249 const tool::opt::list& metadata() const;
00251
00252 private:
00253 template <typename ProgressInfoSetupType,
00254 typename ProgressInfoUpdateType>
00255 void
00256 setup(const std::string& filename,
00257 bool build_index,
00258 ProgressInfoSetupType& pi_setup,
00259 ProgressInfoUpdateType& pi_update);
00260
00261 void warn(const std::streampos&p, const std::string& msg);
00262 void handle_truncation(const std::string& msg);
00263
00264 template <typename ProgressInfoSetupType,
00265 typename ProgressInfoUpdateType>
00266 void
00267 setup_marks(std::istream& f,
00268 ProgressInfoSetupType& pi_setup,
00269 ProgressInfoUpdateType& pi_update);
00270
00271 index_type marks_;
00272
00273 bool swap_;
00274 int32_t zone_;
00275 int32_t snaplen_;
00276 link_type type_;
00277 size_t pkt_count_;
00278 std::streampos file_size_;
00279 std::string file_name_;
00280 tool::opt::list metadata_;
00281 };
00282
00283 }
00284
00285 # include "descriptor.hxx"
00286
00287 #endif // ! PCAP_DESCRITPOR_HH_