A Discrete-Event Network Simulator
API
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Properties Friends Macros Groups Pages
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, Header &header, Ptr<const Packet> p);
134 
143  void Write (Time t, uint8_t const *buffer, uint32_t length);
144 
153  uint32_t GetMagic (void);
154 
163  uint16_t GetVersionMajor (void);
164 
173  uint16_t GetVersionMinor (void);
174 
183  int32_t GetTimeZoneOffset (void);
184 
193  uint32_t GetSigFigs (void);
194 
203  uint32_t GetSnapLen (void);
204 
213  uint32_t GetDataLinkType (void);
214 
215 private:
217  uint32_t m_snapLen;
218 };
219 
220 } // namespace ns3
221 
222 #endif /* PCAP_FILE_WRAPPER_H */
Protocol header serialization and deserialization.
Definition: header.h:42
Simulation virtual time values and global simulation resolution.
Definition: nstime.h:79
uint32_t GetMagic(void)
Returns the magic number of the pcap file as defined by the magic_number field in the pcap global hea...
void Write(Time t, Ptr< const Packet > p)
Write the next packet to 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.
uint16_t GetVersionMajor(void)
Returns the major version of the pcap file as defined by the version_major field in the pcap global h...
uint32_t GetDataLinkType(void)
Returns the data link type field of the pcap file as defined by the network field in the pcap global ...
A class representing a pcap file.
Definition: pcap-file.h:42
static TypeId GetTypeId(void)
Get the type ID.
int32_t GetTimeZoneOffset(void)
Returns the time zone offset of the pcap file as defined by the thiszone field in the pcap global hea...
void Clear(void)
Clear all state bits of the underlying iostream.
static const int32_t ZONE_DEFAULT
Time zone offset for current location.
Definition: pcap-file.h:45
bool Eof(void) const
void Open(std::string const &filename, std::ios::openmode mode)
Create a new pcap file or open an existing pcap file.
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 GetSigFigs(void)
Returns the accuracy of timestamps field of the pcap file as defined by the sigfigs field in the pcap...
PcapFile m_file
Pcap file.
uint32_t m_snapLen
max length of saved packets
bool Fail(void) const
a base class which provides memory management and object aggregation
Definition: object.h:64
void Close(void)
Close the underlying pcap file.
A class that wraps a PcapFile as an ns3::Object and provides a higher-layer ns-3 interface to the low...
a unique identifier for an interface.
Definition: type-id.h:49
uint32_t GetSnapLen(void)
Returns the max length of saved packets field of the pcap file as defined by the snaplen field in the...