23#include "ns3/assert.h" 
   24#include "ns3/packet.h" 
   25#include "ns3/fatal-error.h" 
   26#include "ns3/fatal-impl.h" 
   27#include "ns3/header.h" 
   28#include "ns3/buffer.h" 
   31#include "ns3/build-profile.h" 
  168  return ((val >> 8) & 0x00ff) | ((val << 8) & 0xff00);
 
  175  return ((val >> 24) & 0x000000ff) | ((val >> 8) & 0x0000ff00) | ((val << 8) & 0x00ff0000) | ((val << 24) & 0xff000000);
 
  209  m_file.seekp (0, std::ios::beg);
 
  253  m_file.seekg (0, std::ios::beg);
 
  280      m_file.setstate (std::ios::failbit);
 
  306      m_file.setstate (std::ios::failbit);
 
  315      m_file.setstate (std::ios::failbit);
 
  333  mode |= std::ios::binary;
 
  336  m_file.open (filename.c_str (), mode);
 
  337  if (mode & std::ios::in)
 
  347  NS_LOG_FUNCTION (
this << dataLinkType << snapLen << timeZoneCorrection << swapMode);
 
  392  bool bigEndian = u.b[3];
 
  418      Swap (&header, &header);
 
  470  uint8_t * 
const data,
 
  478  NS_LOG_FUNCTION (
this << &
data <<maxBytes << tsSec << tsUsec << inclLen << origLen << readLen);
 
  499      Swap (&header, &header);
 
  534  pcap1.
Open (f1, std::ios::in);
 
  535  pcap2.
Open (f2, std::ios::in);
 
  536  bool bad = pcap1.
Fail () || pcap2.
Fail ();
 
  542  uint8_t *data1 = 
new uint8_t [snapLen] ();
 
  543  uint8_t *data2 = 
new uint8_t [snapLen] ();
 
  556  while (!pcap1.
Eof () && !pcap2.
Eof ())
 
  558      pcap1.
Read (data1, snapLen, tsSec1, tsUsec1, inclLen1, origLen1, readLen1);
 
  559      pcap2.
Read (data2, snapLen, tsSec2, tsUsec2, inclLen2, origLen2, readLen2);
 
  561      bool same = pcap1.
Fail () == pcap2.
Fail ();
 
  574      if (tsSec1 != tsSec2 || tsUsec1 != tsUsec2)
 
  580      if (readLen1 != readLen2)
 
  586      if (std::memcmp (data1, data2, readLen1) != 0)
 
  595  bad = pcap1.
Fail () || pcap2.
Fail ();
 
  596  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(void) const
 
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
 
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
 
A class representing a pcap file.
 
void Open(std::string const &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
 
uint16_t GetVersionMajor(void)
Returns the major version of the pcap file as defined by the version_major field in the pcap global h...
 
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 GetSnapLen(void)
Returns the max length of saved packets field of the pcap file as defined by the snaplen field in the...
 
static bool Diff(std::string const &f1, std::string const &f2, uint32_t &sec, uint32_t &usec, uint32_t &packets, uint32_t snapLen=SNAPLEN_DEFAULT)
Compare two PCAP files packet-by-packet.
 
std::string m_filename
file name
 
void Write(uint32_t tsSec, uint32_t tsUsec, uint8_t const *const data, uint32_t totalLen)
Write next packet to file.
 
PcapFileHeader m_fileHeader
file header
 
uint32_t WritePacketHeader(uint32_t tsSec, uint32_t tsUsec, uint32_t totalLen)
Write a Pcap packet header.
 
void Clear(void)
Clear all state bits of the underlying iostream.
 
void WriteFileHeader(void)
Write a Pcap file header.
 
uint32_t GetSigFigs(void)
Returns the accuracy of timestamps field of the pcap file as defined by the sigfigs field in the pcap...
 
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.
 
uint32_t GetDataLinkType(void)
Returns the data link type field of the pcap file as defined by the network field in the pcap global ...
 
void ReadAndVerifyFileHeader(void)
Read and verify a Pcap file header.
 
bool IsNanoSecMode(void)
Get the nanosecond mode of the file.
 
uint32_t GetMagic(void)
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global hea...
 
bool m_nanosecMode
nanosecond timestamp mode
 
std::fstream m_file
file stream
 
void Close(void)
Close the underlying file.
 
uint16_t GetVersionMinor(void)
Returns the minor version of the pcap file as defined by the version_minor field in the pcap global h...
 
int32_t GetTimeZoneOffset(void)
Returns the time zone offset of the pcap file as defined by the thiszone field in the pcap global hea...
 
bool GetSwapMode(void)
Get the swap mode of the file.
 
uint8_t Swap(uint8_t val)
Swap a value byte order.
 
#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.