00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef PRISM_HEADER_HXX_
00023 # define PRISM_HEADER_HXX_
00024
00025 # include "prism_header.hh"
00026
00027 # include <wipal/tool/endianness.hh>
00028
00029 namespace prism
00030 {
00031
00032
00033
00034
00035 inline
00036 uint32_t
00037 item::get(bool swapped) const
00038 {
00039 return tool::extract_long_u(data, swapped);
00040 }
00041
00042 inline
00043 item&
00044 item::set(uint32_t value, bool swapped)
00045 {
00046 status = 0;
00047 data = tool::extract_long_u(value, swapped);
00048
00049 return *this;
00050 }
00051
00052
00053
00054
00055
00056 inline
00057 time::time(): mactime_ (0), hosttime_ (0)
00058 {
00059 }
00060
00061 inline
00062 time::time(uint32_t mactime, uint32_t hosttime): mactime_ (mactime),
00063 hosttime_ (hosttime)
00064 {
00065 }
00066
00067 inline
00068 uint32_t
00069 time::mactime() const
00070 {
00071 return mactime_;
00072 }
00073
00074 inline
00075 uint32_t
00076 time::hosttime() const
00077 {
00078 return hosttime_;
00079 }
00080
00081 inline
00082 time::impl_type
00083 time::get_impl() const
00084 {
00085 return mactime();
00086 }
00087
00088 inline
00089 time::exact_type&
00090 time::increment(tool::microseconds ms)
00091 {
00092 const tool::microseconds::mpz_type mpz_hosttime = hosttime_;
00093 const tool::microseconds ms_mactime = ms + mactime_;
00094 const tool::microseconds ms_hosttime = ms + mpz_hosttime * 10;
00095
00096 mactime_ = ms_mactime.get_prism_mactime();
00097 hosttime_ = ms_hosttime.get_prism_hosttime();
00098
00099 return this->exact();
00100 }
00101
00102
00103
00104
00105
00106
00107 inline
00108 size_t
00109 header::len_impl(size_t, bool) const
00110 {
00111 return sizeof (*this);
00112 }
00113
00114 inline
00115 header::time_type
00116 header::time_get_impl(bool swapped) const
00117 {
00118 return time_type (mactime.get(swapped), hosttime.get(swapped));
00119 }
00120
00121 inline
00122 void
00123 header::time_set_impl(const time_type& value, bool swapped)
00124 {
00125 mactime.set(value.mactime(), swapped);
00126 hosttime.set(value.hosttime(), swapped);
00127 }
00128
00129 template <class D1, class D2>
00130 bool
00131 header::eq_time(const pcapxx::frame_descriptor<D1>& lhs,
00132 const pcapxx::frame_descriptor<D2>& rhs,
00133 tool::endian::endianness phy_end,
00134 unsigned prec)
00135 {
00136 using tool::endian::need_swap;
00137
00138 const pcapxx::pkthdr& lhs_pcap = *lhs.pcap_header().get();
00139 const pcapxx::pkthdr& rhs_pcap = *rhs.pcap_header().get();
00140
00141 const size_t caplen = std::min(lhs_pcap.caplen,
00142 rhs_pcap.caplen);
00143
00144 if (caplen < sizeof (prism::header))
00145 return false;
00146
00147 const bool lhs_sw = need_swap(phy_end, lhs.swapped());
00148 const bool rhs_sw = need_swap(phy_end, rhs.swapped());
00149
00150 const header* const lhs_phy = (reinterpret_cast<const header*>
00151 (lhs.bytes().get()));
00152 const header* const rhs_phy = (reinterpret_cast<const header*>
00153 (rhs.bytes().get()));
00154
00155
00156 return unsigned (std::abs(int (lhs_phy->mactime.get(lhs_sw) -
00157 rhs_phy->mactime.get(rhs_sw)))) <= prec;
00158 }
00159
00160 }
00161
00162 #endif // ! PRISM_HEADER_HXX_