00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PCAP_PKT_HH_
00023 # define PCAP_PKT_HH_
00024
00025 extern "C"
00026 {
00027 # include <time.h>
00028 # include <inttypes.h>
00029 }
00030 # include <iostream>
00031
00032 # include <boost/shared_ptr.hpp>
00033 # include <boost/array.hpp>
00034
00035 # include <wipal/tool/iterable.hh>
00036 # include <wipal/tool/options.hh>
00037
00038 namespace wpl
00039 {
00040
00042 namespace pkt
00043 {
00044
00052 enum type
00053 {
00054 LOOP = 0,
00055 EN10MB = 1,
00056 EN3MB = 2,
00057 AX25 = 3,
00058 PRONET = 4,
00059 CHAOS = 5,
00060 IEEE802 = 6,
00061 ARCNET = 7,
00062 SLIP = 8,
00063 PPP = 9,
00064 FDDI = 10,
00065 IEEE802_11 = 105,
00066 PRISM_HEADER = 119,
00067 IEEE802_11_RADIO = 127,
00068 IEEE802_11_RADIO_AVS = 163
00069 };
00070
00077 struct metadata
00078 {
00079 metadata(unsigned id,
00080 unsigned ts_sec,
00081 unsigned ts_usec,
00082 size_t caplen,
00083 size_t len);
00084
00085 bool operator == (const metadata&) const;
00086 bool operator != (const metadata&) const;
00087
00088 unsigned id;
00089 struct timeval ts;
00090 size_t caplen;
00091 size_t len;
00092 };
00093
00113 template <class Bottom>
00114 struct stream: WP_INHERIT(public tool::iterable, stream<Bottom>)
00115 {
00116 typedef WP_GET_EXACT(Bottom, stream<Bottom>) exact_type;
00117 typedef tool::iterable<exact_type> super_type;
00118 typedef WP_TYPE(iterator, exact_type) iterator;
00119 typedef iterator const_iterator;
00120 typedef typename iterator::value_type packet;
00121
00133 bool swapped() const;
00134
00140 pkt::type type() const;
00141
00146 void expect(pkt::type t) const;
00147
00149 std::ostream& print(std::ostream&) const;
00150
00152 std::ostream& print_impl(std::ostream&) const;
00153
00160 opt::list& meta();
00161 const opt::list& meta() const;
00163
00164 private:
00165 opt::list meta_;
00166 };
00167
00169 template <class B>
00170 std::ostream&
00171 operator << (std::ostream& os, const stream<B>& s);
00172
00184 template <class Source>
00185 struct packet
00186 {
00188 enum { max_size = 65535 };
00189
00191 typedef Source source_type;
00192
00194
00195 packet(unsigned index,
00196 unsigned sec,
00197 unsigned usec,
00198 size_t caplen,
00199 size_t len = 0,
00200 const Source* src = 0);
00201
00202 packet(const metadata& meta,
00203 const Source* src = 0);
00205
00207 const Source* source_ptr() const;
00208
00210 const Source& source() const;
00211
00213 bool swapped() const;
00214
00216 long use_count() const;
00217
00219 bool unique() const;
00220
00222
00223 const metadata& meta() const;
00224 metadata& meta();
00226
00228
00229 const void* bytes() const;
00230 void* bytes();
00232
00234 std::ostream& print(std::ostream&) const;
00235
00237
00238 bool operator == (const packet&) const;
00239 bool operator != (const packet&) const;
00241
00243 struct shared_data
00244 {
00245 template <class B>
00246 shared_data(const stream<B>* src,
00247 const metadata& meta);
00248
00249 const Source* src_;
00250 metadata meta_;
00251 boost::array<uint8_t, max_size> bytes_;
00252 };
00253
00254 protected:
00255 boost::shared_ptr<shared_data> data_;
00256 };
00257
00259 template <class Source>
00260 std::ostream&
00261 operator << (std::ostream&, const packet<Source>&);
00262
00263 }
00264
00265 }
00266
00267 # include "pkt.hxx"
00268
00269 #endif // ! PCAP_PKT_HH_