6009
|
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 |
#include "pcap-file-object.h"
|
|
20 |
#include "ns3/log.h"
|
|
21 |
|
|
22 |
NS_LOG_COMPONENT_DEFINE ("PcapFileObject");
|
|
23 |
|
|
24 |
namespace ns3 {
|
|
25 |
|
|
26 |
NS_OBJECT_ENSURE_REGISTERED (PcapFileObject);
|
|
27 |
|
|
28 |
TypeId
|
|
29 |
PcapFileObject::GetTypeId (void)
|
|
30 |
{
|
|
31 |
static TypeId tid = TypeId ("ns3::PcapFileObject")
|
|
32 |
.SetParent<Object> ()
|
|
33 |
.AddConstructor<PcapFileObject> ()
|
|
34 |
;
|
|
35 |
return tid;
|
|
36 |
}
|
|
37 |
|
|
38 |
|
|
39 |
PcapFileObject::PcapFileObject ()
|
|
40 |
{
|
|
41 |
}
|
|
42 |
|
|
43 |
PcapFileObject::~PcapFileObject ()
|
|
44 |
{
|
|
45 |
Close ();
|
|
46 |
}
|
|
47 |
|
|
48 |
void
|
|
49 |
PcapFileObject::Close (void)
|
|
50 |
{
|
|
51 |
file.Close ();
|
|
52 |
}
|
|
53 |
|
|
54 |
bool
|
|
55 |
PcapFileObject::Open (std::string const &filename, std::string const &mode)
|
|
56 |
{
|
|
57 |
return file.Open (filename, mode);
|
|
58 |
}
|
|
59 |
|
|
60 |
bool
|
|
61 |
PcapFileObject::Init (uint32_t dataLinkType, uint32_t snapLen, int32_t tzCorrection)
|
|
62 |
{
|
|
63 |
return file.Init (dataLinkType, snapLen, tzCorrection);
|
|
64 |
}
|
|
65 |
|
|
66 |
bool
|
|
67 |
PcapFileObject::Write (Time t, Ptr<const Packet> p)
|
|
68 |
{
|
|
69 |
uint64_t current = t.GetMicroSeconds ();
|
|
70 |
uint64_t s = current / 1000000;
|
|
71 |
uint64_t us = current % 1000000;
|
|
72 |
|
|
73 |
uint32_t bufferSize = p->GetSize ();
|
|
74 |
uint8_t *buffer = new uint8_t[bufferSize];
|
|
75 |
p->CopyData (buffer, bufferSize);
|
|
76 |
bool rc = file.Write (s, us, buffer, bufferSize);
|
|
77 |
delete [] buffer;
|
|
78 |
return rc;
|
|
79 |
}
|
|
80 |
|
|
81 |
bool
|
|
82 |
PcapFileObject::Write (Time t, uint8_t const *buffer, uint32_t length)
|
|
83 |
{
|
|
84 |
uint64_t current = t.GetMicroSeconds ();
|
|
85 |
uint64_t s = current / 1000000;
|
|
86 |
uint64_t us = current % 1000000;
|
|
87 |
|
|
88 |
return file.Write (s, us, buffer, length);
|
|
89 |
}
|
|
90 |
|
|
91 |
uint32_t
|
|
92 |
PcapFileObject::GetMagic (void)
|
|
93 |
{
|
|
94 |
return file.GetMagic ();
|
|
95 |
}
|
|
96 |
|
|
97 |
uint16_t
|
|
98 |
PcapFileObject::GetVersionMajor (void)
|
|
99 |
{
|
|
100 |
return file.GetVersionMajor ();
|
|
101 |
}
|
|
102 |
|
|
103 |
uint16_t
|
|
104 |
PcapFileObject::GetVersionMinor (void)
|
|
105 |
{
|
|
106 |
return file.GetVersionMinor ();
|
|
107 |
}
|
|
108 |
|
|
109 |
int32_t
|
|
110 |
PcapFileObject::GetTimeZoneOffset (void)
|
|
111 |
{
|
|
112 |
return file.GetTimeZoneOffset ();
|
|
113 |
}
|
|
114 |
|
|
115 |
uint32_t
|
|
116 |
PcapFileObject::GetSigFigs (void)
|
|
117 |
{
|
|
118 |
return file.GetSigFigs ();
|
|
119 |
}
|
|
120 |
|
|
121 |
uint32_t
|
|
122 |
PcapFileObject::GetSnapLen (void)
|
|
123 |
{
|
|
124 |
return file.GetSnapLen ();
|
|
125 |
}
|
|
126 |
|
|
127 |
uint32_t
|
|
128 |
PcapFileObject::GetDataLinkType (void)
|
|
129 |
{
|
|
130 |
return file.GetDataLinkType ();
|
|
131 |
}
|
|
132 |
|
|
133 |
} //namespace ns3
|