Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pcap-Net
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Pcap-Net
Commits
ce9ee300
Commit
ce9ee300
authored
Aug 07, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Some refactoring.
parent
d40e339a
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
180 additions
and
52 deletions
+180
-52
UInt48.cs
PcapDotNet/src/PcapDotNet.Base/UInt48.cs
+1
-0
PacketDumpFileTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PacketDumpFileTests.cs
+81
-0
PcapDotNet.Core.Test.csproj
...tNet/src/PcapDotNet.Core.Test/PcapDotNet.Core.Test.csproj
+1
-1
WiresharkCompareTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
+2
-10
PacketCommunicator.cpp
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.cpp
+2
-24
PacketCommunicator.h
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.h
+0
-10
PacketDumpFile.cpp
PcapDotNet/src/PcapDotNet.Core/PacketDumpFile.cpp
+1
-1
PacketHeader.cpp
PcapDotNet/src/PcapDotNet.Core/PacketHeader.cpp
+2
-2
PacketSampleStatistics.cpp
PcapDotNet/src/PcapDotNet.Core/PacketSampleStatistics.cpp
+2
-2
PacketTimestamp.cpp
PcapDotNet/src/PcapDotNet.Core/PacketTimestamp.cpp
+48
-0
PacketTimestamp.h
PcapDotNet/src/PcapDotNet.Core/PacketTimestamp.h
+38
-0
WinPCapDotNet.Core.vcproj
PcapDotNet/src/PcapDotNet.Core/WinPCapDotNet.Core.vcproj
+2
-2
No files found.
PcapDotNet/src/PcapDotNet.Base/UInt48.cs
View file @
ce9ee300
...
@@ -28,6 +28,7 @@ namespace PcapDotNet.Base
...
@@ -28,6 +28,7 @@ namespace PcapDotNet.Base
/// A bitwise combination of NumberStyles values that indicates the permitted format of s.
/// A bitwise combination of NumberStyles values that indicates the permitted format of s.
/// A typical value to specify is NumberStyles.Integer.
/// A typical value to specify is NumberStyles.Integer.
/// </param>
/// </param>
/// <param name="provider">An System.IFormatProvider that supplies culture-specific formatting information about value.</param>
/// <returns>A 48-bit unsigned integer equivalent to the number specified in s.</returns>
/// <returns>A 48-bit unsigned integer equivalent to the number specified in s.</returns>
public
static
UInt48
Parse
(
string
value
,
NumberStyles
style
,
IFormatProvider
provider
)
public
static
UInt48
Parse
(
string
value
,
NumberStyles
style
,
IFormatProvider
provider
)
{
{
...
...
PcapDotNet/src/PcapDotNet.Core.Test/
DumpPackets
Tests.cs
→
PcapDotNet/src/PcapDotNet.Core.Test/
PacketDumpFile
Tests.cs
View file @
ce9ee300
using
System
;
using
System
;
using
System.IO
;
using
System.IO
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets
;
using
PcapDotNet.Packets
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.TestUtils
;
using
PcapDotNet.TestUtils
;
namespace
PcapDotNet.Core.Test
namespace
PcapDotNet.Core.Test
{
{
/// <summary>
/// Summary description for DumpPacketsTests
/// </summary>
[
TestClass
]
public
class
DumpPacketsTests
{
public
DumpPacketsTests
()
{
//
// TODO: Add constructor logic here
//
}
private
TestContext
testContextInstance
;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public
TestContext
TestContext
{
get
{
return
testContextInstance
;
}
set
{
testContextInstance
=
value
;
}
}
#
region
Additional
test
attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#
endregion
[
TestMethod
]
public
void
DumpIpV4PacketTest
()
{
MacAddress
ethernetSource
=
new
MacAddress
(
"00:01:02:03:04:05"
);
MacAddress
ethernetDestination
=
new
MacAddress
(
"A0:A1:A2:A3:A4:A5"
);
Random
random
=
new
Random
();
using
(
PacketCommunicator
communicator
=
LivePacketDeviceTests
.
OpenLiveDevice
())
{
using
(
PacketDumpFile
dumpFile
=
communicator
.
OpenDump
(
@"c:\wow.pcap"
))
{
for
(
int
i
=
0
;
i
!=
1000
;
++
i
)
{
byte
ipV4TypeOfService
=
random
.
NextByte
();
ushort
ipV4Identification
=
random
.
NextUShort
();
byte
ipV4Ttl
=
random
.
NextByte
();
IpV4FragmentationOptions
ipV4FragmentationFlags
=
random
.
NextEnum
<
IpV4FragmentationOptions
>();
ushort
ipV4FragmentationOffset
=
(
ushort
)(
random
.
NextUShort
()
/
8
*
8
);
IpV4Fragmentation
ipV4Fragmentation
=
new
IpV4Fragmentation
(
ipV4FragmentationFlags
,
ipV4FragmentationOffset
);
IpV4Protocol
ipV4Protocol
=
random
.
NextEnum
<
IpV4Protocol
>();
IpV4Address
ipV4Source
=
new
IpV4Address
(
random
.
NextUInt
());
IpV4Address
ipV4Destination
=
new
IpV4Address
(
random
.
NextUInt
());
IpV4Options
ipV4Options
=
random
.
NextIpV4Options
();
byte
[]
ipV4PayloadBuffer
=
new
byte
[
random
.
Next
(
0
,
50
*
1024
)];
random
.
NextBytes
(
ipV4PayloadBuffer
);
Datagram
ipV4Payload
=
new
Datagram
(
ipV4PayloadBuffer
);
Packet
packet
=
PacketBuilder
.
EthernetIpV4
(
DateTime
.
Now
,
ethernetSource
,
ethernetDestination
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
ipV4Protocol
,
ipV4Source
,
ipV4Destination
,
ipV4Options
,
ipV4Payload
);
dumpFile
.
Dump
(
packet
);
dumpFile
.
Flush
();
}
}
}
}
}
/// <summary>
/// <summary>
/// Summary description for PacketDumpFileTests
/// Summary description for PacketDumpFileTests
/// </summary>
/// </summary>
...
@@ -165,7 +65,7 @@ namespace PcapDotNet.Core.Test
...
@@ -165,7 +65,7 @@ namespace PcapDotNet.Core.Test
string
filename
=
Path
.
GetTempPath
()
+
@"dump.pcap"
;
string
filename
=
Path
.
GetTempPath
()
+
@"dump.pcap"
;
Packet
expectedPacket
=
PacketBuilder
.
Ethernet
(
DateTime
.
Now
,
new
MacAddress
(
1
),
new
MacAddress
(
2
),
EthernetType
.
QInQ
,
Packet
expectedPacket
=
PacketBuilder
.
Ethernet
(
DateTime
.
Now
,
new
MacAddress
(
1
),
new
MacAddress
(
2
),
EthernetType
.
QInQ
,
new
Datagram
(
new
byte
[]
{
1
,
2
,
3
}));
new
Datagram
(
new
byte
[]
{
1
,
2
,
3
}));
PacketDumpFile
.
Dump
(
filename
,
new
PcapDataLink
(
DataLinkKind
.
Ethernet
),
PacketDevice
.
DefaultSnapshotLength
,
PacketDumpFile
.
Dump
(
filename
,
new
PcapDataLink
(
DataLinkKind
.
Ethernet
),
PacketDevice
.
DefaultSnapshotLength
,
new
[]
{
expectedPacket
});
new
[]
{
expectedPacket
});
...
...
PcapDotNet/src/PcapDotNet.Core.Test/PcapDotNet.Core.Test.csproj
View file @
ce9ee300
...
@@ -47,11 +47,11 @@
...
@@ -47,11 +47,11 @@
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Compile Include="BerkeleyPacketFilterTests.cs" />
<Compile Include="BerkeleyPacketFilterTests.cs" />
<Compile Include="DumpPacketsTests.cs" />
<Compile Include="MoreAssert.cs" />
<Compile Include="MoreAssert.cs" />
<Compile Include="LivePacketDeviceTests.cs" />
<Compile Include="LivePacketDeviceTests.cs" />
<Compile Include="MoreIpV4Option.cs" />
<Compile Include="MoreIpV4Option.cs" />
<Compile Include="MoreXElement.cs" />
<Compile Include="MoreXElement.cs" />
<Compile Include="PacketDumpFileTests.cs" />
<Compile Include="PacketHandler.cs" />
<Compile Include="PacketHandler.cs" />
<Compile Include="OfflinePacketDeviceTests.cs" />
<Compile Include="OfflinePacketDeviceTests.cs" />
<Compile Include="PacketSendBufferTests.cs" />
<Compile Include="PacketSendBufferTests.cs" />
...
...
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
View file @
ce9ee300
...
@@ -87,7 +87,7 @@ namespace PcapDotNet.Core.Test
...
@@ -87,7 +87,7 @@ namespace PcapDotNet.Core.Test
Random
random
=
new
Random
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
!=
numPackets
;
++
i
)
for
(
int
i
=
0
;
i
!=
numPackets
;
++
i
)
{
{
DateTime
packetTimestamp
=
random
.
NextDateTime
(
Packet
Communicator
.
MinimumPacketTimestamp
,
PacketCommunicator
.
MaximumPacketTimestamp
);
DateTime
packetTimestamp
=
random
.
NextDateTime
(
Packet
Timestamp
.
MinimumPacketTimestamp
,
PacketTimestamp
.
MaximumPacketTimestamp
);
if
(
random
.
NextBool
())
if
(
random
.
NextBool
())
{
{
yield
return
yield
return
...
@@ -315,14 +315,6 @@ namespace PcapDotNet.Core.Test
...
@@ -315,14 +315,6 @@ namespace PcapDotNet.Core.Test
return
optionFieldShow
;
return
optionFieldShow
;
});
});
// List<string> strings1 = new List<string>(optionShows);
// List<string> strings2 = new List<string>(option.GetWiresharkSubfieldStrings());
// for (int i = 0; i != strings1.Count; ++i )
// {
// Assert.AreEqual(strings1[i], strings2[i]);
// }
Assert
.
IsTrue
(
optionShows
.
SequenceEqual
(
option
.
GetWiresharkSubfieldStrings
()));
Assert
.
IsTrue
(
optionShows
.
SequenceEqual
(
option
.
GetWiresharkSubfieldStrings
()));
}
}
}
}
...
@@ -355,7 +347,7 @@ namespace PcapDotNet.Core.Test
...
@@ -355,7 +347,7 @@ namespace PcapDotNet.Core.Test
DateTime
fieldTimestamp
=
fieldShow
[
4
]
==
' '
DateTime
fieldTimestamp
=
fieldShow
[
4
]
==
' '
?
DateTime
.
ParseExact
(
fieldShow
,
"MMM d, yyyy HH:mm:ss.fffffff"
,
CultureInfo
.
InvariantCulture
)
?
DateTime
.
ParseExact
(
fieldShow
,
"MMM d, yyyy HH:mm:ss.fffffff"
,
CultureInfo
.
InvariantCulture
)
:
DateTime
.
ParseExact
(
fieldShow
,
"MMM dd, yyyy HH:mm:ss.fffffff"
,
CultureInfo
.
InvariantCulture
);
:
DateTime
.
ParseExact
(
fieldShow
,
"MMM dd, yyyy HH:mm:ss.fffffff"
,
CultureInfo
.
InvariantCulture
);
MoreAssert
.
IsInRange
(
fieldTimestamp
.
AddSeconds
(-
0.5
),
fieldTimestamp
.
AddSeconds
(
0.5
),
packet
.
Timestamp
);
MoreAssert
.
IsInRange
(
fieldTimestamp
.
AddSeconds
(-
1
),
fieldTimestamp
.
AddSeconds
(
1
),
packet
.
Timestamp
);
break
;
break
;
case
"frame.len"
:
case
"frame.len"
:
...
...
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.cpp
View file @
ce9ee300
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
#include "MarshalingServices.h"
#include "MarshalingServices.h"
#include "PacketDumpFile.h"
#include "PacketDumpFile.h"
#include "Timestamp.h"
#include "
Packet
Timestamp.h"
#include "PcapError.h"
#include "PcapError.h"
#include "Pcap.h"
#include "Pcap.h"
...
@@ -14,28 +14,6 @@ using namespace System::Collections::Generic;
...
@@ -14,28 +14,6 @@ using namespace System::Collections::Generic;
using
namespace
PcapDotNet
::
Packets
;
using
namespace
PcapDotNet
::
Packets
;
using
namespace
PcapDotNet
::
Core
;
using
namespace
PcapDotNet
::
Core
;
// static
DateTime
PacketCommunicator
::
MinimumPacketTimestamp
::
get
()
{
timeval
zeroTimeValue
;
zeroTimeValue
.
tv_sec
=
Int32
::
MinValue
;
zeroTimeValue
.
tv_usec
=
Int32
::
MinValue
;
DateTime
result
;
Timestamp
::
PcapTimestampToDateTime
(
zeroTimeValue
,
result
);
return
result
;
}
// static
DateTime
PacketCommunicator
::
MaximumPacketTimestamp
::
get
()
{
timeval
maxTimeValue
;
maxTimeValue
.
tv_sec
=
Int32
::
MaxValue
;
maxTimeValue
.
tv_usec
=
Int32
::
MaxValue
;
DateTime
result
;
Timestamp
::
PcapTimestampToDateTime
(
maxTimeValue
,
result
);
return
result
;
}
PcapDataLink
PacketCommunicator
::
DataLink
::
get
()
PcapDataLink
PacketCommunicator
::
DataLink
::
get
()
{
{
return
PcapDataLink
(
pcap_datalink
(
_pcapDescriptor
));
return
PcapDataLink
(
pcap_datalink
(
_pcapDescriptor
));
...
@@ -341,7 +319,7 @@ InvalidOperationException^ PacketCommunicator::BuildInvalidOperation(System::Str
...
@@ -341,7 +319,7 @@ InvalidOperationException^ PacketCommunicator::BuildInvalidOperation(System::Str
Packet
^
PacketCommunicator
::
CreatePacket
(
const
pcap_pkthdr
&
packetHeader
,
const
unsigned
char
*
packetData
,
IDataLink
^
dataLink
)
Packet
^
PacketCommunicator
::
CreatePacket
(
const
pcap_pkthdr
&
packetHeader
,
const
unsigned
char
*
packetData
,
IDataLink
^
dataLink
)
{
{
DateTime
timestamp
;
DateTime
timestamp
;
Timestamp
::
PcapTimestampToDateTime
(
packetHeader
.
ts
,
timestamp
);
Packet
Timestamp
::
PcapTimestampToDateTime
(
packetHeader
.
ts
,
timestamp
);
array
<
Byte
>^
managedPacketData
=
MarshalingServices
::
UnamangedToManagedByteArray
(
packetData
,
0
,
packetHeader
.
caplen
);
array
<
Byte
>^
managedPacketData
=
MarshalingServices
::
UnamangedToManagedByteArray
(
packetData
,
0
,
packetHeader
.
caplen
);
return
gcnew
Packet
(
managedPacketData
,
timestamp
,
dataLink
);
return
gcnew
Packet
(
managedPacketData
,
timestamp
,
dataLink
);
...
...
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.h
View file @
ce9ee300
...
@@ -23,16 +23,6 @@ namespace PcapDotNet { namespace Core
...
@@ -23,16 +23,6 @@ namespace PcapDotNet { namespace Core
public
ref
class
PacketCommunicator
abstract
:
System
::
IDisposable
public
ref
class
PacketCommunicator
abstract
:
System
::
IDisposable
{
{
public
:
public
:
static
property
System
::
DateTime
MinimumPacketTimestamp
{
System
::
DateTime
get
();
}
static
property
System
::
DateTime
MaximumPacketTimestamp
{
System
::
DateTime
get
();
}
/// <summary>
/// <summary>
/// The link layer of an adapter.
/// The link layer of an adapter.
/// </summary>
/// </summary>
...
...
PcapDotNet/src/PcapDotNet.Core/PacketDumpFile.cpp
View file @
ce9ee300
#include "PacketDumpFile.h"
#include "PacketDumpFile.h"
#include "Timestamp.h"
#include "
Packet
Timestamp.h"
#include "PacketHeader.h"
#include "PacketHeader.h"
#include "MarshalingServices.h"
#include "MarshalingServices.h"
#include "PcapError.h"
#include "PcapError.h"
...
...
PcapDotNet/src/PcapDotNet.Core/PacketHeader.cpp
View file @
ce9ee300
#include "PacketHeader.h"
#include "PacketHeader.h"
#include "Pcap.h"
#include "Pcap.h"
#include "Timestamp.h"
#include "
Packet
Timestamp.h"
using
namespace
PcapDotNet
::
Core
;
using
namespace
PcapDotNet
::
Core
;
using
namespace
PcapDotNet
::
Packets
;
using
namespace
PcapDotNet
::
Packets
;
...
@@ -8,7 +8,7 @@ using namespace PcapDotNet::Packets;
...
@@ -8,7 +8,7 @@ using namespace PcapDotNet::Packets;
// static
// static
void
PacketHeader
::
GetPcapHeader
(
pcap_pkthdr
&
header
,
Packet
^
packet
)
void
PacketHeader
::
GetPcapHeader
(
pcap_pkthdr
&
header
,
Packet
^
packet
)
{
{
Timestamp
::
DateTimeToPcapTimestamp
(
packet
->
Timestamp
,
header
.
ts
);
Packet
Timestamp
::
DateTimeToPcapTimestamp
(
packet
->
Timestamp
,
header
.
ts
);
header
.
len
=
packet
->
Length
;
header
.
len
=
packet
->
Length
;
header
.
caplen
=
packet
->
Length
;
header
.
caplen
=
packet
->
Length
;
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core/PacketSampleStatistics.cpp
View file @
ce9ee300
#include "PacketSampleStatistics.h"
#include "PacketSampleStatistics.h"
#include "Timestamp.h"
#include "
Packet
Timestamp.h"
#include "Pcap.h"
#include "Pcap.h"
using
namespace
System
;
using
namespace
System
;
...
@@ -28,7 +28,7 @@ System::String^ PacketSampleStatistics::ToString()
...
@@ -28,7 +28,7 @@ System::String^ PacketSampleStatistics::ToString()
PacketSampleStatistics
::
PacketSampleStatistics
(
const
pcap_pkthdr
&
packetHeader
,
const
unsigned
char
*
packetData
)
PacketSampleStatistics
::
PacketSampleStatistics
(
const
pcap_pkthdr
&
packetHeader
,
const
unsigned
char
*
packetData
)
{
{
P
capDotNet
::
Core
::
Timestamp
::
PcapTimestampToDateTime
(
packetHeader
.
ts
,
_timestamp
);
P
acket
Timestamp
::
PcapTimestampToDateTime
(
packetHeader
.
ts
,
_timestamp
);
_acceptedPackets
=
*
reinterpret_cast
<
const
unsigned
long
*>
(
packetData
);
_acceptedPackets
=
*
reinterpret_cast
<
const
unsigned
long
*>
(
packetData
);
_acceptedBytes
=
*
reinterpret_cast
<
const
unsigned
long
*>
(
packetData
+
8
);
_acceptedBytes
=
*
reinterpret_cast
<
const
unsigned
long
*>
(
packetData
+
8
);
...
...
PcapDotNet/src/PcapDotNet.Core/Timestamp.cpp
→
PcapDotNet/src/PcapDotNet.Core/
Packet
Timestamp.cpp
View file @
ce9ee300
#include "Timestamp.h"
#include "
Packet
Timestamp.h"
#include "Pcap.h"
#include "Pcap.h"
using
namespace
System
;
using
namespace
System
;
using
namespace
PcapDotNet
::
Core
;
using
namespace
PcapDotNet
::
Core
;
// static
DateTime
PacketTimestamp
::
MinimumPacketTimestamp
::
get
()
{
return
_minimumPacketTimestamp
;
}
// static
DateTime
PacketTimestamp
::
MaximumPacketTimestamp
::
get
()
{
return
_maximumPacketTimestamp
;
}
// static
// static
void
Timestamp
::
PcapTimestampToDateTime
(
const
timeval
&
pcapTimestamp
,
[
System
::
Runtime
::
InteropServices
::
Out
]
System
::
DateTime
%
dateTime
)
void
PacketTimestamp
::
PcapTimestampToDateTime
(
const
timeval
&
pcapTimestamp
,
[
Runtime
::
InteropServices
::
Out
]
DateTime
%
dateTime
)
{
{
dateTime
=
DateTime
(
1970
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
::
Utc
);
dateTime
=
DateTime
(
1970
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
::
Utc
);
dateTime
=
dateTime
.
Add
(
TimeSpan
::
FromSeconds
(
pcapTimestamp
.
tv_sec
)
+
TimeSpan
::
FromMilliseconds
(((
double
)
pcapTimestamp
.
tv_usec
)
/
1000
));
dateTime
=
dateTime
.
Add
(
TimeSpan
::
FromSeconds
(
pcapTimestamp
.
tv_sec
)
+
TimeSpan
::
FromMilliseconds
(((
double
)
pcapTimestamp
.
tv_usec
)
/
1000
));
...
@@ -13,10 +25,24 @@ void Timestamp::PcapTimestampToDateTime(const timeval& pcapTimestamp, [System::R
...
@@ -13,10 +25,24 @@ void Timestamp::PcapTimestampToDateTime(const timeval& pcapTimestamp, [System::R
}
}
// static
// static
void
Timestamp
::
DateTimeToPcapTimestamp
(
System
::
DateTime
dateTime
,
timeval
&
pcapTimestamp
)
void
PacketTimestamp
::
DateTimeToPcapTimestamp
(
DateTime
dateTime
,
timeval
&
pcapTimestamp
)
{
{
dateTime
=
dateTime
.
ToUniversalTime
();
dateTime
=
dateTime
.
ToUniversalTime
();
TimeSpan
timespan
=
dateTime
-
DateTime
(
1970
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
::
Utc
);
TimeSpan
timespan
=
dateTime
-
DateTime
(
1970
,
1
,
1
,
0
,
0
,
0
,
DateTimeKind
::
Utc
);
pcapTimestamp
.
tv_sec
=
(
long
)
timespan
.
TotalSeconds
;
pcapTimestamp
.
tv_sec
=
(
long
)
timespan
.
TotalSeconds
;
pcapTimestamp
.
tv_usec
=
(
long
)(
timespan
.
Milliseconds
*
1000
);
pcapTimestamp
.
tv_usec
=
(
long
)(
timespan
.
Milliseconds
*
1000
);
}
// static
void
PacketTimestamp
::
Initialize
()
{
// Min
timeval
pcapTimestamp
;
pcapTimestamp
.
tv_sec
=
Int32
::
MinValue
;
pcapTimestamp
.
tv_usec
=
Int32
::
MinValue
;
PacketTimestamp
::
PcapTimestampToDateTime
(
pcapTimestamp
,
_minimumPacketTimestamp
);
pcapTimestamp
.
tv_sec
=
Int32
::
MaxValue
;
pcapTimestamp
.
tv_usec
=
Int32
::
MaxValue
;
PacketTimestamp
::
PcapTimestampToDateTime
(
pcapTimestamp
,
_maximumPacketTimestamp
);
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core/Timestamp.h
→
PcapDotNet/src/PcapDotNet.Core/
Packet
Timestamp.h
View file @
ce9ee300
...
@@ -4,13 +4,35 @@
...
@@ -4,13 +4,35 @@
namespace
PcapDotNet
{
namespace
Core
namespace
PcapDotNet
{
namespace
Core
{
{
p
rivate
ref
class
Timestamp
p
ublic
ref
class
PacketTimestamp
sealed
{
{
public
:
public
:
/// <summary>
/// The minimum legal timestamp to put in a packet.
/// </summary>
static
property
System
::
DateTime
MinimumPacketTimestamp
{
System
::
DateTime
get
();
}
/// <summary>
/// The maximum legal timestamp to put in a packet.
/// </summary>
static
property
System
::
DateTime
MaximumPacketTimestamp
{
System
::
DateTime
get
();
}
internal
:
static
void
PcapTimestampToDateTime
(
const
timeval
&
pcapTimestamp
,
[
System
::
Runtime
::
InteropServices
::
Out
]
System
::
DateTime
%
dateTime
);
static
void
PcapTimestampToDateTime
(
const
timeval
&
pcapTimestamp
,
[
System
::
Runtime
::
InteropServices
::
Out
]
System
::
DateTime
%
dateTime
);
static
void
DateTimeToPcapTimestamp
(
System
::
DateTime
dateTime
,
timeval
&
pcapTimestamp
);
static
void
DateTimeToPcapTimestamp
(
System
::
DateTime
dateTime
,
timeval
&
pcapTimestamp
);
private
:
private
:
Timestamp
(){}
static
PacketTimestamp
()
{
Initialize
();
}
PacketTimestamp
(){}
static
void
Initialize
();
static
System
::
DateTime
_minimumPacketTimestamp
;
static
System
::
DateTime
_maximumPacketTimestamp
;
};
};
}}
}}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core/WinPCapDotNet.Core.vcproj
View file @
ce9ee300
...
@@ -372,11 +372,11 @@
...
@@ -372,11 +372,11 @@
>
>
</File>
</File>
<File
<File
RelativePath=
".\Timestamp.cpp"
RelativePath=
".\
Packet
Timestamp.cpp"
>
>
</File>
</File>
<File
<File
RelativePath=
".\Timestamp.h"
RelativePath=
".\
Packet
Timestamp.h"
>
>
</File>
</File>
</Filter>
</Filter>
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment