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
00039 namespace pcapxx
00040 {
00041
00042 template <class D>
00043 struct descriptor;
00044
00045 }
00046
00047 namespace tool
00048 {
00049
00051 template <class B>
00052 struct types< pcapxx::descriptor<B> >
00053 {
00055 typedef WP_GET_EXACT(B, pcapxx::descriptor<B>) exact_type;
00056
00058 typedef pcapxx::internals::frame_iterator<exact_type> iterator;
00059 };
00060
00061 }
00062
00063 namespace pcapxx
00064 {
00065
00090 template <class Bottom = tool::bottom>
00091 struct descriptor: WP_INHERIT(public tool::iterable, descriptor<Bottom>)
00092 {
00094
00095 typedef WP_GET_EXACT(Bottom, descriptor<Bottom>) exact_type;
00096 typedef tool::iterable<exact_type> super_type;
00098
00100 typedef WP_TYPE(iterator, exact_type) iterator;
00101 typedef iterator const_iterator;
00102
00110 typedef std::vector<std::streampos> index_type;
00111
00112 enum
00113 {
00124 mark_step = 4096,
00125
00135 junk_len = 4096
00136 };
00137
00139 enum link_type
00140 {
00141 LOOP = 0,
00142 EN10MB = 1,
00143 EN3MB = 2,
00144 AX25 = 3,
00145 PRONET = 4,
00146 CHAOS = 5,
00147 IEEE802 = 6,
00148 ARCNET = 7,
00149 SLIP = 8,
00150 PPP = 9,
00151 FDDI = 10,
00152 IEEE802_11 = 105,
00153 PRISM_HEADER = 119,
00154 IEEE802_11_RADIO = 127,
00155 IEEE802_11_RADIO_AVS = 163
00156 };
00157
00159 descriptor(const std::string& filename, bool build_index = false);
00160
00165 descriptor(const std::string& filename,
00166 const index_type& marks,
00167 unsigned pkt_count);
00168
00185 template <typename ProgressInfoSetupType,
00186 typename ProgressInfoUpdateType>
00187 descriptor(const std::string& filename,
00188 ProgressInfoSetupType& pi_setup,
00189 ProgressInfoUpdateType& pi_update);
00190
00192 iterator operator [] (size_t);
00193
00195 size_t size() const;
00196
00198 bool swapped() const;
00199
00201 int32_t zone() const;
00202
00204 int32_t snaplen() const;
00205
00207 link_type linktype() const;
00208
00213 void expect(link_type l) const;
00214
00216 std::streampos file_size() const;
00217
00219 const std::string& file_name() const;
00220
00222 pcapxx::dumper dumper(const std::string& fname) const;
00223
00224 private:
00225 template <typename ProgressInfoSetupType,
00226 typename ProgressInfoUpdateType>
00227 void
00228 setup(const std::string& filename,
00229 bool build_index,
00230 ProgressInfoSetupType& pi_setup,
00231 ProgressInfoUpdateType& pi_update);
00232
00233 void warn(const std::streampos&p, const std::string& msg);
00234 void handle_truncation(const std::string& msg);
00235
00236 template <typename ProgressInfoSetupType,
00237 typename ProgressInfoUpdateType>
00238 void
00239 setup_marks(std::istream& f,
00240 ProgressInfoSetupType& pi_setup,
00241 ProgressInfoUpdateType& pi_update);
00242
00243 index_type marks_;
00244
00245 bool swap_;
00246 int32_t zone_;
00247 int32_t snaplen_;
00248 link_type type_;
00249 size_t pkt_count_;
00250 std::streampos file_size_;
00251 std::string file_name_;
00252 };
00253
00254 }
00255
00256 # include "descriptor.hxx"
00257
00258 #endif // ! PCAP_DESCRITPOR_HH_