include/trace-tools/pcap/descriptor.hh

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_DESCRIPTOR_HH_
00023 # define PCAP_DESCRIPTOR_HH_
00024 
00025 # include <string>
00026 
00027 # include <boost/optional.hpp>
00028 # include <boost/shared_ptr.hpp>
00029 
00030 # include <trace-tools/tool/iterator_base.hh>
00031 # include <trace-tools/tool/iterable.hh>
00032 # include <trace-tools/pcap/frame_iterator.hh>
00033 # include <trace-tools/pcap/typedefs.hh>
00034 # include <trace-tools/pcap/dumper.hh>
00035 
00037 namespace pcapxx
00038 {
00039 
00040   template <class D>
00041   struct descriptor;
00042 
00043 } // End of namespace pcapxx.
00044 
00045 namespace tool
00046 {
00047 
00049   template <class B>
00050   struct types< pcapxx::descriptor<B> >
00051   {
00053     typedef pcapxx::internals::frame_iterator<B, bottom>        iterator;
00054   };
00055 
00056 } // End of namespace tool.
00057 
00058 namespace pcapxx
00059 {
00060 
00085   template <class Bottom = tool::bottom>
00086   struct descriptor: tt_inherit(public tool::iterable, descriptor<Bottom>)
00087   {
00096     descriptor(const std::string& device, int snaplen, int promisc, int to_ms);
00097 
00099     descriptor(const std::string& fname);
00100 
00107     descriptor(int linktype, int snaplen);
00108 
00114     int                 datalink() const;
00115 
00117     bool                is_swapped() const;
00118 
00120     std::string         error() const;
00121 
00123     pcapxx::dumper      dumper(const std::string& fname) const;
00124 
00133     template <handler Callback>
00134     int
00135     loop(void* user = 0, int cnt = -1);
00136 
00137   private:
00138 
00140     struct wrapper_data
00141     {
00143       descriptor*       desc;
00144 
00146       void*             user;
00147     };
00148 
00150     template <handler H>
00151     static
00152     void
00153     handler_wrapper(u_char*, const pcap_pkthdr*, const u_char*);
00154 
00156     struct shared_data
00157     {
00158       shared_data(pcap_t*);
00159       ~shared_data();
00160 
00161       pcap_t*   desc;   
00162       unsigned  curr;   
00163     };
00164 
00165     boost::shared_ptr<shared_data> d_;
00166   };
00167 
00168 } // End of namespace pcapxx.
00169 
00170 # include "descriptor.hxx"
00171 
00172 #endif // ! PCAP_DESCRITPOR_HH_

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