include/wipal/phy/prism_header.hxx

00001 /*
00002  * WiPal - A library and a set of tools to manipulate wireless traces.
00003  * Copyright (C) 2007  Universite Pierre et Marie Curie - Paris 6
00004  *
00005  * This program is free software; you can redistribute it and/or modify
00006  * it under the terms of the GNU General Public License as published by
00007  * the Free Software Foundation; either version 2 of the License, or
00008  * (at your option) any later version.
00009  *
00010  * This program is distributed in the hope that it will be useful,
00011  * but WITHOUT ANY WARRANTY; without even the implied warranty of
00012  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013  * GNU General Public License for more details.
00014  *
00015  * You should have received a copy of the GNU General Public License
00016  * along with this program; if not, write to the Free Software
00017  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
00018  * MA  02110-1301  USA
00019  *
00020  * Author: Thomas Claveirole <thomas.claveirole@lip6.fr>
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   inline
00033   uint32_t
00034   item::get(bool swapped) const
00035   {
00036     return tool::extract_long_u(data, swapped);
00037   }
00038 
00039   inline
00040   item&
00041   item::set(uint32_t value, bool swapped)
00042   {
00043     status = 0;
00044     data = tool::extract_long_u(value, swapped);
00045 
00046     return *this;
00047   }
00048 
00049   inline
00050   bool
00051   eq_80211(const header* lhs, size_t lhs_caplen,
00052            const header* rhs, size_t rhs_caplen)
00053   {
00054     const size_t caplen = std::min(lhs_caplen, rhs_caplen);
00055 
00056     if (caplen < sizeof (prism::header))
00057       return false;
00058 
00059     return 0 == memcmp(lhs + 1, rhs + 1, caplen - sizeof (prism::header));
00060   }
00061 
00062   inline
00063   bool
00064   eq_time_and_80211(const header* lhs, size_t lhs_caplen, bool lhs_swapped,
00065                     const header* rhs, size_t rhs_caplen, bool rhs_swapped,
00066                     unsigned    precision,
00067                     bool        check_hosttime)
00068   {
00069     const size_t caplen = std::min(lhs_caplen, rhs_caplen);
00070 
00071     if (caplen < sizeof (prism::header))
00072       return false;
00073 
00074     const unsigned dmac = std::abs(int (lhs->mactime.get(lhs_swapped) -
00075                                         rhs->mactime.get(rhs_swapped)));
00076 
00077     if (dmac > precision)
00078       return false;
00079 
00080     if (check_hosttime)
00081       {
00082         const unsigned dhost = std::abs(int (lhs->hosttime.get(lhs_swapped) -
00083                                              rhs->hosttime.get(rhs_swapped)));
00084 
00085         if (dhost > precision / 10)
00086           return false;
00087       }
00088 
00089     return 0 == memcmp(lhs + 1, rhs + 1, caplen - sizeof (prism::header));
00090   }
00091 
00092 } // End of namespace prism.
00093 
00094 #endif // ! PRISM_HEADER_HXX_

Generated on Tue Jan 15 19:32:31 2008 for wipal by  doxygen 1.5.4