include/wipal/pcap/descriptor.hh

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_DESCRIPTOR_HH_
00023 # define PCAP_DESCRIPTOR_HH_
00024 
00025 extern "C"
00026 {
00027 # include <inttypes.h>
00028 }
00029 # include <vector>
00030 # include <ios>
00031 # include <string>
00032 # include <cstdlib>
00033 
00034 # include <wipal/pcap/frame_iterator.hh>
00035 # include <wipal/tool/iterable.hh>
00036 # include <wipal/pcap/dumper.hh>
00037 
00039 namespace pcapxx
00040 {
00041 
00042   template <class D>
00043   struct descriptor;
00044 
00045 } // End of namespace pcapxx.
00046 
00047 namespace tool
00048 {
00049 
00051   template <class B>
00052   struct types< pcapxx::descriptor<B> >
00053   {
00055     typedef pcapxx::internals::frame_iterator<bottom>   iterator;
00056   };
00057 
00058 } // End of namespace tool.
00059 
00060 namespace pcapxx
00061 {
00062 
00087   template <class Bottom = tool::bottom>
00088   struct descriptor: wp_inherit(public tool::iterable, descriptor<Bottom>)
00089   {
00091 
00092     typedef wp_get_exact(Bottom, descriptor<Bottom>)    exact_type;
00093     typedef tool::iterable<exact_type>                  super_type;
00095 
00097     typedef wp_type(iterator, exact_type)               iterator;
00098 
00106     typedef std::vector<std::streampos>                 index_type;
00107 
00108     enum
00109     {
00120       mark_step = 4096,
00121 
00131       junk_len  = 4096
00132     };
00133 
00135     enum link_type
00136     {
00137       LOOP              = 0,    
00138       EN10MB            = 1,    
00139       EN3MB             = 2,    
00140       AX25              = 3,    
00141       PRONET            = 4,    
00142       CHAOS             = 5,    
00143       IEEE802           = 6,    
00144       ARCNET            = 7,    
00145       SLIP              = 8,    
00146       PPP               = 9,    
00147       FDDI              = 10,   
00148       IEEE802_11        = 105,  
00149       PRISM_HEADER      = 119,  
00150       RADIOTAP_HEADER   = 127   
00151     };
00152 
00154     descriptor(const std::string& filename, bool build_index = false);
00155 
00160     descriptor(const std::string&       filename,
00161                const index_type&        marks,
00162                unsigned                 pkt_count);
00163 
00180     template <typename ProgressInfoSetupType,
00181               typename ProgressInfoUpdateType>
00182     descriptor(const std::string&       filename,
00183                ProgressInfoSetupType&   pi_setup,
00184                ProgressInfoUpdateType&  pi_update);
00185 
00187     iterator            operator [] (size_t);
00188 
00190     size_t              size() const;
00191 
00193     bool                swapped() const;
00194 
00196     int32_t             zone() const;
00197 
00199     int32_t             snaplen() const;
00200 
00202     link_type           linktype() const;
00203 
00208     void                expect(link_type l) const;
00209 
00211     std::streampos      file_size() const;
00212 
00214     const std::string&  file_name() const;
00215 
00217     pcapxx::dumper      dumper(const std::string& fname) const;
00218 
00219   private:
00220     template <typename ProgressInfoSetupType,
00221               typename ProgressInfoUpdateType>
00222     void
00223     setup(const std::string&                    filename,
00224           bool                                  build_index,
00225           ProgressInfoSetupType&                pi_setup,
00226           ProgressInfoUpdateType&               pi_update);
00227 
00228     void                warn(const std::streampos&p, const std::string& msg);
00229     void                handle_truncation(const std::string& msg);
00230 
00231     template <typename ProgressInfoSetupType,
00232               typename ProgressInfoUpdateType>
00233     void
00234     setup_marks(std::istream&           f,
00235                 ProgressInfoSetupType&  pi_setup,
00236                 ProgressInfoUpdateType& pi_update);
00237 
00238     index_type          marks_;
00239 
00240     bool                swap_;
00241     int32_t             zone_;
00242     int32_t             snaplen_;
00243     link_type           type_;
00244     size_t              pkt_count_;
00245     std::streampos      file_size_;
00246     std::string         file_name_;
00247   };
00248 
00249 } // End of namespace pcapxx.
00250 
00251 # include "descriptor.hxx"
00252 
00253 #endif // ! PCAP_DESCRITPOR_HH_

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