src/network/utils/pcap-file-wrapper.h
author Vedran Miletić <rivanvx@gmail.com>
Sat, 01 Sep 2012 20:57:21 +0200
changeset 9063 32755d0516f4
parent 7386 2310ed220a61
child 10657 6531a8817def
permissions -rw-r--r--
Bug 1237 - code cleanups related to includes
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
7385
10beb0e53130 standardize emacs c++ mode comments
Vedran Miletić <rivanvx@gmail.com>
parents: 7353
diff changeset
     1
/* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     2
/*
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     3
 * Copyright (c) 2009 University of Washington
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     4
 *
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     5
 * This program is free software; you can redistribute it and/or modify
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     6
 * it under the terms of the GNU General Public License version 2 as
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     7
 * published by the Free Software Foundation;
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     8
 *
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
     9
 * This program is distributed in the hope that it will be useful,
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    10
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    11
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    12
 * GNU General Public License for more details.
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    13
 *
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    14
 * You should have received a copy of the GNU General Public License
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    15
 * along with this program; if not, write to the Free Software
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    16
 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    17
 */
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    18
6052
e146b9c9c7e7 PcapFileObject to PcapFileWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6041
diff changeset
    19
#ifndef PCAP_FILE_WRAPPER_H
e146b9c9c7e7 PcapFileObject to PcapFileWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6041
diff changeset
    20
#define PCAP_FILE_WRAPPER_H
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    21
9063
32755d0516f4 Bug 1237 - code cleanups related to includes
Vedran Miletić <rivanvx@gmail.com>
parents: 7386
diff changeset
    22
#include <cstring>
6056
27b8cb0963bf add missing include
Craig Dowell <craigdo@ee.washington.edu>
parents: 6052
diff changeset
    23
#include <limits>
6206
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    24
#include <fstream>
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    25
#include "ns3/ptr.h"
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    26
#include "ns3/packet.h"
6455
e17da5733c0b Change nix-vector to use SimpleRefCount instead of Object
Josh Pelkey <jpelkey@gatech.edu>
parents: 6206
diff changeset
    27
