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 avs
00033 {
00034
00035 inline
00036 size_t
00037 header::len_impl(size_t caplen, bool) const
00038 {
00039 if (not caplen)
00040 return caplen + 1;
00041
00042 return tool::extract_big_endian_long_u(length);
00043 }
00044
00045 inline
00046 header::time_type
00047 header::time_get_impl(bool) const
00048 {
00049 return mactime_get();
00050 }
00051
00052 inline
00053 void
00054 header::time_set_impl(const time_type& t, bool)
00055 {
00056 const uint64_t v = t.get_impl();
00057
00058 if (not tool::endian::need_swap(tool::endian::big, false))
00059 mactime = v;
00060 else
00061 {
00062 const uint32_t lo = tool::extract_swapped_long_u(v & uint32_t (-1));
00063 const uint32_t hi = tool::extract_swapped_long_u(v >> 32);
00064
00065
00066
00067
00068 void* const v = static_cast<void*> (&mactime);
00069 uint32_t* const u = static_cast<uint32_t*> (v);
00070
00071 u[0] = hi;
00072 u[1] = lo;
00073 }
00074 }
00075
00076 template <class D1, class D2>
00077 bool
00078 header::eq_time(const pcapxx::frame_descriptor<D1>& lhs,
00079 const pcapxx::frame_descriptor<D2>& rhs,
00080 tool::endian::endianness ,
00081 unsigned prec)
00082 {
00083 const size_t lhs_caplen = lhs.pcap_header()->caplen;
00084 const size_t rhs_caplen = rhs.pcap_header()->caplen;
00085
00086 const header* const lhs_phy = (reinterpret_cast<const header*>
00087 (lhs.bytes().get()));
00088 const header* const rhs_phy = (reinterpret_cast<const header*>
00089 (rhs.bytes().get()));
00090
00091 if (lhs_phy->len(lhs_caplen, false) > lhs_caplen or
00092 rhs_phy->len(rhs_caplen, false) > rhs_caplen)
00093 return false;
00094
00095 return std::abs(int64_t (lhs_phy->mactime_get() -
00096 rhs_phy->mactime_get())) < prec;
00097 }
00098
00099 inline
00100 uint64_t
00101 header::mactime_get() const
00102 {
00103 return uint64_get(&mactime);
00104 }
00105
00106 inline
00107 uint64_t
00108 header::hosttime_get() const
00109 {
00110 return uint64_get(&hosttime);
00111 }
00112
00113 inline
00114 uint64_t
00115 header::uint64_get(const void* p)
00116 {
00117 if (not tool::endian::need_swap(tool::endian::big, false))
00118 return *static_cast<const uint64_t*> (p);
00119 else
00120 {
00121 const uint32_t* const p32 = static_cast<const uint32_t*> (p);
00122
00123 const uint32_t hi = tool::extract_big_endian_long_u(p32[0]);
00124 const uint32_t lo = tool::extract_big_endian_long_u(p32[1]);
00125
00126 return (uint64_t (hi) << 32) | lo;
00127 }
00128 }
00129
00130 }
00131
00132 #endif // ! AVS_HEADER_HXX_