00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PCAP_STREAM_HH_
00023 # define PCAP_STREAM_HH_
00024
00025 extern "C"
00026 {
00027 # include <inttypes.h>
00028 }
00029 # include <cstdlib>
00030 # include <string>
00031 # include <vector>
00032
00033 # include <wipal/pcap/pkt.hh>
00034 # include <wipal/pcap/file_iterator.hh>
00035
00036 namespace wpl
00037 {
00038
00057 namespace pcap
00058 {
00059
00060 template <class D>
00061 struct file;
00062
00063 template <class D>
00064 struct indexed_file;
00065
00066 }
00067
00068 namespace tool
00069 {
00070
00071 template <class B>
00072 struct types< pcap::file<B> >
00073 {
00074 typedef WP_GET_EXACT(B, pcap::file<B>) exact_type;
00075 typedef pcap::internals::file_iterator<exact_type> iterator;
00076 };
00077
00078 template <class B>
00079 struct types< pcap::indexed_file<B> >
00080 {
00081 typedef WP_GET_EXACT(B, pcap::indexed_file<B>) exact_type;
00082 typedef pcap::internals::file_iterator<exact_type> iterator;
00083 };
00084
00085 }
00086
00087 namespace pcap
00088 {
00089
00091 template <class Bottom>
00092 struct stream: WP_INHERIT(public pkt::stream, stream<Bottom>)
00093 {
00095 int32_t zone() const;
00096
00098 int32_t snaplen() const;
00099 };
00100
00102 template <class Bottom>
00103 struct istream: WP_INHERIT(public stream, istream<Bottom>)
00104 {
00105 typedef WP_GET_EXACT(Bottom, istream<Bottom>) exact_type;
00106 typedef stream<exact_type> super_type;
00107 typedef WP_TYPE(iterator, exact_type) iterator;
00108 typedef iterator const_iterator;
00109
00111 istream(std::istream* const is);
00112
00113 std::ostream& print_impl(std::ostream&) const;
00114
00115 bool swapped_impl() const;
00116 pkt::type type_impl() const;
00117 int32_t zone_impl() const;
00118 int32_t snaplen_impl() const;
00119
00120 private:
00121 bool swap_;
00122 pkt::type type_;
00123 int32_t zone_;
00124 int32_t snaplen_;
00125 };
00126
00128 template <class Bottom = tool::bottom>
00129 struct file: WP_INHERIT(public istream, file<Bottom>)
00130 {
00131 typedef WP_GET_EXACT(Bottom, file<Bottom>) exact_type;
00132 typedef istream<exact_type> super_type;
00133
00135 file(const std::string& filename);
00136
00145 std::ifstream* stream(bool seek = true) const;
00146
00148 std::streampos filesize() const;
00149
00151 const std::string& filename() const;
00152
00153 std::ostream& print_impl(std::ostream&) const;
00154
00155 private:
00156 std::string filename_;
00157 std::streampos filesize_;
00158 };
00159
00165 template <class Bottom = tool::bottom>
00166 struct indexed_file: WP_INHERIT(public file, indexed_file<Bottom>)
00167 {
00168 typedef WP_GET_EXACT(Bottom, indexed_file<Bottom>) exact_type;
00169 typedef file<exact_type> super_type;
00170 typedef WP_TYPE(iterator, exact_type) iterator;
00171
00179 typedef std::vector<std::streampos> index_type;
00180
00181 enum
00182 {
00197 mark_step = 4,
00198
00208 junk_len = 4096
00209 };
00210
00212 indexed_file(const std::string& filename);
00213
00218 indexed_file(const std::string& filename,
00219 const index_type& marks,
00220 unsigned size);
00221
00238 template <typename ProgressInfoSetupType,
00239 typename ProgressInfoUpdateType>
00240 indexed_file(const std::string& filename,
00241 ProgressInfoSetupType& pi_setup,
00242 ProgressInfoUpdateType& pi_update);
00243
00245 iterator operator [] (size_t);
00246
00248 size_t size() const;
00249
00250 protected:
00251 void warn(const std::streampos& pos, const std::string& msg);
00252 void handle_truncation(const std::string& msg);
00253
00254 private:
00255 template <typename ProgressInfoSetupType,
00256 typename ProgressInfoUpdateType>
00257 void
00258 setup(ProgressInfoSetupType& pi_setup,
00259 ProgressInfoUpdateType& pi_update);
00260
00261 index_type marks_;
00262 size_t size_;
00263 };
00264
00265 }
00266
00267 }
00268
00269 # include "stream.hxx"
00270
00271 #endif // ! PCAP_STREAM_HH_