include/wipal/pcap/dumper.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_DUMPER_HXX_
00023 # define PCAP_DUMPER_HXX_
00024 
00025 # include "dumper.hh"
00026 
00027 namespace pcapxx
00028 {
00029 
00030   inline
00031   dumper::dumper(const std::string&     filename,
00032                  int32_t                type,
00033                  int32_t                snaplen):
00034     file_name_ (filename),
00035     pkt_count_ (0),
00036     output_ (new std::ofstream (filename.c_str(), (std::ios::out   |
00037                                                    std::ios::trunc |
00038                                                    std::ios::binary)))
00039   {
00040     internals::file_header h;
00041 
00042     h.magic             = 0xa1b2c3d4;
00043     h.version_major     = internals::version_major;
00044     h.version_minor     = internals::version_minor;
00045     h.thiszone          = 0;
00046     h.sigfigs           = 0;
00047     h.snaplen           = snaplen;
00048     h.linktype          = type;
00049 
00050     if (not *output_.get())
00051       throw tool::file_error("Could not open file for writing");
00052     if (not output_->write(reinterpret_cast<char*> (&h), sizeof (h)))
00053       throw tool::write_error("Could not write PCAP file header");
00054 
00055     marks_.push_back(output_->tellp());
00056   }
00057 
00058   inline
00059   void
00060   dumper::operator () (const frame_descriptor& d)
00061   {
00062     return (*this) (d.pcap_header().get(), d.bytes().get());
00063   }
00064 
00065 } // End of namespace pcapxx.
00066 
00067 /* dumper::operator () (const pkthdr* h, const void* f)
00068  *
00069  *         and
00070  *
00071  * dumper::descriptor() const
00072  *
00073  * are implemented in descriptor.hxx.  (I know, that is ugly.  That is
00074  * to avoid circular dependancy issues.)
00075  */
00076 # include <wipal/pcap/descriptor.hh>
00077 
00078 #endif // ! PCAP_DESCRITPOR_HH_

Generated on Tue Jan 15 19:32:31 2008 for wipal by  doxygen 1.5.4