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/pcap/frame_iterator.hh>
00035 # include <wipal/tool/iterable.hh>
00036 # include <wipal/pcap/dumper.hh>
00037
00056 namespace pcapxx
00057 {
00058
00059 template <class D>
00060 struct descriptor;
00061
00062 }
00063
00064 namespace tool
00065 {
00066
00068 template <class B>
00069 struct types< pcapxx::descriptor<B> >
00070 {
00072 typedef WP_GET_EXACT(B, pcapxx::descriptor<B>) exact_type;
00073
00075 typedef pcapxx::internals::frame_iterator<exact_type> iterator;
00076 };
00077
00078 }
00079
00080 namespace pcapxx
00081 {
00082
00107 template <class Bottom = tool::bottom>
00108 struct descriptor: WP_INHERIT(public tool::iterable, descriptor<Bottom>)
00109 {
00111
00112 typedef WP_GET_EXACT(Bottom, descriptor<Bottom>) exact_type;
00113 typedef tool::iterable<exact_type> super_type;
00115
00117 typedef WP_TYPE(iterator, exact_type) iterator;
00118 typedef iterator const_iterator;
00119
00127 typedef std::vector<std::streampos> index_type;
00128
00129 enum
00130 {
00141 mark_step = 4096,
00142
00152 junk_len = 4096
00153 };
00154
00156 enum link_type
00157 {
00158 LOOP = 0,
00159 EN10MB = 1,
00160 EN3MB = 2,
00161 AX25 = 3,
00162 PRONET = 4,
00163 CHAOS = 5,
00164 IEEE802 = 6,
00165 ARCNET = 7,
00166 SLIP = 8,
00167 PPP = 9,
00168 FDDI = 10,
00169 IEEE802_11 = 105,
00170 PRISM_HEADER = 119,
00171 IEEE802_11_RADIO = 127,
00172 IEEE802_11_RADIO_AVS = 163
00173 };
00174
00176 descriptor(const std::string& filename, bool build_index = false);
00177
00182 descriptor(const std::string& filename,
00183 const index_type& marks,
00184 unsigned pkt_count);
00185
00202 template <typename ProgressInfoSetupType,
00203 typename ProgressInfoUpdateType>
00204 descriptor(const std::string& filename,
00205 ProgressInfoSetupType& pi_setup,
00206 ProgressInfoUpdateType& pi_update);
00207
00209 iterator operator [] (size_t);
00210
00212 size_t size() const;
00213
00215 bool swapped() const;
00216
00218 int32_t zone() const;
00219
00221 int32_t snaplen() const;
00222
00224 link_type linktype() const;
00225
00230 void expect(link_type l) const;
00231
00233 std::streampos file_size() const;
00234
00236 const std::string& file_name() const;
00237
00239 pcapxx::dumper dumper(const std::string& fname) const;
00240
00241 private:
00242 template <typename ProgressInfoSetupType,
00243 typename ProgressInfoUpdateType>
00244 void
00245 setup(const std::string& filename,
00246 bool build_index,
00247 ProgressInfoSetupType& pi_setup,
00248 ProgressInfoUpdateType& pi_update);
00249
00250 void warn(const std::streampos&p, const std::string& msg);
00251 void handle_truncation(const std::string& msg);
00252
00253 template <typename ProgressInfoSetupType,
00254 typename ProgressInfoUpdateType>
00255 void
00256 setup_marks(std::istream& f,
00257 ProgressInfoSetupType& pi_setup,
00258 ProgressInfoUpdateType& pi_update);
00259
00260 index_type marks_;
00261
00262 bool swap_;
00263 int32_t zone_;
00264 int32_t snaplen_;
00265 link_type type_;
00266 size_t pkt_count_;
00267 std::streampos file_size_;
00268 std::string file_name_;
00269 };
00270
00271 }
00272
00273 # include "descriptor.hxx"
00274
00275 #endif // ! PCAP_DESCRITPOR_HH_