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"
36 const uint32_t
MAGIC = 0xa1b2c3d4;
140 return ((val >> 8) & 0x00ff) | ((val << 8) & 0xff00);
146 return ((val >> 24) & 0x000000ff) | ((val >> 8) & 0x0000ff00) | ((val << 8) & 0x00ff0000) | ((val << 24) & 0xff000000);
177 m_file.seekp (0, std::ios::beg);
220 m_file.seekg (0, std::ios::beg);
247 m_file.setstate (std::ios::failbit);
267 m_file.setstate (std::ios::failbit);
276 m_file.setstate (std::ios::failbit);
293 mode |= std::ios::binary;
295 m_file.open (filename.c_str (), mode);
296 if (mode & std::ios::in)
304 PcapFile::Init (uint32_t dataLinkType, uint32_t snapLen, int32_t timeZoneCorrection,
bool swapMode)
337 bool bigEndian = u.b[3];
362 Swap (&header, &header);
380 m_file.write ((
const char *)data, inclLen);
394 uint32_t totalSize = headerSize + p->
GetSize ();
400 uint32_t toCopy = std::min (headerSize, inclLen);
408 uint8_t *
const data,
424 m_file.read ((
char *)&header.m_tsSec,
sizeof(header.m_tsSec));
425 m_file.read ((
char *)&header.m_tsUsec,
sizeof(header.m_tsUsec));
426 m_file.read ((
char *)&header.m_inclLen,
sizeof(header.m_inclLen));
427 m_file.read ((
char *)&header.m_origLen,
sizeof(header.m_origLen));
436 Swap (&header, &header);
439 tsSec = header.m_tsSec;
440 tsUsec = header.m_tsUsec;
441 inclLen = header.m_inclLen;
442 origLen = header.m_origLen;
451 readLen = maxBytes < header.m_inclLen ? maxBytes : header.m_inclLen;
452 m_file.read ((
char *)data, readLen);
458 if (readLen < header.m_inclLen)
460 m_file.seekg (header.m_inclLen - readLen, std::ios::cur);
466 uint32_t & sec, uint32_t & usec,
470 pcap1.
Open (f1, std::ios::in);
471 pcap2.
Open (f2, std::ios::in);
472 bool bad = pcap1.
Fail () || pcap2.
Fail ();
478 uint8_t *data1 =
new uint8_t [snapLen] ();
479 uint8_t *data2 =
new uint8_t [snapLen] ();
482 uint32_t tsUsec1 = 0;
483 uint32_t tsUsec2 = 0;
484 uint32_t inclLen1 = 0;
485 uint32_t inclLen2 = 0;
486 uint32_t origLen1 = 0;
487 uint32_t origLen2 = 0;
488 uint32_t readLen1 = 0;
489 uint32_t readLen2 = 0;
492 while (!pcap1.
Eof () && !pcap2.
Eof ())
494 pcap1.
Read (data1, snapLen, tsSec1, tsUsec1, inclLen1, origLen1, readLen1);
495 pcap2.
Read (data2, snapLen, tsSec2, tsUsec2, inclLen2, origLen2, readLen2);
497 bool same = pcap1.
Fail () == pcap2.
Fail ();
508 if (tsSec1 != tsSec2 || tsUsec1 != tsUsec2)
514 if (readLen1 != readLen2)
520 if (std::memcmp (data1, data2, readLen1) != 0)
529 bad = pcap1.
Fail () || pcap2.
Fail ();
530 bool eof = pcap1.
Eof () && pcap2.
Eof ();