include/wipal/pcap/find.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 PCAP_FIND_HXX_
00023 # define PCAP_FIND_HXX_
00024 
00025 # include "find.hh"
00026 
00027 # include <cassert>
00028 # include <algorithm>
00029 
00030 namespace pcapxx
00031 {
00032 
00033   inline
00034   match::match(const vector_of_bytes& bytes, size_t first, size_t last):
00035     bytes_ (bytes),
00036     first_ (first),
00037     last_ (last)
00038   {
00039     assert(first_ < last_);
00040     assert(bytes_.size() <= last_ - first_);
00041   }
00042 
00043   inline
00044   bool
00045   match::operator == (const frame_descriptor& rhs) const
00046   {
00047     const size_t        caplen = rhs.pcap_header()->caplen;
00048 
00049     if (first_ > caplen)
00050       return false;
00051 
00052     const uint8_t* const        bytes = rhs.bytes().get();
00053     const uint8_t* const        first = bytes + first_;
00054     const uint8_t* const        last = bytes + std::min(caplen, last_);
00055 
00056     return std::search(first, last, bytes_.begin(), bytes_.end()) != last;
00057   }
00058 
00059   inline
00060   bool
00061   operator == (const frame_descriptor& rhs, const match& lhs)
00062   {
00063     return lhs == rhs;
00064   }
00065 
00066 
00067 } // End of namespace pcapxx.
00068 
00069 #endif // ! PCAP_FIND_HH_

Generated on Wed Jan 16 16:15:14 2008 for wipal by  doxygen 1.5.4