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 pcapxx::internals::frame_iterator<bottom> iterator;
00056 };
00057
00058 }
00059
00060 namespace pcapxx
00061 {
00062
00087 template <class Bottom = tool::bottom>
00088 struct descriptor: WP_INHERIT(public tool::iterable, descriptor<Bottom>)
00089 {
00091
00092 typedef WP_GET_EXACT(Bottom, descriptor<Bottom>) exact_type;
00093 typedef tool::iterable<exact_type> super_type;
00095
00097 typedef WP_TYPE(iterator, exact_type) iterator;
00098 typedef iterator const_iterator;
00099
00107 typedef std::vector<std::streampos> index_type;
00108
00109 enum
00110 {
00121 mark_step = 4096,
00122
00132 junk_len = 4096
00133 };
00134
00136 enum link_type
00137 {
00138 LOOP = 0,
00139 EN10MB = 1,
00140 EN3MB = 2,
00141 AX25 = 3,
00142 PRONET = 4,
00143 CHAOS = 5,
00144 IEEE802 = 6,
00145 ARCNET = 7,
00146 SLIP = 8,
00147 PPP = 9,
00148 FDDI = 10,
00149 IEEE802_11 = 105,
00150 PRISM_HEADER = 119,
00151 IEEE802_11_RADIO = 127,
00152 IEEE802_11_RADIO_AVS = 163
00153 };
00154
00156 descriptor(const std::string& filename, bool build_index = false);
00157
00162 descriptor(const std::string& filename,
00163 const index_type& marks,
00164 unsigned pkt_count);
00165
00182 template <typename ProgressInfoSetupType,
00183 typename ProgressInfoUpdateType>
00184 descriptor(const std::string& filename,
00185 ProgressInfoSetupType& pi_setup,
00186 ProgressInfoUpdateType& pi_update);
00187
00189 iterator operator [] (size_t);
00190
00192 size_t size() const;
00193
00195 bool swapped() const;
00196
00198 int32_t zone() const;
00199
00201 int32_t snaplen() const;
00202
00204 link_type linktype() const;
00205
00210 void expect(link_type l) const;
00211
00213 std::streampos file_size() const;
00214
00216 const std::string& file_name() const;
00217
00219 pcapxx::dumper dumper(const std::string& fname) const;
00220
00221 private:
00222 template <typename ProgressInfoSetupType,
00223 typename ProgressInfoUpdateType>
00224 void
00225 setup(const std::string& filename,
00226 bool build_index,
00227 ProgressInfoSetupType& pi_setup,
00228 ProgressInfoUpdateType& pi_update);
00229
00230 void warn(const std::streampos&p, const std::string& msg);
00231 void handle_truncation(const std::string& msg);
00232
00233 template <typename ProgressInfoSetupType,
00234 typename ProgressInfoUpdateType>
00235 void
00236 setup_marks(std::istream& f,
00237 ProgressInfoSetupType& pi_setup,
00238 ProgressInfoUpdateType& pi_update);
00239
00240 index_type marks_;
00241
00242 bool swap_;
00243 int32_t zone_;
00244 int32_t snaplen_;
00245 link_type type_;
00246 size_t pkt_count_;
00247 std::streampos file_size_;
00248 std::string file_name_;
00249 };
00250
00251 }
00252
00253 # include "descriptor.hxx"
00254
00255 #endif // ! PCAP_DESCRITPOR_HH_