00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
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 }
00096
00097 #endif // ! PCAP_FRAME_DESCRIPTOR_HXX_