00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 }
00066
00067
00068
00069
00070
00071
00072
00073
00074
00075
00076 # include <wipal/pcap/descriptor.hh>
00077
00078 #endif // ! PCAP_DESCRITPOR_HH_