00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 }
00068
00069 #endif // ! PCAP_FIND_HH_