#include "ns3/object.h"
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    28
#include "ns3/nstime.h"
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    29
#include "pcap-file.h"
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    30
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    31
namespace ns3 {
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    32
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    33
/*
6101
6e16bf523c55 some doxygen updates got missed
Craig Dowell <craigdo@ee.washington.edu>
parents: 6056
diff changeset
    34
 * A class that wraps a PcapFile as an ns3::Object and provides a higher-layer
6e16bf523c55 some doxygen updates got missed
Craig Dowell <craigdo@ee.washington.edu>
parents: 6056
diff changeset
    35
 * ns-3 interface to the low-level public methods of PcapFile.  Users are
6e16bf523c55 some doxygen updates got missed
Craig Dowell <craigdo@ee.washington.edu>
parents: 6056
diff changeset
    36
 * encouraged to use this object instead of class ns3::PcapFile in ns-3
6e16bf523c55 some doxygen updates got missed
Craig Dowell <craigdo@ee.washington.edu>
parents: 6056
diff changeset
    37
 * public APIs.
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    38
 */
6052
e146b9c9c7e7 PcapFileObject to PcapFileWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6041
diff changeset
    39
class PcapFileWrapper : public Object
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    40
{
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    41
public:
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    42
  static TypeId GetTypeId (void);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    43
6052
e146b9c9c7e7 PcapFileObject to PcapFileWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6041
diff changeset
    44
  PcapFileWrapper ();
e146b9c9c7e7 PcapFileObject to PcapFileWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6041
diff changeset
    45
  ~PcapFileWrapper ();
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    46
6206
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    47
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    48
  /**
6206
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    49
   * \return true if the 'fail' bit is set in the underlying iostream, false otherwise.
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    50
   */
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    51
  bool Fail (void) const;
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    52
  /**
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    53
   * \return true if the 'eof' bit is set in the underlying iostream, false otherwise.
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    54
   */
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    55
  bool Eof (void) const;
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    56
  /**
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    57
   * Clear all state bits of the underlying iostream.
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    58
   */
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    59
  void Clear (void);
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    60
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    61
  /**
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    62
   * Create a new pcap file or open an existing pcap file.  Semantics are
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    63
   * similar to the stdc++ io stream classes.
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    64
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    65
   * Since a pcap file is always a binary file, the file type is automatically 
6206
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    66
   * selected as a binary file (fstream::binary is automatically ored with the mode
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    67
   * field).
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    68
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    69
   * \param filename String containing the name of the file.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    70
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    71
   * \param mode String containing the access mode for the file.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    72
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    73
   */
6206
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
    74
  void Open (std::string const &filename, std::ios::openmode mode);
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    75
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    76
  /**
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    77
   * Close the underlying pcap file.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    78
   */
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    79
  void Close (void);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
    80
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    81
  /**
6052
e146b9c9c7e7 PcapFileObject to PcapFileWrapper
Craig Dowell <craigdo@ee.washington.edu>
parents: 6041
diff changeset
    82
   * Initialize the pcap file associated with this wrapper.  This file must have
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    83
   * been previously opened with write permissions.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    84
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    85
   * \param dataLinkType A data link type as defined in the pcap library.  If
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    86
   * you want to make resulting pcap files visible in existing tools, the 
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    87
   * data link type must match existing definitions, such as PCAP_ETHERNET,
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    88
   * PCAP_PPP, PCAP_80211, etc.  If you are storing different kinds of packet
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    89
   * data, such as naked TCP headers, you are at liberty to locally define your
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    90
   * own data link types.  According to the pcap-linktype man page, "well-known"
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    91
   * pcap linktypes range from 0 to 177.  If you use a large random number for
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    92
   * your type, chances are small for a collision.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    93
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    94
   * \param snapLen An optional maximum size for packets written to the file.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    95
   * Defaults to 65535.  If packets exceed this length they are truncated.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    96
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    97
   * \param tzCorrection An integer describing the offset of your local
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    98
   * time zone from UTC/GMT.  For example, Pacific Standard Time in the US is
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
    99
   * GMT-8, so one would enter -8 for that correction.  Defaults to 0 (UTC).
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   100
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   101
   * \warning Calling this method on an existing file will result in the loss
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   102
   * any existing data.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   103
   */
6206
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
   104
  void Init (uint32_t dataLinkType, 
6041
b65c6d6794f8 Review feedback
Craig Dowell <craigdo@ee.washington.edu>
parents: 6040
diff changeset
   105
             uint32_t snapLen = std::numeric_limits<uint32_t>::max (), 
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   106
             int32_t tzCorrection = PcapFile::ZONE_DEFAULT);
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   107
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   108
  /**
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   109
   * \brief Write the next packet to file
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   110
   * 
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   111
   * \param t Packet timestamp as ns3::Time.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   112
   * \param p Packet to write to the pcap file.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   113
   * 
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   114
   */
6206
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
   115
  void Write (Time t, Ptr<const Packet> p);
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   116
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   117
  /**
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   118
   * \brief Write the provided header along with the packet to the pcap file.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   119
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   120
   * It is the case that adding a header to a packet prior to writing it to a
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   121
   * file must trigger a deep copy in the Packet.  By providing the header
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   122
   * separately, we can avoid that copy.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   123
   * 
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   124
   * \param t Packet timestamp as ns3::Time.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   125
   * \param header The Header to prepend to the packet.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   126
   * \param p Packet to write to the pcap file.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   127
   * 
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   128
   */
6206
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
   129
  void Write (Time t, Header &header, Ptr<const Packet> p);
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   130
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   131
  /**
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   132
   * \brief Write the provided data buffer to the pcap file.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   133
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   134
   * \param t Packet timestamp as ns3::Time.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   135
   * \param buffer The buffer to write.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   136
   * \param length The size of the buffer.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   137
   * 
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   138
   */
6206
9787dc9fdd84 bug 872: ns3::PcapFileWrapper::Write explodes stack
Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
parents: 6101
diff changeset
   139
  void Write (Time t, uint8_t const *buffer, uint32_t length);
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   140
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   141
  /*
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   142
   * \brief Returns the magic number of the pcap file as defined by the magic_number
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   143
   * field in the pcap global header.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   144
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   145
   * See http://wiki.wireshark.org/Development/LibpcapFileFormat
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   146
   */ 
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   147
  uint32_t GetMagic (void);
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   148
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   149
  /*
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   150
   * \brief Returns the major version of the pcap file as defined by the version_major
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   151
   * field in the pcap global header.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   152
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   153
   * See http://wiki.wireshark.org/Development/LibpcapFileFormat
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   154
   */ 
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   155
  uint16_t GetVersionMajor (void);
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   156
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   157
  /*
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   158
   * \brief Returns the minor version of the pcap file as defined by the version_minor
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   159
   * field in the pcap global header.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   160
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   161
   * See http://wiki.wireshark.org/Development/LibpcapFileFormat
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   162
   */ 
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   163
  uint16_t GetVersionMinor (void);
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   164
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   165
  /*
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   166
   * \brief Returns the time zone offset of the pcap file as defined by the thiszone
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   167
   * field in the pcap global header.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   168
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   169
   * See http://wiki.wireshark.org/Development/LibpcapFileFormat
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   170
   */ 
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   171
  int32_t GetTimeZoneOffset (void);
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   172
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   173
  /*
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   174
   * \brief Returns the accuracy of timestamps field of the pcap file as defined
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   175
   * by the sigfigs field in the pcap global header.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   176
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   177
   * See http://wiki.wireshark.org/Development/LibpcapFileFormat
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   178
   */ 
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   179
  uint32_t GetSigFigs (void);
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   180
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   181
  /*
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   182
   * \brief Returns the max length of saved packets field of the pcap file as 
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   183
   * defined by the snaplen field in the pcap global header.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   184
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   185
   * See http://wiki.wireshark.org/Development/LibpcapFileFormat
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   186
   */ 
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   187
  uint32_t GetSnapLen (void);
6040
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   188
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   189
  /*
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   190
   * \brief Returns the data link type field of the pcap file as defined by the 
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   191
   * network field in the pcap global header.
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   192
   *
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   193
   * See http://wiki.wireshark.org/Development/LibpcapFileFormat
a30eb0e5758a Add Doxygen
Craig Dowell <craigdo@ee.washington.edu>
parents: 6035
diff changeset
   194
   */ 
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   195
  uint32_t GetDataLinkType (void);
7182
5ecfee5d17de network coding style changes
Josh Pelkey <jpelkey@gatech.edu>
parents: 6823
diff changeset
   196
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   197
private:
6035
ecd8840c3573 add ability to pass a header to pcap file object
Craig Dowell <craigdo@ee.washington.edu>
parents: 6009
diff changeset
   198
  PcapFile m_file;
6041
b65c6d6794f8 Review feedback
Craig Dowell <craigdo@ee.washington.edu>
parents: 6040
diff changeset
   199
  uint32_t m_snapLen;
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   200
};
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   201
7386
2310ed220a61 standardize ns-3 namespace declaration format
Vedran Miletić <rivanvx@gmail.com>
parents: 7385
diff changeset
   202
} // namespace ns3
6009
e1b696a1ed28 redo pcap tracing
Craig Dowell <craigdo@ee.washington.edu>
parents:
diff changeset
   203
7353
09fccf6195ea bug 1203: Inconsistently named ifndef/define macros in ns-3 headers
Vedran Miletic <rivanvx@gmail.com>
parents: 7182
diff changeset
   204
#endif /* PCAP_FILE_WRAPPER_H */