00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022 #ifndef AVS_HEADER_HXX_
00023 # define AVS_HEADER_HXX_
00024
00025 # include "avs_header.hh"
00026
00027 # include <stdexcept>
00028 # include <cstring>
00029
00030 # include <wipal/tool/endianness.hh>
00031
00032 namespace wpl
00033 {
00034
00035 namespace avs
00036 {
00037
00038 inline
00039 size_t
00040 header::len_impl(size_t caplen, bool) const
00041 {
00042 if (not caplen)
00043 return caplen + 1;
00044
00045 return tool::extract_big_endian_long_u(length);
00046 }
00047
00048 inline
00049 header::time_type
00050 header::time_get_impl(bool) const
00051 {
00052 return mactime_get();
00053 }
00054
00055 inline
00056 void
00057 header::time_set_impl(const time_type& t, bool)
00058 {
00059 const uint64_t v = t.get_impl();
00060
00061 if (not tool::need_swap(tool::end::big, false))
00062 mactime = v;
00063 else
00064 {
00065 const uint32_t lo = tool::extract_swapped_long_u(v & uint32_t (-1));
00066 const uint32_t hi = tool::extract_swapped_long_u(v >> 32);
00067
00068
00069
00070
00071 void* const v = static_cast<void*> (&mactime);
00072 uint32_t* const u = static_cast<uint32_t*> (v);
00073
00074 u[0] = hi;
00075 u[1] = lo;
00076 }
00077 }
00078
00079 template <class S1, class S2>
00080 bool
00081 header::eq_time(const pkt::packet<S1>& lhs,
00082 const pkt::packet<S2>& rhs,
00083 const unsigned prec,
00084 const tool::end::endianness )
00085 {
00086 const size_t lhs_caplen = lhs.meta().caplen;
00087 const size_t rhs_caplen = rhs.meta().caplen;
00088
00089 const header* const lhs_phy = (static_cast<const header*>
00090 (lhs.bytes()));
00091 const header* const rhs_phy = (static_cast<const header*>
00092 (rhs.bytes()));
00093
00094 if (lhs_phy->len(lhs_caplen, false) > lhs_caplen or
00095 rhs_phy->len(rhs_caplen, false) > rhs_caplen)
00096 return false;
00097
00098 return std::abs(int64_t (lhs_phy->mactime_get() -
00099 rhs_phy->mactime_get())) <= prec;
00100 }
00101
00102 inline
00103 uint64_t
00104 header::mactime_get() const
00105 {
00106 return uint64_get(&mactime);
00107 }
00108
00109 inline
00110 uint64_t
00111 header::hosttime_get() const
00112 {
00113 return uint64_get(&hosttime);
00114 }
00115
00116 inline
00117 uint64_t
00118 header::uint64_get(const void* p)
00119 {
00120 if (not tool::need_swap(tool::end::big, false))
00121 return *static_cast<const uint64_t*> (p);
00122 else
00123 {
00124 const uint32_t* const p32 = static_cast<const uint32_t*> (p);
00125
00126 const uint32_t hi = tool::extract_big_endian_long_u(p32[0]);
00127 const uint32_t lo = tool::extract_big_endian_long_u(p32[1]);
00128
00129 return (uint64_t (hi) << 32) | lo;
00130 }
00131 }
00132
00133 }
00134
00135 }
00136
00137 #endif // ! AVS_HEADER_HXX_