11#include "ns3/assert.h" 
   12#include "ns3/buffer.h" 
   13#include "ns3/build-profile.h" 
   14#include "ns3/fatal-error.h" 
   15#include "ns3/fatal-impl.h" 
   16#include "ns3/header.h" 
   18#include "ns3/packet.h" 
  161    return ((val >> 8) & 0x00ff) | ((val << 8) & 0xff00);
 
 
  168    return ((val >> 24) & 0x000000ff) | ((val >> 8) & 0x0000ff00) | ((val << 8) & 0x00ff0000) |
 
  169           ((val << 24) & 0xff000000);
 
 
  203    m_file.seekp(0, std::ios::beg);
 
 
  247    m_file.seekg(0, std::ios::beg);
 
  274        m_file.setstate(std::ios::failbit);
 
  301        m_file.setstate(std::ios::failbit);
 
  310        m_file.setstate(std::ios::failbit);
 
 
  328    mode |= std::ios::binary;
 
  331    m_file.open(filename, mode);
 
  332    if (mode & std::ios::in)
 
 
  346    NS_LOG_FUNCTION(
this << dataLinkType << snapLen << timeZoneCorrection << swapMode);
 
  391    bool bigEndian = u.b[3];
 
 
  417        Swap(&header, &header);
 
 
  446    p->CopyData(&
m_file, inclLen);
 
 
  455    uint32_t totalSize = headerSize + p->GetSize();
 
  461    uint32_t toCopy = std::min(headerSize, inclLen);
 
  464    p->CopyData(&
m_file, inclLen);
 
 
  476    NS_LOG_FUNCTION(
this << &
data << maxBytes << tsSec << tsUsec << inclLen << origLen << readLen);
 
  497        Swap(&header, &header);
 
 
  527               const std::string& f2,
 
  536    pcap1.
Open(f1, std::ios::in);
 
  537    pcap2.
Open(f2, std::ios::in);
 
  538    bool bad = pcap1.
Fail() || pcap2.
Fail();
 
  544    auto data1 = 
new uint8_t[snapLen]();
 
  545    auto data2 = 
new uint8_t[snapLen]();
 
  558    while (!pcap1.
Eof() && !pcap2.
Eof())
 
  560        pcap1.
Read(data1, snapLen, tsSec1, tsUsec1, inclLen1, origLen1, readLen1);
 
  561        pcap2.
Read(data2, snapLen, tsSec2, tsUsec2, inclLen2, origLen2, readLen2);
 
  563        bool same = pcap1.
Fail() == pcap2.
Fail();
 
  576        if (tsSec1 != tsSec2 || tsUsec1 != tsUsec2)
 
  582        if (readLen1 != readLen2)
 
  588        if (std::memcmp(data1, data2, readLen1) != 0)
 
  598    bool eof = pcap1.
Eof() && pcap2.
Eof();
 
 
automatically resized byte buffer
void CopyData(std::ostream *os, uint32_t size) const
Copy the specified amount of data from the buffer to the given output stream.
void AddAtStart(uint32_t start)
Buffer::Iterator Begin() const
A class representing a pcap file.
bool IsNanoSecMode()
Get the nanosecond mode of the file.
void Close()
Close the underlying file.
static bool Diff(const std::string &f1, const std::string &f2, uint32_t &sec, uint32_t &usec, uint32_t &packets, uint32_t snapLen=SNAPLEN_DEFAULT)
Compare two PCAP files packet-by-packet.
void Open(const std::string &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
uint32_t GetDataLinkType()
Returns the data link type field of the pcap file as defined by the network field in the pcap global ...
void Read(uint8_t *const data, uint32_t maxBytes, uint32_t &tsSec, uint32_t &tsUsec, uint32_t &inclLen, uint32_t &origLen, uint32_t &readLen)
Read next packet from file.
uint32_t GetMagic()
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global hea...
uint16_t GetVersionMajor()
Returns the major version of the pcap file as defined by the version_major field in the pcap global h...
std::string m_filename
file name
uint16_t GetVersionMinor()
Returns the minor version of the pcap file as defined by the version_minor field in the pcap global h...
PcapFileHeader m_fileHeader
file header
void Clear()
Clear all state bits of the underlying iostream.
uint32_t WritePacketHeader(uint32_t tsSec, uint32_t tsUsec, uint32_t totalLen)
Write a Pcap packet header.
void Init(uint32_t dataLinkType, uint32_t snapLen=SNAPLEN_DEFAULT, int32_t timeZoneCorrection=ZONE_DEFAULT, bool swapMode=false, bool nanosecMode=false)
Initialize the pcap file associated with this object.
void Write(uint32_t tsSec, uint32_t tsUsec, const uint8_t *const data, uint32_t totalLen)
Write next packet to file.
uint32_t GetSnapLen()
Returns the max length of saved packets field of the pcap file as defined by the snaplen field in the...
bool GetSwapMode()
Get the swap mode of the file.
bool m_nanosecMode
nanosecond timestamp mode
int32_t GetTimeZoneOffset()
Returns the time zone offset of the pcap file as defined by the thiszone field in the pcap global hea...
std::fstream m_file
file stream
void ReadAndVerifyFileHeader()
Read and verify a Pcap file header.
void WriteFileHeader()
Write a Pcap file header.
uint32_t GetSigFigs()
Returns the accuracy of timestamps field of the pcap file as defined by the sigfigs field in the pcap...
uint8_t Swap(uint8_t val)
Swap a value byte order.
Smart pointer class similar to boost::intrusive_ptr.
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file,...
#define NS_BUILD_DEBUG(code)
Execute a code snippet in debug builds.
void UnregisterStream(std::ostream *stream)
Unregister a stream for flushing on abnormal exit.
void RegisterStream(std::ostream *stream)
Register a stream to be flushed on abnormal exit.
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by ",...
Every class exported by the ns3 library is enclosed in the ns3 namespace.
const uint32_t MAGIC
Magic number identifying standard pcap file format.
const uint32_t NS_SWAPPED_MAGIC
Looks this way if byte swapping is required.
const uint32_t SWAPPED_MAGIC
Looks this way if byte swapping is required.
const uint16_t VERSION_MINOR
Minor version of supported pcap file format.
const uint32_t NS_MAGIC
Magic number identifying nanosec resolution pcap file format.
const uint16_t VERSION_MAJOR
Major version of supported pcap file format.