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"
40 const uint32_t
MAGIC = 0xa1b2c3d4;
160 return ((val >> 8) & 0x00ff) | ((val << 8) & 0xff00);
167 return ((val >> 24) & 0x000000ff) | ((val >> 8) & 0x0000ff00) | ((val << 8) & 0x00ff0000) | ((val << 24) & 0xff000000);
201 m_file.seekp (0, std::ios::beg);
245 m_file.seekg (0, std::ios::beg);
272 m_file.setstate (std::ios::failbit);
292 m_file.setstate (std::ios::failbit);
301 m_file.setstate (std::ios::failbit);
319 mode |= std::ios::binary;
321 m_file.open (filename.c_str (), mode);
322 if (mode & std::ios::in)
330 PcapFile::Init (uint32_t dataLinkType, uint32_t snapLen, int32_t timeZoneCorrection,
bool swapMode)
332 NS_LOG_FUNCTION (
this << dataLinkType << snapLen << timeZoneCorrection << swapMode);
364 bool bigEndian = u.b[3];
390 Swap (&header, &header);
409 m_file.write ((
const char *)data, inclLen);
425 uint32_t totalSize = headerSize + p->
GetSize ();
431 uint32_t toCopy = std::min (headerSize, inclLen);
439 uint8_t *
const data,
447 NS_LOG_FUNCTION (
this << &data <<maxBytes << tsSec << tsUsec << inclLen << origLen << readLen);
456 m_file.read ((
char *)&header.m_tsSec,
sizeof(header.m_tsSec));
457 m_file.read ((
char *)&header.m_tsUsec,
sizeof(header.m_tsUsec));
458 m_file.read ((
char *)&header.m_inclLen,
sizeof(header.m_inclLen));
459 m_file.read ((
char *)&header.m_origLen,
sizeof(header.m_origLen));
468 Swap (&header, &header);
471 tsSec = header.m_tsSec;
472 tsUsec = header.m_tsUsec;
473 inclLen = header.m_inclLen;
474 origLen = header.m_origLen;
483 readLen = maxBytes < header.m_inclLen ? maxBytes : header.m_inclLen;
484 m_file.read ((
char *)data, readLen);
490 if (readLen < header.m_inclLen)
492 m_file.seekg (header.m_inclLen - readLen, std::ios::cur);
498 uint32_t & sec, uint32_t & usec,
503 pcap1.
Open (f1, std::ios::in);
504 pcap2.
Open (f2, std::ios::in);
505 bool bad = pcap1.
Fail () || pcap2.
Fail ();
511 uint8_t *data1 =
new uint8_t [snapLen] ();
512 uint8_t *data2 =
new uint8_t [snapLen] ();
515 uint32_t tsUsec1 = 0;
516 uint32_t tsUsec2 = 0;
517 uint32_t inclLen1 = 0;
518 uint32_t inclLen2 = 0;
519 uint32_t origLen1 = 0;
520 uint32_t origLen2 = 0;
521 uint32_t readLen1 = 0;
522 uint32_t readLen2 = 0;
525 while (!pcap1.
Eof () && !pcap2.
Eof ())
527 pcap1.
Read (data1, snapLen, tsSec1, tsUsec1, inclLen1, origLen1, readLen1);
528 pcap2.
Read (data2, snapLen, tsSec2, tsUsec2, inclLen2, origLen2, readLen2);
530 bool same = pcap1.
Fail () == pcap2.
Fail ();
541 if (tsSec1 != tsSec2 || tsUsec1 != tsUsec2)
547 if (readLen1 != readLen2)
553 if (std::memcmp (data1, data2, readLen1) != 0)
562 bad = pcap1.
Fail () || pcap2.
Fail ();
563 bool eof = pcap1.
Eof () && pcap2.
Eof ();