include/trace-tools/pcap/frame_descriptor.hxx

00001 /*
00002  * trace-tools - 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_FRAME_DESCRIPTOR_HXX_
00023 # define PCAP_FRAME_DESCRIPTOR_HXX_
00024 
00025 # include <cstring>
00026 
00027 # include "frame_descriptor.hh"
00028 
00029 namespace pcapxx
00030 {
00031 
00032   inline
00033   frame_descriptor::frame_descriptor(const pkthdr* h, const void* b):
00034     pcap_header_ (new pkthdr (*h))
00035   {
00036     const size_t        caplen = pcap_header()->caplen;
00037     uint8_t* const      tmp = new uint8_t [caplen];
00038 
00039     memcpy(tmp, b, caplen);
00040     bytes_.reset(tmp, delete_uint8_t_array);
00041   }
00042 
00043   inline
00044   const frame_descriptor::pkthdr_ptr&
00045   frame_descriptor::pcap_header() const
00046   {
00047     return pcap_header_;
00048   }
00049 
00050   inline
00051   const frame_descriptor::bytes_ptr&
00052   frame_descriptor::bytes() const
00053   {
00054     return bytes_;
00055   }
00056 
00057   inline
00058   std::ostream&
00059   frame_descriptor::print(std::ostream& os) const
00060   {
00061     return os << pcap_header()->id;
00062   }
00063 
00064   inline
00065   bool
00066   frame_descriptor::operator == (const frame_descriptor& rhs) const
00067   {
00068     return
00069       not memcmp(pcap_header().get(), rhs.pcap_header().get(), sizeof (pkthdr))
00070       and
00071       not memcmp(bytes().get(), rhs.bytes().get(), pcap_header()->caplen);
00072   }
00073 
00074   inline
00075   bool
00076   frame_descriptor::operator != (const frame_descriptor& rhs) const
00077   {
00078     return not (*this == rhs);
00079   }
00080 
00081   inline
00082   void
00083   frame_descriptor::delete_uint8_t_array(uint8_t* a)
00084   {
00085     delete[] a;
00086   }
00087 
00088   inline
00089   std::ostream&
00090   operator << (std::ostream& os, const frame_descriptor& fd)
00091   {
00092     return fd.print(os);
00093   }
00094 
00095 } // End of namespace pcapxx.
00096 
00097 #endif // ! PCAP_FRAME_DESCRIPTOR_HXX_

Generated on Wed Sep 12 16:02:46 2007 for trace-tools by  doxygen 1.5.3