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 microseconds)
00091 {
00092 mactime_ = mpz_class (microseconds + mactime_).get_ui();
00093 hosttime_ = mpz_class (microseconds / 10 + hosttime_).get_ui();
00094
00095 return this->exact();
00096 }
00097
00098
00099
00100
00101
00102
00103 inline
00104 size_t
00105 header::len_impl(size_t, bool) const
00106 {
00107 return sizeof (*this);
00108 }
00109
00110 inline
00111 header::time_type
00112 header::time_get_impl(bool swapped) const
00113 {
00114 return time_type (mactime.get(swapped), hosttime.get(swapped));
00115 }
00116
00117 inline
00118 void
00119 header::time_set_impl(const time_type& value, bool swapped)
00120 {
00121 mactime.set(value.mactime(), swapped);
00122 hosttime.set(value.hosttime(), swapped);
00123 }
00124
00125 inline
00126 bool
00127 header::eq_time(const pcapxx::frame_descriptor& lhs,
00128 const pcapxx::frame_descriptor& rhs,
00129 tool::endian::endianness phy_end,
00130 unsigned prec)
00131 {
00132 using tool::endian::need_swap;
00133
00134 const pcapxx::pkthdr& lhs_pcap = *lhs.pcap_header().get();
00135 const pcapxx::pkthdr& rhs_pcap = *rhs.pcap_header().get();
00136
00137 const size_t caplen = std::min(lhs_pcap.caplen,
00138 rhs_pcap.caplen);
00139
00140 if (caplen < sizeof (prism::header))
00141 return false;
00142
00143 const bool lhs_sw = need_swap(phy_end, lhs_pcap.swapped);
00144 const bool rhs_sw = need_swap(phy_end, rhs_pcap.swapped);
00145
00146 const header* const lhs_phy = (reinterpret_cast<const header*>
00147 (lhs.bytes().get()));
00148 const header* const rhs_phy = (reinterpret_cast<const header*>
00149 (rhs.bytes().get()));
00150
00151
00152 return unsigned (std::abs(int (lhs_phy->mactime.get(lhs_sw) -
00153 rhs_phy->mactime.get(rhs_sw)))) <= prec;
00154 }
00155
00156 }
00157
00158 #endif // ! PRISM_HEADER_HXX_