A Discrete-Event Network Simulator
API
pcap-file-wrapper.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2009 University of Washington
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2 as
6  * published by the Free Software Foundation;
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11  * GNU General Public License for more details.
12  *
13  * You should have received a copy of the GNU General Public License
14  * along with this program; if not, write to the Free Software
15  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16  */
17 
18 #ifndef PCAP_FILE_WRAPPER_H
19 #define PCAP_FILE_WRAPPER_H
20 
21 #include "pcap-file.h"
22 
23 #include "ns3/nstime.h"
24 #include "ns3/object.h"
25 #include "ns3/packet.h"
26 #include "ns3/ptr.h"
27 
28 #include <cstring>
29 #include <fstream>
30 #include <limits>
31 
32 namespace ns3
33 {
34 
41 class PcapFileWrapper : public Object
42 {
43  public:
48  static TypeId GetTypeId();
49 
51  ~PcapFileWrapper() override;
52 
56  bool Fail() const;
60  bool Eof() const;
64  void Clear();
65 
79  void Open(const std::string& filename, std::ios::openmode mode);
80 
84  void Close();
85 
109  void Init(uint32_t dataLinkType,
110  uint32_t snapLen = std::numeric_limits<uint32_t>::max(),
111  int32_t tzCorrection = PcapFile::ZONE_DEFAULT);
112 
120  void Write(Time t, Ptr<const Packet> p);
121 
134  void Write(Time t, const Header& header, Ptr<const Packet> p);
135 
144  void Write(Time t, const uint8_t* buffer, uint32_t length);
145 
152  Ptr<Packet> Read(Time& t);
153 
162  uint32_t GetMagic();
163 
172  uint16_t GetVersionMajor();
173 
182  uint16_t GetVersionMinor();
183 
192  int32_t GetTimeZoneOffset();
193 
202  uint32_t GetSigFigs();
203 
212  uint32_t GetSnapLen();
213 
222  uint32_t GetDataLinkType();
223 
224  private:
226  uint32_t m_snapLen;
228 };
229 
230 } // namespace ns3
231 
232 #endif /* PCAP_FILE_WRAPPER_H */
#define max(a, b)
Definition: 80211b.c:42
Protocol header serialization and deserialization.
Definition: header.h:44
A base class which provides memory management and object aggregation.
Definition: object.h:89
A class representing a pcap file.
Definition: pcap-file.h:43
static const int32_t ZONE_DEFAULT
Time zone offset for current location.
Definition: pcap-file.h:45
A class that wraps a PcapFile as an ns3::Object and provides a higher-layer ns-3 interface to the low...
Ptr< Packet > Read(Time &t)
Read the next packet from the file.
void Write(Time t, Ptr< const Packet > p)
Write the next packet to file.
static TypeId GetTypeId()
Get the type ID.
PcapFile m_file
Pcap file.
void Open(const std::string &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
int32_t GetTimeZoneOffset()
Returns the time zone offset of the pcap file as defined by the thiszone field in the pcap global hea...
uint32_t m_snapLen
max length of saved packets
uint32_t GetSigFigs()
Returns the accuracy of timestamps field of the pcap file as defined by the sigfigs field in the pcap...
void Close()
Close the underlying pcap file.
void Init(uint32_t dataLinkType, uint32_t snapLen=std::numeric_limits< uint32_t >::max(), int32_t tzCorrection=PcapFile::ZONE_DEFAULT)
Initialize the pcap file associated with this wrapper.
void Clear()
Clear all state bits of the underlying iostream.
uint32_t GetMagic()
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global hea...
uint16_t GetVersionMajor()
Returns the major version of the pcap file as defined by the version_major field in the pcap global h...
uint32_t GetSnapLen()
Returns the max length of saved packets field of the pcap file as defined by the snaplen field in the...
uint16_t GetVersionMinor()
Returns the minor version of the pcap file as defined by the version_minor field in the pcap global h...
uint32_t GetDataLinkType()
Returns the data link type field of the pcap file as defined by the network field in the pcap global ...
bool m_nanosecMode
Timestamps in nanosecond mode.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:105
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.