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 wpl
00030 {
00031
00032 namespace prism
00033 {
00034
00035
00036
00037
00038
00039 inline
00040 uint32_t
00041 item::get(bool swapped) const
00042 {
00043 return tool::extract_long_u(data, swapped);
00044 }
00045
00046 inline
00047 item&
00048 item::set(uint32_t value, bool swapped)
00049 {
00050 status = 0;
00051 data = tool::extract_long_u(value, swapped);
00052
00053 return *this;
00054 }
00055
00056
00057
00058
00059
00060 inline
00061 time::time(): mactime_ (0), hosttime_ (0)
00062 {
00063 }
00064
00065 inline
00066 time::time(uint32_t mactime, uint32_t hosttime): mactime_ (mactime),
00067 hosttime_ (hosttime)
00068 {
00069 }
00070
00071 inline
00072 uint32_t
00073 time::mactime() const
00074 {
00075 return mactime_;
00076 }
00077
00078 inline
00079 uint32_t
00080 time::hosttime() const
00081 {
00082 return hosttime_;
00083 }
00084
00085 inline
00086 time::impl_type
00087 time::get_impl() const
00088 {
00089 return mactime();
00090 }
00091
00092 inline
00093 time::exact_type&
00094 time::increment(tool::microseconds ms)
00095 {
00096 const tool::microseconds::mpz_type mpz_hosttime = hosttime_;
00097 const tool::microseconds ms_mactime = ms + mactime_;
00098 const tool::microseconds ms_hosttime = ms + mpz_hosttime * 10;
00099
00100 mactime_ = ms_mactime.get_prism_mactime();
00101 hosttime_ = ms_hosttime.get_prism_hosttime();
00102
00103 return this->exact();
00104 }
00105
00106
00107
00108
00109
00110
00111 inline
00112 size_t
00113 header::len_impl(size_t, bool) const
00114 {
00115 return sizeof (*this);
00116 }
00117
00118 inline
00119 header::time_type
00120 header::time_get_impl(bool swapped) const
00121 {
00122 return time_type (mactime.get(swapped), hosttime.get(swapped));
00123 }
00124
00125 inline
00126 void
00127 header::time_set_impl(const time_type& value, bool swapped)
00128 {
00129 mactime.set(value.mactime(), swapped);
00130 hosttime.set(value.hosttime(), swapped);
00131 }
00132
00133 template <class S1, class S2>
00134 bool
00135 header::eq_time(const pkt::packet<S1>& lhs,
00136 const pkt::packet<S2>& rhs,
00137 const unsigned prec,
00138 const tool::end::endianness phy_end)
00139 {
00140 using tool::need_swap;
00141
00142 const pkt::metadata& lhs_meta = lhs.meta();
00143 const pkt::metadata& rhs_meta = rhs.meta();
00144
00145 const size_t caplen = std::min(lhs_meta.caplen,
00146 rhs_meta.caplen);
00147
00148 if (caplen < sizeof (prism::header))
00149 return false;
00150
00151 const bool lhs_sw = need_swap(phy_end, lhs.swapped());
00152 const bool rhs_sw = need_swap(phy_end, rhs.swapped());
00153
00154 const header* const lhs_phy = (static_cast<const header*>
00155 (lhs.bytes()));
00156 const header* const rhs_phy = (static_cast<const header*>
00157 (rhs.bytes()));
00158
00159
00160 return unsigned (std::abs(int (lhs_phy->mactime.get(lhs_sw) -
00161 rhs_phy->mactime.get(rhs_sw)))) <= prec;
00162 }
00163
00164 }
00165
00166 }
00167
00168 #endif // ! PRISM_HEADER_HXX_