A Discrete-Event Network Simulator
API
pcap-file-wrapper.h
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 
19 #ifndef PCAP_FILE_WRAPPER_H
20 #define PCAP_FILE_WRAPPER_H
21 
22 #include <cstring>
23 #include <limits>
24 #include <fstream>
25 #include "ns3/ptr.h"
26 #include "ns3/packet.h"
27 #include "ns3/object.h"
28 #include "ns3/nstime.h"
29 #include "pcap-file.h"
30 
31 namespace ns3 {
32 
39 class PcapFileWrapper : public Object
40 {
41 public:
46  static TypeId GetTypeId (void);
47 
48  PcapFileWrapper ();
50 
51 
55  bool Fail (void) const;
59  bool Eof (void) const;
63  void Clear (void);
64 
78  void Open (std::string const &filename, std::ios::openmode mode);
79 
83  void Close (void);
84 
108  void Init (uint32_t dataLinkType,
109  uint32_t snapLen = std::numeric_limits<uint32_t>::max (),
110  int32_t tzCorrection = PcapFile::ZONE_DEFAULT);
111 
119  void Write (Time t, Ptr<const Packet> p);
120 
133  void Write (Time t, const Header &header, Ptr<const Packet> p);
134 
143  void Write (Time t, uint8_t const *buffer, uint32_t length);
144 
151  Ptr<Packet> Read (Time &t);
152 
161  uint32_t GetMagic (void);
162 
171  uint16_t GetVersionMajor (void);
172 
181  uint16_t GetVersionMinor (void);
182 
191  int32_t GetTimeZoneOffset (void);
192 
201  uint32_t GetSigFigs (void);
202 
211  uint32_t GetSnapLen (void);
212 
221  uint32_t GetDataLinkType (void);
222 
223 private:
225  uint32_t m_snapLen;
227 };
228 
229 } // namespace ns3
230 
231 #endif /* PCAP_FILE_WRAPPER_H */
#define max(a, b)
Definition: 80211b.c:43
Protocol header serialization and deserialization.
Definition: header.h:43
A base class which provides memory management and object aggregation.
Definition: object.h:88
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.
PcapFile m_file
Pcap file.
uint32_t GetDataLinkType(void)
Returns the data link type field of the pcap file as defined by the network field in the pcap global ...
void Clear(void)
Clear all state bits of the underlying iostream.
void Open(std::string const &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
uint32_t GetSnapLen(void)
Returns the max length of saved packets field of the pcap file as defined by the snaplen field in the...
void Close(void)
Close the underlying pcap file.
uint32_t m_snapLen
max length of saved packets
bool Fail(void) const
uint32_t GetSigFigs(void)
Returns the accuracy of timestamps field of the pcap file as defined by the sigfigs field in the pcap...
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.
static TypeId GetTypeId(void)
Get the type ID.
uint16_t GetVersionMajor(void)
Returns the major version of the pcap file as defined by the version_major field in the pcap global h...
bool Eof(void) const
uint16_t GetVersionMinor(void)
Returns the minor version of the pcap file as defined by the version_minor field in the pcap global h...
uint32_t GetMagic(void)
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global hea...
int32_t GetTimeZoneOffset(void)
Returns the time zone offset of the pcap file as defined by the thiszone field in the pcap global hea...
bool m_nanosecMode
Timestamps in nanosecond mode.
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:103
a unique identifier for an interface.
Definition: type-id.h:59
Every class exported by the ns3 library is enclosed in the ns3 namespace.