A Discrete-Event Network Simulator
API
pcap-file.cc
Go to the documentation of this file.
1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
2 /*
3  * Copyright (c) 2009 University of Washington
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2 as
7  * published by the Free Software Foundation;
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17  *
18  * Author: Craig Dowell (craigdo@ee.washington.edu)
19  */
20 
21 #include <iostream>
22 #include <cstring>
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"
29 #include "pcap-file.h"
30 #include "ns3/log.h"
31 #include "ns3/build-profile.h"
32 //
33 // This file is used as part of the ns-3 test framework, so please refrain from
34 // adding any ns-3 specific constructs such as Packet to this file.
35 //
36 
37 namespace ns3 {
38 
39 NS_LOG_COMPONENT_DEFINE ("PcapFile");
40 
41 const uint32_t MAGIC = 0xa1b2c3d4;
42 const uint32_t SWAPPED_MAGIC = 0xd4c3b2a1;
44 const uint32_t NS_MAGIC = 0xa1b23cd4;
45 const uint32_t NS_SWAPPED_MAGIC = 0xd43cb2a1;
47 const uint16_t VERSION_MAJOR = 2;
48 const uint16_t VERSION_MINOR = 4;
51  : m_file (),
52  m_swapMode (false)
53 {
54  NS_LOG_FUNCTION (this);
56 }
57 
59 {
60  NS_LOG_FUNCTION (this);
62  Close ();
63 }
64 
65 
66 bool
67 PcapFile::Fail (void) const
68 {
69  NS_LOG_FUNCTION (this);
70  return m_file.fail ();
71 }
72 bool
73 PcapFile::Eof (void) const
74 {
75  NS_LOG_FUNCTION (this);
76  return m_file.eof ();
77 }
78 void
80 {
81  NS_LOG_FUNCTION (this);
82  m_file.clear ();
83 }
84 
85 
86 void
88 {
89  NS_LOG_FUNCTION (this);
90  m_file.close ();
91 }
92 
93 uint32_t
95 {
96  NS_LOG_FUNCTION (this);
98 }
99 
100 uint16_t
102 {
103  NS_LOG_FUNCTION (this);
105 }
106 
107 uint16_t
109 {
110  NS_LOG_FUNCTION (this);
112 }
113 
114 int32_t
116 {
117  NS_LOG_FUNCTION (this);
118  return m_fileHeader.m_zone;
119 }
120 
121 uint32_t
123 {
124  NS_LOG_FUNCTION (this);
125  return m_fileHeader.m_sigFigs;
126 }
127 
128 uint32_t
130 {
131  NS_LOG_FUNCTION (this);
132  return m_fileHeader.m_snapLen;
133 }
134 
135 uint32_t
137 {
138  NS_LOG_FUNCTION (this);
139  return m_fileHeader.m_type;
140 }
141 
142 bool
144 {
145  NS_LOG_FUNCTION (this);
146  return m_swapMode;
147 }
148 
149 uint8_t
150 PcapFile::Swap (uint8_t val)
151 {
152  NS_LOG_FUNCTION (this << static_cast<uint32_t> (val));
153  return val;
154 }
155 
156 uint16_t
157 PcapFile::Swap (uint16_t val)
158 {
159  NS_LOG_FUNCTION (this << val);
160  return ((val >> 8) & 0x00ff) | ((val << 8) & 0xff00);
161 }
162 
163 uint32_t
164 PcapFile::Swap (uint32_t val)
165 {
166  NS_LOG_FUNCTION (this << val);
167  return ((val >> 24) & 0x000000ff) | ((val >> 8) & 0x0000ff00) | ((val << 8) & 0x00ff0000) | ((val << 24) & 0xff000000);
168 }
169 
170 void
172 {
173  NS_LOG_FUNCTION (this << from << to);
174  to->m_magicNumber = Swap (from->m_magicNumber);
175  to->m_versionMajor = Swap (from->m_versionMajor);
176  to->m_versionMinor = Swap (from->m_versionMinor);
177  to->m_zone = Swap (uint32_t (from->m_zone));
178  to->m_sigFigs = Swap (from->m_sigFigs);
179  to->m_snapLen = Swap (from->m_snapLen);
180  to->m_type = Swap (from->m_type);
181 }
182 
183 void
185 {
186  NS_LOG_FUNCTION (this << from << to);
187  to->m_tsSec = Swap (from->m_tsSec);
188  to->m_tsUsec = Swap (from->m_tsUsec);
189  to->m_inclLen = Swap (from->m_inclLen);
190  to->m_origLen = Swap (from->m_origLen);
191 }
192 
193 void
195 {
196  NS_LOG_FUNCTION (this);
197  //
198  // If we're initializing the file, we need to write the pcap file header
199  // at the start of the file.
200  //
201  m_file.seekp (0, std::ios::beg);
202 
203  //
204  // We have the ability to write out the pcap file header in a foreign endian
205  // format, so we need a temp place to swap on the way out.
206  //
207  PcapFileHeader header;
208 
209  //
210  // the pointer headerOut selects either the swapped or non-swapped version of
211  // the pcap file header.
212  //
213  PcapFileHeader *headerOut = 0;
214 
215  if (m_swapMode == false)
216  {
217  headerOut = &m_fileHeader;
218  }
219  else
220  {
221  Swap (&m_fileHeader, &header);
222  headerOut = &header;
223  }
224 
225  //
226  // Watch out for memory alignment differences between machines, so write
227  // them all individually.
228  //
229  m_file.write ((const char *)&headerOut->m_magicNumber, sizeof(headerOut->m_magicNumber));
230  m_file.write ((const char *)&headerOut->m_versionMajor, sizeof(headerOut->m_versionMajor));
231  m_file.write ((const char *)&headerOut->m_versionMinor, sizeof(headerOut->m_versionMinor));
232  m_file.write ((const char *)&headerOut->m_zone, sizeof(headerOut->m_zone));
233  m_file.write ((const char *)&headerOut->m_sigFigs, sizeof(headerOut->m_sigFigs));
234  m_file.write ((const char *)&headerOut->m_snapLen, sizeof(headerOut->m_snapLen));
235  m_file.write ((const char *)&headerOut->m_type, sizeof(headerOut->m_type));
236 }
237 
238 void
240 {
241  NS_LOG_FUNCTION (this);
242  //
243  // Pcap file header is always at the start of the file
244  //
245  m_file.seekg (0, std::ios::beg);
246 
247  //
248  // Watch out for memory alignment differences between machines, so read
249  // them all individually.
250  //
254  m_file.read ((char *)&m_fileHeader.m_zone, sizeof(m_fileHeader.m_zone));
255  m_file.read ((char *)&m_fileHeader.m_sigFigs, sizeof(m_fileHeader.m_sigFigs));
256  m_file.read ((char *)&m_fileHeader.m_snapLen, sizeof(m_fileHeader.m_snapLen));
257  m_file.read ((char *)&m_fileHeader.m_type, sizeof(m_fileHeader.m_type));
258 
259  if (m_file.fail ())
260  {
261  return;
262  }
263 
264  //
265  // There are four possible magic numbers that can be there. Normal and byte
266  // swapped versions of the standard magic number, and normal and byte swapped
267  // versions of the magic number indicating nanosecond resolution timestamps.
268  //
269  if (m_fileHeader.m_magicNumber != MAGIC && m_fileHeader.m_magicNumber != SWAPPED_MAGIC &&
270  m_fileHeader.m_magicNumber != NS_MAGIC && m_fileHeader.m_magicNumber != NS_SWAPPED_MAGIC)
271  {
272  m_file.setstate (std::ios::failbit);
273  }
274 
275  //
276  // If the magic number is swapped, then we can assume that everything else we read
277  // is swapped.
278  //
279  m_swapMode = (m_fileHeader.m_magicNumber == SWAPPED_MAGIC
280  || m_fileHeader.m_magicNumber == NS_SWAPPED_MAGIC) ? true : false;
281 
282  if (m_swapMode)
283  {
285  }
286 
287  //
288  // We only deal with one version of the pcap file format.
289  //
290  if (m_fileHeader.m_versionMajor != VERSION_MAJOR || m_fileHeader.m_versionMinor != VERSION_MINOR)
291  {
292  m_file.setstate (std::ios::failbit);
293  }
294 
295  //
296  // A quick test of reasonablness for the time zone offset corresponding to
297  // a real place on the planet.
298  //
299  if (m_fileHeader.m_zone < -12 || m_fileHeader.m_zone > 12)
300  {
301  m_file.setstate (std::ios::failbit);
302  }
303 
304  if (m_file.fail ())
305  {
306  m_file.close ();
307  }
308 }
309 
310 void
311 PcapFile::Open (std::string const &filename, std::ios::openmode mode)
312 {
313  NS_LOG_FUNCTION (this << filename << mode);
314  NS_ASSERT ((mode & std::ios::app) == 0);
315  NS_ASSERT (!m_file.fail ());
316  //
317  // All pcap files are binary files, so we just do this automatically.
318  //
319  mode |= std::ios::binary;
320 
321  m_file.open (filename.c_str (), mode);
322  if (mode & std::ios::in)
323  {
324  // will set the fail bit if file header is invalid.
326  }
327 }
328 
329 void
330 PcapFile::Init (uint32_t dataLinkType, uint32_t snapLen, int32_t timeZoneCorrection, bool swapMode)
331 {
332  NS_LOG_FUNCTION (this << dataLinkType << snapLen << timeZoneCorrection << swapMode);
333  //
334  // Initialize the in-memory file header.
335  //
339  m_fileHeader.m_zone = timeZoneCorrection;
341  m_fileHeader.m_snapLen = snapLen;
342  m_fileHeader.m_type = dataLinkType;
343 
344  //
345  // We use pcap files for regression testing. We do byte-for-byte comparisons
346  // in those tests to determine pass or fail. If we allow big endian systems
347  // to write big endian headers, they will end up byte-swapped and the
348  // regression tests will fail. Until we get rid of the regression tests, we
349  // have to pick an endianness and stick with it. The precedent is little
350  // endian, so we set swap mode if required to pick little endian.
351  //
352  // We do want to allow a user or test suite to enable swapmode irrespective
353  // of what we decide here, so we allow setting swapmode from formal parameter
354  // as well.
355  //
356  // So, determine the endianness of the running system.
357  //
358  union {
359  uint32_t a;
360  uint8_t b[4];
361  } u;
362 
363  u.a = 1;
364  bool bigEndian = u.b[3];
365 
366  //
367  // And set swap mode if requested or we are on a big-endian system.
368  //
369  m_swapMode = swapMode | bigEndian;
370 
371  WriteFileHeader ();
372 }
373 
374 uint32_t
375 PcapFile::WritePacketHeader (uint32_t tsSec, uint32_t tsUsec, uint32_t totalLen)
376 {
377  NS_LOG_FUNCTION (this << tsSec << tsUsec << totalLen);
378  NS_ASSERT (m_file.good ());
379 
380  uint32_t inclLen = totalLen > m_fileHeader.m_snapLen ? m_fileHeader.m_snapLen : totalLen;
381 
382  PcapRecordHeader header;
383  header.m_tsSec = tsSec;
384  header.m_tsUsec = tsUsec;
385  header.m_inclLen = inclLen;
386  header.m_origLen = totalLen;
387 
388  if (m_swapMode)
389  {
390  Swap (&header, &header);
391  }
392 
393  //
394  // Watch out for memory alignment differences between machines, so write
395  // them all individually.
396  //
397  m_file.write ((const char *)&header.m_tsSec, sizeof(header.m_tsSec));
398  m_file.write ((const char *)&header.m_tsUsec, sizeof(header.m_tsUsec));
399  m_file.write ((const char *)&header.m_inclLen, sizeof(header.m_inclLen));
400  m_file.write ((const char *)&header.m_origLen, sizeof(header.m_origLen));
401  NS_BUILD_DEBUG(m_file.flush());
402  return inclLen;
403 }
404 
405 void
406 PcapFile::Write (uint32_t tsSec, uint32_t tsUsec, uint8_t const * const data, uint32_t totalLen)
407 {
408  NS_LOG_FUNCTION (this << tsSec << tsUsec << &data << totalLen);
409  uint32_t inclLen = WritePacketHeader (tsSec, tsUsec, totalLen);
410  m_file.write ((const char *)data, inclLen);
411  NS_BUILD_DEBUG(m_file.flush());
412 }
413 
414 void
415 PcapFile::Write (uint32_t tsSec, uint32_t tsUsec, Ptr<const Packet> p)
416 {
417  NS_LOG_FUNCTION (this << tsSec << tsUsec << p);
418  uint32_t inclLen = WritePacketHeader (tsSec, tsUsec, p->GetSize ());
419  p->CopyData (&m_file, inclLen);
420  NS_BUILD_DEBUG(m_file.flush());
421 }
422 
423 void
424 PcapFile::Write (uint32_t tsSec, uint32_t tsUsec, const Header &header, Ptr<const Packet> p)
425 {
426  NS_LOG_FUNCTION (this << tsSec << tsUsec << &header << p);
427  uint32_t headerSize = header.GetSerializedSize ();
428  uint32_t totalSize = headerSize + p->GetSize ();
429  uint32_t inclLen = WritePacketHeader (tsSec, tsUsec, totalSize);
430 
431  Buffer headerBuffer;
432  headerBuffer.AddAtStart (headerSize);
433  header.Serialize (headerBuffer.Begin ());
434  uint32_t toCopy = std::min (headerSize, inclLen);
435  headerBuffer.CopyData (&m_file, toCopy);
436  inclLen -= toCopy;
437  p->CopyData (&m_file, inclLen);
438 }
439 
440 void
442  uint8_t * const data,
443  uint32_t maxBytes,
444  uint32_t &tsSec,
445  uint32_t &tsUsec,
446  uint32_t &inclLen,
447  uint32_t &origLen,
448  uint32_t &readLen)
449 {
450  NS_LOG_FUNCTION (this << &data <<maxBytes << tsSec << tsUsec << inclLen << origLen << readLen);
451  NS_ASSERT (m_file.good ());
452 
453  PcapRecordHeader header;
454 
455  //
456  // Watch out for memory alignment differences between machines, so read
457  // them all individually.
458  //
459  m_file.read ((char *)&header.m_tsSec, sizeof(header.m_tsSec));
460  m_file.read ((char *)&header.m_tsUsec, sizeof(header.m_tsUsec));
461  m_file.read ((char *)&header.m_inclLen, sizeof(header.m_inclLen));
462  m_file.read ((char *)&header.m_origLen, sizeof(header.m_origLen));
463 
464  if (m_file.fail ())
465  {
466  return;
467  }
468 
469  if (m_swapMode)
470  {
471  Swap (&header, &header);
472  }
473 
474  tsSec = header.m_tsSec;
475  tsUsec = header.m_tsUsec;
476  inclLen = header.m_inclLen;
477  origLen = header.m_origLen;
478 
479  //
480  // We don't always want to force the client to keep a maximum length buffer
481  // around so we allow her to specify a minimum number of bytes to read.
482  // Usually 64 bytes is enough information to print all of the headers, so
483  // it isn't typically necessary to read all thousand bytes of an echo packet,
484  // for example, to figure out what is going on.
485  //
486  readLen = maxBytes < header.m_inclLen ? maxBytes : header.m_inclLen;
487  m_file.read ((char *)data, readLen);
488 
489  //
490  // To keep the file pointer pointed in the right place, however, we always
491  // need to account for the entire packet as stored originally.
492  //
493  if (readLen < header.m_inclLen)
494  {
495  m_file.seekg (header.m_inclLen - readLen, std::ios::cur);
496  }
497 }
498 
499 bool
500 PcapFile::Diff (std::string const & f1, std::string const & f2,
501  uint32_t & sec, uint32_t & usec, uint32_t & packets,
502  uint32_t snapLen)
503 {
504  NS_LOG_FUNCTION (f1 << f2 << sec << usec << snapLen);
505  PcapFile pcap1, pcap2;
506  pcap1.Open (f1, std::ios::in);
507  pcap2.Open (f2, std::ios::in);
508  bool bad = pcap1.Fail () || pcap2.Fail ();
509  if (bad)
510  {
511  return true;
512  }
513 
514  uint8_t *data1 = new uint8_t [snapLen] ();
515  uint8_t *data2 = new uint8_t [snapLen] ();
516  uint32_t tsSec1 = 0;
517  uint32_t tsSec2 = 0;
518  uint32_t tsUsec1 = 0;
519  uint32_t tsUsec2 = 0;
520  uint32_t inclLen1 = 0;
521  uint32_t inclLen2 = 0;
522  uint32_t origLen1 = 0;
523  uint32_t origLen2 = 0;
524  uint32_t readLen1 = 0;
525  uint32_t readLen2 = 0;
526  bool diff = false;
527 
528  while (!pcap1.Eof () && !pcap2.Eof ())
529  {
530  pcap1.Read (data1, snapLen, tsSec1, tsUsec1, inclLen1, origLen1, readLen1);
531  pcap2.Read (data2, snapLen, tsSec2, tsUsec2, inclLen2, origLen2, readLen2);
532 
533  bool same = pcap1.Fail () == pcap2.Fail ();
534  if (!same)
535  {
536  diff = true;
537  break;
538  }
539  if (pcap1.Eof ())
540  {
541  break;
542  }
543 
544  ++packets;
545 
546  if (tsSec1 != tsSec2 || tsUsec1 != tsUsec2)
547  {
548  diff = true; // Next packet timestamps do not match
549  break;
550  }
551 
552  if (readLen1 != readLen2)
553  {
554  diff = true; // Packet lengths do not match
555  break;
556  }
557 
558  if (std::memcmp (data1, data2, readLen1) != 0)
559  {
560  diff = true; // Packet data do not match
561  break;
562  }
563  }
564  sec = tsSec1;
565  usec = tsUsec1;
566 
567  bad = pcap1.Fail () || pcap2.Fail ();
568  bool eof = pcap1.Eof () && pcap2.Eof ();
569  if (bad && !eof)
570  {
571  diff = true;
572  }
573 
574  delete[] data1;
575  delete[] data2;
576 
577  return diff;
578 }
579 
580 } // namespace ns3
Protocol header serialization and deserialization.
Definition: header.h:42
void AddAtStart(uint32_t start)
Definition: buffer.cc:309
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
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.
Definition: pcap-file.cc:500
uint32_t m_tsSec
seconds part of timestamp
Definition: pcap-file.h:297
uint8_t Swap(uint8_t val)
Swap a value byte order.
Definition: pcap-file.cc:150
void WriteFileHeader(void)
Write a Pcap file header.
Definition: pcap-file.cc:194
uint16_t GetVersionMinor(void)
Returns the minor version of the pcap file as defined by the version_minor field in the pcap global h...
Definition: pcap-file.cc:108
automatically resized byte buffer
Definition: buffer.h:92
Pcap file header.
Definition: pcap-file.h:283
#define NS_ASSERT(condition)
At runtime, in debugging builds, if this condition is not true, the program prints the source file...
Definition: assert.h:67
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition: log.h:201
uint32_t GetSize(void) const
Returns the the size in bytes of the packet (including the zero-filled initial payload).
Definition: packet.h:786
const uint16_t VERSION_MAJOR
Major version of supported pcap file format.
Definition: pcap-file.cc:47
uint16_t m_versionMajor
Major version identifying the version of pcap used in this file.
Definition: pcap-file.h:285
uint32_t m_origLen
actual length of original packet
Definition: pcap-file.h:300
bool Eof(void) const
Definition: pcap-file.cc:73
const uint32_t SWAPPED_MAGIC
Looks this way if byte swapping is required.
Definition: pcap-file.cc:42
Pcap record header.
Definition: pcap-file.h:296
bool GetSwapMode(void)
Get the swap mode of the file.
Definition: pcap-file.cc:143
A class representing a pcap file.
Definition: pcap-file.h:42
uint32_t m_tsUsec
microseconds part of timestamp (nsecs for PCAP_NSEC_MAGIC)
Definition: pcap-file.h:298
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.
Definition: pcap-file.cc:441
uint8_t data[writeSize]
void RegisterStream(std::ostream *stream)
Register a stream to be flushed on abnormal exit.
Definition: fatal-impl.cc:98
virtual void Serialize(Buffer::Iterator start) const =0
void CopyData(std::ostream *os, uint32_t size) const
Copy the specified amount of data from the buffer to the given output stream.
Definition: buffer.cc:715
Buffer::Iterator Begin(void) const
Definition: buffer.h:1063
uint32_t m_snapLen
Maximum length of packet data stored in records.
Definition: pcap-file.h:289
bool m_swapMode
swap mode
Definition: pcap-file.h:359
PcapFileHeader m_fileHeader
file header
Definition: pcap-file.h:358
uint32_t GetMagic(void)
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global hea...
Definition: pcap-file.cc:94
Every class exported by the ns3 library is enclosed in the ns3 namespace.
uint32_t m_sigFigs
Unused by pretty much everybody.
Definition: pcap-file.h:288
void Clear(void)
Clear all state bits of the underlying iostream.
Definition: pcap-file.cc:79
virtual uint32_t GetSerializedSize(void) const =0
void ReadAndVerifyFileHeader(void)
Read and verify a Pcap file header.
Definition: pcap-file.cc:239
const uint32_t NS_SWAPPED_MAGIC
Looks this way if byte swapping is required.
Definition: pcap-file.cc:45
uint32_t WritePacketHeader(uint32_t tsSec, uint32_t tsUsec, uint32_t totalLen)
Write a Pcap packet header.
Definition: pcap-file.cc:375
void Init(uint32_t dataLinkType, uint32_t snapLen=SNAPLEN_DEFAULT, int32_t timeZoneCorrection=ZONE_DEFAULT, bool swapMode=false)
Initialize the pcap file associated with this object.
Definition: pcap-file.cc:330
uint32_t GetSigFigs(void)
Returns the accuracy of timestamps field of the pcap file as defined by the sigfigs field in the pcap...
Definition: pcap-file.cc:122
void Close(void)
Close the underlying file.
Definition: pcap-file.cc:87
uint16_t m_versionMinor
Minor version identifying the version of pcap used in this file.
Definition: pcap-file.h:286
uint16_t GetVersionMajor(void)
Returns the major version of the pcap file as defined by the version_major field in the pcap global h...
Definition: pcap-file.cc:101
uint32_t m_inclLen
number of octets of packet saved in file
Definition: pcap-file.h:299
void Open(std::string const &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
Definition: pcap-file.cc:311
uint32_t m_magicNumber
Magic number identifying this as a pcap file.
Definition: pcap-file.h:284
uint32_t m_type
Data link type of packet data.
Definition: pcap-file.h:290
void UnregisterStream(std::ostream *stream)
Unregister a stream for flushing on abnormal exit.
Definition: fatal-impl.cc:105
bool Fail(void) const
Definition: pcap-file.cc:67
const uint16_t VERSION_MINOR
Minor version of supported pcap file format.
Definition: pcap-file.cc:48
std::fstream m_file
file stream
Definition: pcap-file.h:357
const uint32_t NS_MAGIC
Magic number identifying nanosec resolution pcap file format.
Definition: pcap-file.cc:44
#define NS_BUILD_DEBUG(code)
Execute a code snippet in debug builds.
Definition: build-profile.h:63
uint32_t CopyData(uint8_t *buffer, uint32_t size) const
Copy the packet contents to a byte buffer.
Definition: packet.cc:354
int32_t m_zone
Time zone correction to be applied to timestamps of packets.
Definition: pcap-file.h:287
const uint32_t MAGIC
Magic number identifying standard pcap file format.
Definition: pcap-file.cc:41
uint32_t GetDataLinkType(void)
Returns the data link type field of the pcap file as defined by the network field in the pcap global ...
Definition: pcap-file.cc:136
void Write(uint32_t tsSec, uint32_t tsUsec, uint8_t const *const data, uint32_t totalLen)
Write next packet to file.
Definition: pcap-file.cc:406
uint32_t GetSnapLen(void)
Returns the max length of saved packets field of the pcap file as defined by the snaplen field in the...
Definition: pcap-file.cc:129
int32_t GetTimeZoneOffset(void)
Returns the time zone offset of the pcap file as defined by the thiszone field in the pcap global hea...
Definition: pcap-file.cc:115