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
be9615bd
Commit
be9615bd
authored
Jul 31, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IpV4
parent
13e7b291
Show whitespace changes
Inline
Side-by-side
Showing
38 changed files
with
1622 additions
and
472 deletions
+1622
-472
IpV4Tests.cs
PcapDotNet/src/Packets.Test/IpV4Tests.cs
+18
-11
Packets.Test.csproj
PcapDotNet/src/Packets.Test/Packets.Test.csproj
+8
-0
IpV4Datagram.cs
PcapDotNet/src/Packets/IpV4/IpV4Datagram.cs
+3
-433
IpV4Option.cs
PcapDotNet/src/Packets/IpV4/IpV4Option.cs
+89
-0
IpV4OptionEndOfOptionsList.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionEndOfOptionsList.cs
+22
-0
IpV4OptionLooseSourceRouting.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionLooseSourceRouting.cs
+19
-0
IpV4OptionNoOperation.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionNoOperation.cs
+22
-0
IpV4OptionRecordRoute.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionRecordRoute.cs
+19
-0
IpV4OptionRoute.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionRoute.cs
+87
-0
IpV4OptionSecurity.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionSecurity.cs
+97
-0
IpV4OptionSecurityLevel.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionSecurityLevel.cs
+14
-0
IpV4OptionStreamIdentifier.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionStreamIdentifier.cs
+64
-0
IpV4OptionStrictSourceRouting.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionStrictSourceRouting.cs
+19
-0
IpV4OptionTimestamp.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionTimestamp.cs
+123
-0
IpV4OptionTimestampAndAddress.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionTimestampAndAddress.cs
+51
-0
IpV4OptionTimestampOnly.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionTimestampOnly.cs
+41
-0
IpV4OptionTimestampType.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionTimestampType.cs
+12
-0
IpV4OptionType.cs
PcapDotNet/src/Packets/IpV4/IpV4OptionType.cs
+14
-0
IpV4Options.cs
PcapDotNet/src/Packets/IpV4/IpV4Options.cs
+93
-0
MoreByteArray.cs
PcapDotNet/src/Packets/MoreByteArray.cs
+78
-0
Packets.csproj
PcapDotNet/src/Packets/Packets.csproj
+22
-0
PcapDotNet.Base.csproj
PcapDotNet/src/PcapDotNet.Base/PcapDotNet.Base.csproj
+73
-0
PcapDotNet.Base.csproj.vspscc
PcapDotNet/src/PcapDotNet.Base/PcapDotNet.Base.csproj.vspscc
+10
-0
AssemblyInfo.cs
PcapDotNet/src/PcapDotNet.Base/Properties/AssemblyInfo.cs
+36
-0
UInt24.cs
PcapDotNet/src/PcapDotNet.Base/UInt24.cs
+37
-0
DumpPacketsTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/DumpPacketsTests.cs
+32
-24
LivePacketDeviceTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
+1
-1
MoreAssert.cs
PcapDotNet/src/PcapDotNet.Core.Test/MoreAssert.cs
+7
-2
PcapDotNet.Core.Test.csproj
...tNet/src/PcapDotNet.Core.Test/PcapDotNet.Core.Test.csproj
+8
-0
MoreRandomPackets.cs
...Net/src/PcapDotNet.Packets.TestUtils/MoreRandomPackets.cs
+135
-0
PcapDotNet.Packets.TestUtils.csproj
...Net.Packets.TestUtils/PcapDotNet.Packets.TestUtils.csproj
+77
-0
PcapDotNet.Packets.TestUtils.csproj.vspscc
...kets.TestUtils/PcapDotNet.Packets.TestUtils.csproj.vspscc
+10
-0
AssemblyInfo.cs
...c/PcapDotNet.Packets.TestUtils/Properties/AssemblyInfo.cs
+36
-0
MoreRandom.cs
PcapDotNet/src/PcapDotNet.TestUtils/MoreRandom.cs
+84
-0
PcapDotNet.TestUtils.csproj
...tNet/src/PcapDotNet.TestUtils/PcapDotNet.TestUtils.csproj
+69
-0
PcapDotNet.TestUtils.csproj.vspscc
...c/PcapDotNet.TestUtils/PcapDotNet.TestUtils.csproj.vspscc
+10
-0
AssemblyInfo.cs
...otNet/src/PcapDotNet.TestUtils/Properties/AssemblyInfo.cs
+36
-0
PcapDotNet.sln
PcapDotNet/src/PcapDotNet.sln
+46
-1
No files found.
PcapDotNet/src/Packets.Test/IpV4Tests.cs
View file @
be9615bd
using
System
;
using
System
;
using
System.Collections.Generic
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Packets.TestUtils
;
using
PcapDotNet.TestUtils
;
namespace
Packets.Test
namespace
Packets.Test
{
{
...
@@ -98,18 +101,18 @@ namespace Packets.Test
...
@@ -98,18 +101,18 @@ namespace Packets.Test
Random
random
=
new
Random
();
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
!=
100
;
++
i
)
for
(
int
i
=
0
;
i
!=
100
0
;
++
i
)
{
{
byte
ipV4TypeOfService
=
(
byte
)
random
.
Next
(
256
);
byte
ipV4TypeOfService
=
random
.
NextByte
(
);
ushort
ipV4Identification
=
(
ushort
)
random
.
Next
(
65536
);
ushort
ipV4Identification
=
random
.
NextUShort
(
);
byte
ipV4Ttl
=
(
byte
)
random
.
Next
(
256
);
byte
ipV4Ttl
=
random
.
NextByte
(
);
IpV4FragmentationFlags
ipV4FragmentationFlags
=
(
IpV4FragmentationFlags
)(
random
.
Next
(
4
)
<<
13
);
IpV4FragmentationFlags
ipV4FragmentationFlags
=
random
.
NextEnum
<
IpV4FragmentationFlags
>(
);
ushort
ipV4FragmentationOffset
=
(
ushort
)
random
.
Next
(
65536
);
ushort
ipV4FragmentationOffset
=
random
.
NextUShort
(
);
IpV4Fragmentation
ipV4Fragmentation
=
new
IpV4Fragmentation
(
ipV4FragmentationFlags
,
ipV4FragmentationOffset
);
IpV4Fragmentation
ipV4Fragmentation
=
new
IpV4Fragmentation
(
ipV4FragmentationFlags
,
ipV4FragmentationOffset
);
const
IpV4Protocol
ipV4Protocol
=
IpV4Protocol
.
Tcp
;
IpV4Protocol
ipV4Protocol
=
random
.
NextEnum
<
IpV4Protocol
>()
;
IpV4Address
ipV4Source
=
new
IpV4Address
(
(
uint
)
random
.
Nex
t
());
IpV4Address
ipV4Source
=
new
IpV4Address
(
random
.
NextUIn
t
());
IpV4Address
ipV4Destination
=
new
IpV4Address
(
(
uint
)
random
.
Nex
t
());
IpV4Address
ipV4Destination
=
new
IpV4Address
(
random
.
NextUIn
t
());
IpV4Options
ipV4Options
=
IpV4Options
.
None
;
IpV4Options
ipV4Options
=
random
.
NextIpV4Options
()
;
byte
[]
ipV4PayloadBuffer
=
new
byte
[
random
.
Next
(
0
,
50
*
1024
)];
byte
[]
ipV4PayloadBuffer
=
new
byte
[
random
.
Next
(
0
,
50
*
1024
)];
random
.
NextBytes
(
ipV4PayloadBuffer
);
random
.
NextBytes
(
ipV4PayloadBuffer
);
...
@@ -134,6 +137,7 @@ namespace Packets.Test
...
@@ -134,6 +137,7 @@ namespace Packets.Test
Assert
.
AreEqual
(
IpV4Datagram
.
HeaderMinimumLength
+
ipV4Options
.
Length
,
packet
.
Ethernet
.
IpV4
.
HeaderLength
,
"IP HeaderLength"
);
Assert
.
AreEqual
(
IpV4Datagram
.
HeaderMinimumLength
+
ipV4Options
.
Length
,
packet
.
Ethernet
.
IpV4
.
HeaderLength
,
"IP HeaderLength"
);
Assert
.
AreEqual
(
ipV4TypeOfService
,
packet
.
Ethernet
.
IpV4
.
TypeOfService
,
"IP TypeOfService"
);
Assert
.
AreEqual
(
ipV4TypeOfService
,
packet
.
Ethernet
.
IpV4
.
TypeOfService
,
"IP TypeOfService"
);
Assert
.
AreEqual
(
packet
.
Length
-
EthernetDatagram
.
HeaderLength
,
packet
.
Ethernet
.
IpV4
.
TotalLength
,
"IP TotalLength"
);
Assert
.
AreEqual
(
packet
.
Length
-
EthernetDatagram
.
HeaderLength
,
packet
.
Ethernet
.
IpV4
.
TotalLength
,
"IP TotalLength"
);
Assert
.
AreEqual
(
ipV4Identification
,
packet
.
Ethernet
.
IpV4
.
Identification
,
"IP Identification"
);
Assert
.
AreEqual
(
ipV4Fragmentation
,
packet
.
Ethernet
.
IpV4
.
Fragmentation
,
"IP Fragmentation"
);
Assert
.
AreEqual
(
ipV4Fragmentation
,
packet
.
Ethernet
.
IpV4
.
Fragmentation
,
"IP Fragmentation"
);
Assert
.
AreEqual
(
ipV4Fragmentation
.
Flags
,
packet
.
Ethernet
.
IpV4
.
Fragmentation
.
Flags
,
"IP Fragmentation"
);
Assert
.
AreEqual
(
ipV4Fragmentation
.
Flags
,
packet
.
Ethernet
.
IpV4
.
Fragmentation
.
Flags
,
"IP Fragmentation"
);
Assert
.
AreEqual
(
ipV4Fragmentation
.
Offset
,
packet
.
Ethernet
.
IpV4
.
Fragmentation
.
Offset
,
"IP Fragmentation"
);
Assert
.
AreEqual
(
ipV4Fragmentation
.
Offset
,
packet
.
Ethernet
.
IpV4
.
Fragmentation
.
Offset
,
"IP Fragmentation"
);
...
@@ -143,7 +147,10 @@ namespace Packets.Test
...
@@ -143,7 +147,10 @@ namespace Packets.Test
Assert
.
AreEqual
(
true
,
packet
.
Ethernet
.
IpV4
.
IsHeaderChecksumCorrect
,
"IP HeaderChecksumCorrect"
);
Assert
.
AreEqual
(
true
,
packet
.
Ethernet
.
IpV4
.
IsHeaderChecksumCorrect
,
"IP HeaderChecksumCorrect"
);
Assert
.
AreEqual
(
ipV4Source
,
packet
.
Ethernet
.
IpV4
.
Source
,
"IP Source"
);
Assert
.
AreEqual
(
ipV4Source
,
packet
.
Ethernet
.
IpV4
.
Source
,
"IP Source"
);
Assert
.
AreEqual
(
ipV4Destination
,
packet
.
Ethernet
.
IpV4
.
Destination
,
"IP Destination"
);
Assert
.
AreEqual
(
ipV4Destination
,
packet
.
Ethernet
.
IpV4
.
Destination
,
"IP Destination"
);
if
(!
ipV4Options
.
Equals
(
packet
.
Ethernet
.
IpV4
.
Options
))
{
Assert
.
AreEqual
(
ipV4Options
,
packet
.
Ethernet
.
IpV4
.
Options
,
"IP Options"
);
Assert
.
AreEqual
(
ipV4Options
,
packet
.
Ethernet
.
IpV4
.
Options
,
"IP Options"
);
}
Assert
.
AreEqual
(
ipV4Payload
,
packet
.
Ethernet
.
IpV4
.
Payload
,
"IP Payload"
);
Assert
.
AreEqual
(
ipV4Payload
,
packet
.
Ethernet
.
IpV4
.
Payload
,
"IP Payload"
);
}
}
...
...
PcapDotNet/src/Packets.Test/Packets.Test.csproj
View file @
be9615bd
...
@@ -52,6 +52,14 @@
...
@@ -52,6 +52,14 @@
<Project>{8A184AF5-E46C-482C-81A3-76D8CE290104}</Project>
<Project>{8A184AF5-E46C-482C-81A3-76D8CE290104}</Project>
<Name>Packets</Name>
<Name>Packets</Name>
</ProjectReference>
</ProjectReference>
<ProjectReference Include="..\PcapDotNet.Packets.TestUtils\PcapDotNet.Packets.TestUtils.csproj">
<Project>{194D3B9A-AD99-44ED-991A-73C4A7EE550F}</Project>
<Name>PcapDotNet.Packets.TestUtils</Name>
</ProjectReference>
<ProjectReference Include="..\PcapDotNet.TestUtils\PcapDotNet.TestUtils.csproj">
<Project>{540F21A8-CD9F-4288-ADCA-DB17027FF309}</Project>
<Name>PcapDotNet.TestUtils</Name>
</ProjectReference>
</ItemGroup>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
...
...
PcapDotNet/src/Packets/IpV4/IpV4Datagram.cs
View file @
be9615bd
using
System
;
using
System.Collections
;
using
System.Collections
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Linq
;
using
System.Text
;
using
System.Text
;
...
@@ -26,6 +24,7 @@ namespace Packets
...
@@ -26,6 +24,7 @@ namespace Packets
public
class
IpV4Datagram
:
Datagram
public
class
IpV4Datagram
:
Datagram
{
{
public
const
int
HeaderMinimumLength
=
20
;
public
const
int
HeaderMinimumLength
=
20
;
public
const
int
HeaderMaximumLength
=
60
;
private
static
class
Offset
private
static
class
Offset
{
{
...
@@ -148,7 +147,7 @@ namespace Packets
...
@@ -148,7 +147,7 @@ namespace Packets
buffer
.
Write
(
offset
+
Offset
.
Source
,
source
.
ToValue
(),
Endianity
.
Big
);
buffer
.
Write
(
offset
+
Offset
.
Source
,
source
.
ToValue
(),
Endianity
.
Big
);
buffer
.
Write
(
offset
+
Offset
.
Destination
,
destination
.
ToValue
(),
Endianity
.
Big
);
buffer
.
Write
(
offset
+
Offset
.
Destination
,
destination
.
ToValue
(),
Endianity
.
Big
);
// options.Write(
offset + Offset.Options);
options
.
Write
(
buffer
,
offset
+
Offset
.
Options
);
buffer
.
Write
(
offset
+
Offset
.
HeaderChecksum
,
Sum16BitsToChecksum
(
Sum16Bits
(
buffer
,
offset
,
headerLength
)),
Endianity
.
Big
);
buffer
.
Write
(
offset
+
Offset
.
HeaderChecksum
,
Sum16BitsToChecksum
(
Sum16Bits
(
buffer
,
offset
,
headerLength
)),
Endianity
.
Big
);
}
}
...
@@ -183,433 +182,4 @@ namespace Packets
...
@@ -183,433 +182,4 @@ namespace Packets
private
bool
?
_isHeaderChecksumCorrect
;
private
bool
?
_isHeaderChecksumCorrect
;
private
Datagram
_tcp
;
private
Datagram
_tcp
;
}
}
public
class
IpV4Options
:
IEquatable
<
IpV4Options
>
{
public
static
IpV4Options
None
{
get
{
return
_none
;
}
}
internal
IpV4Options
()
{
}
internal
IpV4Options
(
byte
[]
buffer
,
int
offset
,
int
length
)
{
_length
=
length
;
int
offsetEnd
=
offset
+
length
;
while
(
offset
!=
offsetEnd
)
{
IpV4Option
option
=
IpV4Option
.
Read
(
buffer
,
ref
offset
,
offsetEnd
-
offset
);
if
(
option
==
null
)
return
;
// Invalid
if
(
option
.
IsAppearsAtMostOnce
)
{
foreach
(
IpV4Option
previousOption
in
_options
)
{
if
(
option
.
GetType
()
==
previousOption
.
GetType
())
return
;
// Invalid
}
}
_options
.
Add
(
option
);
if
(
option
is
IpV4OptionEndOfOptionsList
)
break
;
// Valid?
}
}
public
int
Length
{
get
{
return
_length
;
}
}
public
bool
Equals
(
IpV4Options
other
)
{
if
(
other
==
null
)
return
false
;
if
(
Length
!=
other
.
Length
)
return
false
;
return
_options
.
EqualCollection
(
other
.
_options
);
}
public
override
bool
Equals
(
object
obj
)
{
return
Equals
(
obj
as
IpV4Options
);
}
private
List
<
IpV4Option
>
_options
=
new
List
<
IpV4Option
>();
private
int
_length
;
private
static
IpV4Options
_none
=
new
IpV4Options
();
}
public
static
class
MoreIEnumerable
{
public
static
bool
EqualCollection
<
T
>(
this
IEnumerable
<
T
>
collection1
,
IEnumerable
<
T
>
collection2
)
{
IEnumerator
<
T
>
enumerator1
=
collection1
.
GetEnumerator
();
IEnumerator
<
T
>
enumerator2
=
collection1
.
GetEnumerator
();
while
(
enumerator1
.
MoveNext
())
{
if
(!
enumerator2
.
MoveNext
())
return
false
;
if
(!
enumerator1
.
Current
.
Equals
(
enumerator2
.
Current
))
return
false
;
}
if
(
enumerator2
.
MoveNext
())
return
false
;
return
true
;
}
}
public
enum
IpV4OptionType
:
byte
{
EndOfOptionList
=
0
,
NoOperation
=
1
,
Security
=
130
,
LooseSourceRouting
=
131
,
StrictSourceRouting
=
137
,
RecordRoute
=
7
,
StreamIdentifier
=
136
,
InternetTimestamp
=
68
}
public
abstract
class
IpV4Option
{
public
abstract
bool
IsAppearsAtMostOnce
{
get
;
}
protected
IpV4Option
(
IpV4OptionType
type
)
{
_type
=
type
;
}
internal
static
IpV4Option
Read
(
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
int
offsetEnd
=
offset
+
length
;
if
(
offset
==
offsetEnd
)
return
null
;
IpV4OptionType
optionType
=
(
IpV4OptionType
)
buffer
[
offset
++];
switch
(
optionType
)
{
case
IpV4OptionType
.
EndOfOptionList
:
return
new
IpV4OptionEndOfOptionsList
(
optionType
);
case
IpV4OptionType
.
NoOperation
:
return
new
IpV4OptionNoOperation
(
optionType
);
case
IpV4OptionType
.
Security
:
return
IpV4OptionSecurity
.
Read
(
optionType
,
buffer
,
ref
offset
,
offsetEnd
-
offset
);
case
IpV4OptionType
.
LooseSourceRouting
:
return
IpV4OptionLooseSourceRouting
.
Read
(
optionType
,
buffer
,
ref
offset
,
offsetEnd
-
offset
);
case
IpV4OptionType
.
StrictSourceRouting
:
return
IpV4OptionStrictSourceRouting
.
Read
(
optionType
,
buffer
,
ref
offset
,
offsetEnd
-
offset
);
case
IpV4OptionType
.
RecordRoute
:
return
IpV4OptionRecordRoute
.
Read
(
optionType
,
buffer
,
ref
offset
,
offsetEnd
-
offset
);
case
IpV4OptionType
.
StreamIdentifier
:
return
IpV4OptionStreamIdentifier
.
Read
(
optionType
,
buffer
,
ref
offset
,
offsetEnd
-
offset
);
case
IpV4OptionType
.
InternetTimestamp
:
return
IpV4OptionInternetTimestamp
.
Read
(
optionType
,
buffer
,
ref
offset
,
offsetEnd
-
offset
);
default
:
return
null
;
}
}
private
IpV4OptionType
_type
;
}
[
Flags
]
public
enum
IpV4OptionInternetTimestampType
:
byte
{
TimestampOnly
=
0
,
AddressAndTimestamp
=
1
,
AddressPrespecified
=
3
}
public
class
IpV4OptionInternetTimestamp
:
IpV4Option
{
private
IpV4OptionInternetTimestamp
(
IpV4OptionType
optionType
,
IpV4OptionInternetTimestampType
timestampType
,
byte
overflow
,
KeyValuePair
<
IpV4Address
,
DateTime
>[]
values
,
int
pointedIndex
)
:
base
(
optionType
)
{
_timestampType
=
timestampType
;
_overflow
=
overflow
;
_values
=
values
;
_pointedIndex
=
pointedIndex
;
}
public
override
bool
IsAppearsAtMostOnce
{
get
{
return
true
;
}
}
internal
static
IpV4OptionInternetTimestamp
Read
(
IpV4OptionType
optionType
,
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
if
(
length
<
3
)
return
null
;
byte
optionLength
=
buffer
[
offset
++];
if
(
optionLength
>
length
+
1
||
optionLength
%
4
!=
0
)
return
null
;
byte
pointer
=
buffer
[
offset
++];
if
(
pointer
%
4
!=
1
)
return
null
;
int
pointedIndex
=
pointer
/
4
-
1
;
if
(
pointedIndex
<
0
)
return
null
;
byte
overflow
=
buffer
[
offset
++];
IpV4OptionInternetTimestampType
type
=
(
IpV4OptionInternetTimestampType
)(
overflow
&
0x0F
);
overflow
>>=
4
;
int
numValues
=
optionLength
/
4
-
1
;
if
(
type
!=
IpV4OptionInternetTimestampType
.
TimestampOnly
)
numValues
=
numValues
/
2
-
numValues
%
2
;
KeyValuePair
<
IpV4Address
,
DateTime
>[]
values
=
new
KeyValuePair
<
IpV4Address
,
DateTime
>[
numValues
];
for
(
int
i
=
0
;
i
<
numValues
;
++
i
)
{
switch
(
type
)
{
case
IpV4OptionInternetTimestampType
.
TimestampOnly
:
values
[
i
]
=
new
KeyValuePair
<
IpV4Address
,
DateTime
>(
IpV4Address
.
Zero
,
ReadTimeOfDay
(
buffer
,
ref
offset
));
break
;
case
IpV4OptionInternetTimestampType
.
AddressAndTimestamp
:
case
IpV4OptionInternetTimestampType
.
AddressPrespecified
:
IpV4Address
address
=
new
IpV4Address
(
buffer
.
ReadUInt
(
ref
offset
,
Endianity
.
Big
));
values
[
i
]
=
new
KeyValuePair
<
IpV4Address
,
DateTime
>(
address
,
ReadTimeOfDay
(
buffer
,
ref
offset
));
break
;
}
}
return
new
IpV4OptionInternetTimestamp
(
optionType
,
type
,
overflow
,
values
,
pointedIndex
);
}
private
static
DateTime
ReadTimeOfDay
(
byte
[]
buffer
,
ref
int
offset
)
{
return
DateTime
.
MinValue
.
Date
.
AddMilliseconds
(
buffer
.
ReadUInt
(
ref
offset
,
Endianity
.
Big
));
}
private
IpV4OptionInternetTimestampType
_timestampType
;
private
byte
_overflow
;
private
KeyValuePair
<
IpV4Address
,
DateTime
>[]
_values
;
private
int
_pointedIndex
;
}
public
class
IpV4OptionStreamIdentifier
:
IpV4Option
{
public
override
bool
IsAppearsAtMostOnce
{
get
{
return
true
;
}
}
internal
static
IpV4OptionStreamIdentifier
Read
(
IpV4OptionType
optionType
,
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
if
(
length
<
3
)
return
null
;
byte
optionLength
=
buffer
[
offset
++];
if
(
optionLength
!=
4
)
return
null
;
ushort
identifier
=
buffer
.
ReadUShort
(
ref
offset
,
Endianity
.
Big
);
return
new
IpV4OptionStreamIdentifier
(
optionType
,
identifier
);
}
private
IpV4OptionStreamIdentifier
(
IpV4OptionType
optionType
,
ushort
identifier
)
:
base
(
optionType
)
{
_identifier
=
identifier
;
}
private
ushort
_identifier
;
}
public
class
IpV4OptionRecordRoute
:
IpV4OptionRoute
{
internal
static
IpV4OptionRecordRoute
Read
(
IpV4OptionType
optionType
,
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
IpV4Address
[]
addresses
;
int
pointedAddressIndex
;
if
(!
TryRead
(
out
addresses
,
out
pointedAddressIndex
,
buffer
,
ref
offset
,
length
,
true
))
return
null
;
return
new
IpV4OptionRecordRoute
(
optionType
,
addresses
,
pointedAddressIndex
);
}
private
IpV4OptionRecordRoute
(
IpV4OptionType
optionType
,
IpV4Address
[]
addresses
,
int
pointedAddressIndex
)
:
base
(
optionType
,
addresses
,
pointedAddressIndex
)
{
}
}
public
abstract
class
IpV4OptionRoute
:
IpV4Option
{
public
override
bool
IsAppearsAtMostOnce
{
get
{
return
true
;
}
}
protected
static
bool
TryRead
(
out
IpV4Address
[]
addresses
,
out
int
pointedAddressIndex
,
byte
[]
buffer
,
ref
int
offset
,
int
length
,
bool
readUpToPointer
)
{
addresses
=
null
;
pointedAddressIndex
=
0
;
if
(
length
<
2
)
return
false
;
byte
optionLength
=
buffer
[
offset
++];
if
(
optionLength
>
length
+
1
||
optionLength
%
4
!=
3
)
return
false
;
byte
pointer
=
buffer
[
offset
++];
if
(
pointer
%
4
!=
0
)
return
false
;
pointedAddressIndex
=
pointer
/
4
-
1
;
if
(
pointedAddressIndex
<
0
)
return
false
;
int
numAddresses
=
readUpToPointer
?
pointedAddressIndex
:
(
optionLength
-
3
)
/
4
;
addresses
=
new
IpV4Address
[
numAddresses
];
for
(
int
i
=
0
;
i
!=
numAddresses
;
++
i
)
addresses
[
i
]
=
new
IpV4Address
(
buffer
.
ReadUInt
(
ref
offset
,
Endianity
.
Big
));
return
true
;
}
protected
IpV4OptionRoute
(
IpV4OptionType
optionType
,
IpV4Address
[]
addresses
,
int
pointedAddressIndex
)
:
base
(
optionType
)
{
_addresses
=
addresses
;
_pointedAddressIndex
=
pointedAddressIndex
;
}
private
IpV4Address
[]
_addresses
;
private
int
_pointedAddressIndex
;
}
public
class
IpV4OptionStrictSourceRouting
:
IpV4OptionRoute
{
internal
static
IpV4OptionStrictSourceRouting
Read
(
IpV4OptionType
optionType
,
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
IpV4Address
[]
addresses
;
int
pointedAddressIndex
;
if
(!
TryRead
(
out
addresses
,
out
pointedAddressIndex
,
buffer
,
ref
offset
,
length
,
false
))
return
null
;
return
new
IpV4OptionStrictSourceRouting
(
optionType
,
addresses
,
pointedAddressIndex
);
}
private
IpV4OptionStrictSourceRouting
(
IpV4OptionType
optionType
,
IpV4Address
[]
addresses
,
int
pointedAddressIndex
)
:
base
(
optionType
,
addresses
,
pointedAddressIndex
)
{
}
}
public
class
IpV4OptionLooseSourceRouting
:
IpV4OptionRoute
{
internal
static
IpV4OptionLooseSourceRouting
Read
(
IpV4OptionType
optionType
,
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
IpV4Address
[]
addresses
;
int
pointedAddressIndex
;
if
(!
TryRead
(
out
addresses
,
out
pointedAddressIndex
,
buffer
,
ref
offset
,
length
,
false
))
return
null
;
return
new
IpV4OptionLooseSourceRouting
(
optionType
,
addresses
,
pointedAddressIndex
);
}
private
IpV4OptionLooseSourceRouting
(
IpV4OptionType
optionType
,
IpV4Address
[]
addresses
,
int
pointedAddressIndex
)
:
base
(
optionType
,
addresses
,
pointedAddressIndex
)
{
}
}
public
enum
IpV4OptionSecurityLevel
:
ushort
{
Unclassified
=
0x0000
,
Confidential
=
0xF135
,
EFTO
=
0x789A
,
MMMM
=
0xBC4D
,
PROG
=
0x5E26
,
Restricted
=
0xAF13
,
Secret
=
0xD788
,
TopSecret
=
0x6BC5
}
public
class
IpV4OptionSecurity
:
IpV4Option
{
public
override
bool
IsAppearsAtMostOnce
{
get
{
return
true
;
}
}
internal
static
IpV4OptionSecurity
Read
(
IpV4OptionType
optionType
,
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
if
(
length
<
10
)
return
null
;
byte
optionLength
=
buffer
[
offset
++];
if
(
optionLength
!=
11
)
return
null
;
IpV4OptionSecurityLevel
level
=
(
IpV4OptionSecurityLevel
)
buffer
.
ReadUShort
(
ref
offset
,
Endianity
.
Big
);
ushort
compartments
=
buffer
.
ReadUShort
(
ref
offset
,
Endianity
.
Big
);
ushort
handlingRestrictions
=
buffer
.
ReadUShort
(
ref
offset
,
Endianity
.
Big
);
uint
transmissionControlCode
=
(
uint
)((
buffer
.
ReadUShort
(
ref
offset
,
Endianity
.
Big
)
<<
8
)
+
buffer
[
offset
++]);
return
new
IpV4OptionSecurity
(
optionType
,
level
,
compartments
,
handlingRestrictions
,
transmissionControlCode
);
}
private
IpV4OptionSecurity
(
IpV4OptionType
optionType
,
IpV4OptionSecurityLevel
level
,
ushort
compartments
,
ushort
handlingRestrictions
,
uint
transmissionControlCode
)
:
base
(
optionType
)
{
_level
=
level
;
_compartments
=
compartments
;
_handlingRestrictions
=
handlingRestrictions
;
_transmissionControlCode
=
transmissionControlCode
;
}
private
IpV4OptionSecurityLevel
_level
;
private
ushort
_compartments
;
private
ushort
_handlingRestrictions
;
private
uint
_transmissionControlCode
;
// this could actually be 24 bits
}
public
class
IpV4OptionNoOperation
:
IpV4Option
{
public
override
bool
IsAppearsAtMostOnce
{
get
{
return
false
;
}
}
internal
IpV4OptionNoOperation
(
IpV4OptionType
type
)
:
base
(
type
)
{
}
}
public
class
IpV4OptionEndOfOptionsList
:
IpV4Option
{
public
override
bool
IsAppearsAtMostOnce
{
get
{
return
false
;
}
}
internal
IpV4OptionEndOfOptionsList
(
IpV4OptionType
type
)
:
base
(
type
)
{
}
}
}
}
PcapDotNet/src/Packets/IpV4/IpV4Option.cs
0 → 100644
View file @
be9615bd
using
System
;
namespace
Packets
{
public
abstract
class
IpV4Option
:
IEquatable
<
IpV4Option
>
{
public
IpV4OptionType
OptionType
{
get
{
return
_type
;
}
}
public
abstract
int
Length
{
get
;
}
public
abstract
bool
IsAppearsAtMostOnce
{
get
;
}
public
bool
Equivalent
(
IpV4Option
option
)
{
return
OptionType
==
option
.
OptionType
;
}
public
virtual
bool
Equals
(
IpV4Option
other
)
{
if
(
other
==
null
)
return
false
;
return
Equivalent
(
other
);
}
public
override
bool
Equals
(
object
obj
)
{
return
Equals
(
obj
as
IpV4Option
);
}
protected
IpV4Option
(
IpV4OptionType
type
)
{
_type
=
type
;
}
internal
static
IpV4Option
Read
(
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
int
offsetEnd
=
offset
+
length
;
if
(
offset
==
offsetEnd
)
return
null
;
IpV4OptionType
optionType
=
(
IpV4OptionType
)
buffer
[
offset
++];
switch
(
optionType
)
{
case
IpV4OptionType
.
EndOfOptionList
:
return
new
IpV4OptionEndOfOptionsList
();
case
IpV4OptionType
.
NoOperation
:
return
new
IpV4OptionNoOperation
();
case
IpV4OptionType
.
Security
:
return
IpV4OptionSecurity
.
ReadOptionSecurity
(
buffer
,
ref
offset
,
offsetEnd
-
offset
);
case
IpV4OptionType
.
LooseSourceRouting
:
return
IpV4OptionLooseSourceRouting
.
ReadOptionLooseSourceRouting
(
buffer
,
ref
offset
,
offsetEnd
-
offset
);
case
IpV4OptionType
.
StrictSourceRouting
:
return
IpV4OptionStrictSourceRouting
.
ReadOptionStrictSourceRouting
(
buffer
,
ref
offset
,
offsetEnd
-
offset
);
case
IpV4OptionType
.
RecordRoute
:
return
IpV4OptionRecordRoute
.
ReadOptionRecordRoute
(
buffer
,
ref
offset
,
offsetEnd
-
offset
);
case
IpV4OptionType
.
StreamIdentifier
:
return
IpV4OptionStreamIdentifier
.
ReadOptionStreamIdentifier
(
buffer
,
ref
offset
,
offsetEnd
-
offset
);
case
IpV4OptionType
.
InternetTimestamp
:
return
IpV4OptionTimestamp
.
ReadOptionTimestamp
(
buffer
,
ref
offset
,
offsetEnd
-
offset
);
default
:
return
null
;
}
}
internal
virtual
void
Write
(
byte
[]
buffer
,
ref
int
offset
)
{
buffer
[
offset
++]
=
(
byte
)
OptionType
;
}
private
readonly
IpV4OptionType
_type
;
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionEndOfOptionsList.cs
0 → 100644
View file @
be9615bd
namespace
Packets
{
public
class
IpV4OptionEndOfOptionsList
:
IpV4Option
{
public
const
int
OptionLength
=
1
;
public
IpV4OptionEndOfOptionsList
()
:
base
(
IpV4OptionType
.
EndOfOptionList
)
{
}
public
override
int
Length
{
get
{
return
OptionLength
;
}
}
public
override
bool
IsAppearsAtMostOnce
{
get
{
return
false
;
}
}
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionLooseSourceRouting.cs
0 → 100644
View file @
be9615bd
namespace
Packets
{
public
class
IpV4OptionLooseSourceRouting
:
IpV4OptionRoute
{
public
IpV4OptionLooseSourceRouting
(
IpV4Address
[]
addresses
,
byte
pointedAddressIndex
)
:
base
(
IpV4OptionType
.
LooseSourceRouting
,
addresses
,
pointedAddressIndex
)
{
}
internal
static
IpV4OptionLooseSourceRouting
ReadOptionLooseSourceRouting
(
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
IpV4Address
[]
addresses
;
byte
pointedAddressIndex
;
if
(!
TryRead
(
out
addresses
,
out
pointedAddressIndex
,
buffer
,
ref
offset
,
length
))
return
null
;
return
new
IpV4OptionLooseSourceRouting
(
addresses
,
pointedAddressIndex
);
}
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionNoOperation.cs
0 → 100644
View file @
be9615bd
namespace
Packets
{
public
class
IpV4OptionNoOperation
:
IpV4Option
{
public
const
int
OptionLength
=
1
;
public
IpV4OptionNoOperation
()
:
base
(
IpV4OptionType
.
NoOperation
)
{
}
public
override
int
Length
{
get
{
return
OptionLength
;
}
}
public
override
bool
IsAppearsAtMostOnce
{
get
{
return
false
;
}
}
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionRecordRoute.cs
0 → 100644
View file @
be9615bd
namespace
Packets
{
public
class
IpV4OptionRecordRoute
:
IpV4OptionRoute
{
public
IpV4OptionRecordRoute
(
IpV4Address
[]
addresses
,
byte
pointedAddressIndex
)
:
base
(
IpV4OptionType
.
RecordRoute
,
addresses
,
pointedAddressIndex
)
{
}
internal
static
IpV4OptionRecordRoute
ReadOptionRecordRoute
(
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
IpV4Address
[]
addresses
;
byte
pointedAddressIndex
;
if
(!
TryRead
(
out
addresses
,
out
pointedAddressIndex
,
buffer
,
ref
offset
,
length
))
return
null
;
return
new
IpV4OptionRecordRoute
(
addresses
,
pointedAddressIndex
);
}
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionRoute.cs
0 → 100644
View file @
be9615bd
using
System
;
using
System.Linq
;
namespace
Packets
{
public
abstract
class
IpV4OptionRoute
:
IpV4Option
,
IEquatable
<
IpV4OptionRoute
>
{
public
const
int
OptionMinimumLength
=
3
;
public
const
byte
PointedAddressIndexMaxValue
=
byte
.
MaxValue
/
4
-
1
;
public
byte
PointedAddressIndex
{
get
{
return
_pointedAddressIndex
;
}
}
public
override
int
Length
{
get
{
return
OptionMinimumLength
+
4
*
_addresses
.
Length
;
}
}
public
override
bool
IsAppearsAtMostOnce
{
get
{
return
true
;
}
}
public
bool
Equals
(
IpV4OptionRoute
other
)
{
if
(
other
==
null
)
return
false
;
return
Equivalent
(
other
)
&&
PointedAddressIndex
==
other
.
PointedAddressIndex
&&
_addresses
.
SequenceEqual
(
other
.
_addresses
);
}
public
override
bool
Equals
(
IpV4Option
other
)
{
return
Equals
(
other
as
IpV4OptionRoute
);
}
internal
override
void
Write
(
byte
[]
buffer
,
ref
int
offset
)
{
base
.
Write
(
buffer
,
ref
offset
);
buffer
[
offset
++]
=
(
byte
)
Length
;
buffer
[
offset
++]
=
(
byte
)(
OptionMinimumLength
+
1
+
PointedAddressIndex
*
4
);
for
(
int
i
=
0
;
i
!=
_addresses
.
Length
;
++
i
)
buffer
.
Write
(
ref
offset
,
_addresses
[
i
].
ToValue
(),
Endianity
.
Big
);
}
protected
static
bool
TryRead
(
out
IpV4Address
[]
addresses
,
out
byte
pointedAddressIndex
,
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
addresses
=
null
;
pointedAddressIndex
=
0
;
if
(
length
<
OptionMinimumLength
-
1
)
return
false
;
byte
optionLength
=
buffer
[
offset
++];
if
(
optionLength
<
OptionMinimumLength
||
optionLength
>
length
+
1
||
optionLength
%
4
!=
3
)
return
false
;
byte
pointer
=
buffer
[
offset
++];
if
(
pointer
%
4
!=
0
||
pointer
<
4
)
return
false
;
pointedAddressIndex
=
(
byte
)(
pointer
/
4
-
1
);
int
numAddresses
=
(
optionLength
-
3
)
/
4
;
addresses
=
new
IpV4Address
[
numAddresses
];
for
(
int
i
=
0
;
i
!=
numAddresses
;
++
i
)
addresses
[
i
]
=
new
IpV4Address
(
buffer
.
ReadUInt
(
ref
offset
,
Endianity
.
Big
));
return
true
;
}
protected
IpV4OptionRoute
(
IpV4OptionType
optionType
,
IpV4Address
[]
addresses
,
byte
pointedAddressIndex
)
:
base
(
optionType
)
{
_addresses
=
addresses
;
_pointedAddressIndex
=
pointedAddressIndex
;
}
private
readonly
IpV4Address
[]
_addresses
;
private
readonly
byte
_pointedAddressIndex
;
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionSecurity.cs
0 → 100644
View file @
be9615bd
using
System
;
using
PcapDotNet.Base
;
namespace
Packets
{
public
class
IpV4OptionSecurity
:
IpV4Option
,
IEquatable
<
IpV4OptionSecurity
>
{
public
const
int
OptionLength
=
11
;
public
IpV4OptionSecurity
(
IpV4OptionSecurityLevel
level
,
ushort
compartments
,
ushort
handlingRestrictions
,
UInt24
transmissionControlCode
)
:
base
(
IpV4OptionType
.
Security
)
{
_level
=
level
;
_compartments
=
compartments
;
_handlingRestrictions
=
handlingRestrictions
;
_transmissionControlCode
=
transmissionControlCode
;
}
public
IpV4OptionSecurityLevel
Level
{
get
{
return
_level
;
}
}
public
ushort
Compartments
{
get
{
return
_compartments
;
}
}
public
ushort
HandlingRestrictions
{
get
{
return
_handlingRestrictions
;
}
}
public
UInt24
TransmissionControlCode
{
get
{
return
_transmissionControlCode
;
}
}
public
override
int
Length
{
get
{
return
OptionLength
;
}
}
public
override
bool
IsAppearsAtMostOnce
{
get
{
return
true
;
}
}
public
bool
Equals
(
IpV4OptionSecurity
other
)
{
if
(
other
==
null
)
return
false
;
return
Level
==
other
.
Level
&&
Compartments
==
other
.
Compartments
&&
HandlingRestrictions
==
other
.
HandlingRestrictions
&&
TransmissionControlCode
==
other
.
TransmissionControlCode
;
}
public
override
bool
Equals
(
IpV4Option
other
)
{
return
Equals
(
other
as
IpV4OptionSecurity
);
}
internal
static
IpV4OptionSecurity
ReadOptionSecurity
(
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
if
(
length
<
OptionLength
-
1
)
return
null
;
byte
optionLength
=
buffer
[
offset
++];
if
(
optionLength
!=
OptionLength
)
return
null
;
IpV4OptionSecurityLevel
level
=
(
IpV4OptionSecurityLevel
)
buffer
.
ReadUShort
(
ref
offset
,
Endianity
.
Big
);
ushort
compartments
=
buffer
.
ReadUShort
(
ref
offset
,
Endianity
.
Big
);
ushort
handlingRestrictions
=
buffer
.
ReadUShort
(
ref
offset
,
Endianity
.
Big
);
UInt24
transmissionControlCode
=
buffer
.
ReadUInt24
(
ref
offset
,
Endianity
.
Big
);
return
new
IpV4OptionSecurity
(
level
,
compartments
,
handlingRestrictions
,
transmissionControlCode
);
}
internal
override
void
Write
(
byte
[]
buffer
,
ref
int
offset
)
{
base
.
Write
(
buffer
,
ref
offset
);
buffer
[
offset
++]
=
(
byte
)
Length
;
buffer
.
Write
(
ref
offset
,
(
ushort
)
Level
,
Endianity
.
Big
);
buffer
.
Write
(
ref
offset
,
Compartments
,
Endianity
.
Big
);
buffer
.
Write
(
ref
offset
,
HandlingRestrictions
,
Endianity
.
Big
);
buffer
.
Write
(
ref
offset
,
TransmissionControlCode
,
Endianity
.
Big
);
}
private
readonly
IpV4OptionSecurityLevel
_level
;
private
readonly
ushort
_compartments
;
private
readonly
ushort
_handlingRestrictions
;
private
readonly
UInt24
_transmissionControlCode
;
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionSecurityLevel.cs
0 → 100644
View file @
be9615bd
namespace
Packets
{
public
enum
IpV4OptionSecurityLevel
:
ushort
{
Unclassified
=
0x0000
,
Confidential
=
0xF135
,
EFTO
=
0x789A
,
MMMM
=
0xBC4D
,
PROG
=
0x5E26
,
Restricted
=
0xAF13
,
Secret
=
0xD788
,
TopSecret
=
0x6BC5
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionStreamIdentifier.cs
0 → 100644
View file @
be9615bd
using
System
;
namespace
Packets
{
public
class
IpV4OptionStreamIdentifier
:
IpV4Option
,
IEquatable
<
IpV4OptionStreamIdentifier
>
{
public
const
int
OptionLength
=
4
;
public
IpV4OptionStreamIdentifier
(
ushort
identifier
)
:
base
(
IpV4OptionType
.
StreamIdentifier
)
{
_identifier
=
identifier
;
}
public
ushort
Identifier
{
get
{
return
_identifier
;
}
}
public
override
int
Length
{
get
{
return
OptionLength
;
}
}
public
override
bool
IsAppearsAtMostOnce
{
get
{
return
true
;
}
}
public
bool
Equals
(
IpV4OptionStreamIdentifier
other
)
{
if
(
other
==
null
)
return
false
;
return
Identifier
==
other
.
Identifier
;
}
public
override
bool
Equals
(
IpV4Option
other
)
{
return
Equals
(
other
as
IpV4OptionStreamIdentifier
);
}
internal
static
IpV4OptionStreamIdentifier
ReadOptionStreamIdentifier
(
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
if
(
length
<
OptionLength
-
1
)
return
null
;
byte
optionLength
=
buffer
[
offset
++];
if
(
optionLength
!=
OptionLength
)
return
null
;
ushort
identifier
=
buffer
.
ReadUShort
(
ref
offset
,
Endianity
.
Big
);
return
new
IpV4OptionStreamIdentifier
(
identifier
);
}
internal
override
void
Write
(
byte
[]
buffer
,
ref
int
offset
)
{
base
.
Write
(
buffer
,
ref
offset
);
buffer
[
offset
++]
=
(
byte
)
Length
;
buffer
.
Write
(
ref
offset
,
Identifier
,
Endianity
.
Big
);
}
private
readonly
ushort
_identifier
;
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionStrictSourceRouting.cs
0 → 100644
View file @
be9615bd
namespace
Packets
{
public
class
IpV4OptionStrictSourceRouting
:
IpV4OptionRoute
{
public
IpV4OptionStrictSourceRouting
(
IpV4Address
[]
addresses
,
byte
pointedAddressIndex
)
:
base
(
IpV4OptionType
.
StrictSourceRouting
,
addresses
,
pointedAddressIndex
)
{
}
internal
static
IpV4OptionStrictSourceRouting
ReadOptionStrictSourceRouting
(
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
IpV4Address
[]
addresses
;
byte
pointedAddressIndex
;
if
(!
TryRead
(
out
addresses
,
out
pointedAddressIndex
,
buffer
,
ref
offset
,
length
))
return
null
;
return
new
IpV4OptionStrictSourceRouting
(
addresses
,
pointedAddressIndex
);
}
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionTimestamp.cs
0 → 100644
View file @
be9615bd
using
System
;
namespace
Packets
{
public
abstract
class
IpV4OptionTimestamp
:
IpV4Option
,
IEquatable
<
IpV4OptionTimestamp
>
{
public
const
int
OptionMinimumLength
=
4
;
public
const
int
PointedIndexMaxValue
=
byte
.
MaxValue
/
4
-
1
;
public
IpV4OptionTimestampType
TimestampType
{
get
{
return
_timestampType
;
}
}
public
byte
Overflow
{
get
{
return
_overflow
;
}
}
public
byte
PointedIndex
{
get
{
return
_pointedIndex
;
}
}
public
override
int
Length
{
get
{
return
OptionMinimumLength
+
ValuesLength
;
}
}
public
override
bool
IsAppearsAtMostOnce
{
get
{
return
true
;
}
}
public
bool
Equals
(
IpV4OptionTimestamp
other
)
{
if
(
other
==
null
)
return
false
;
return
TimestampType
==
other
.
TimestampType
&&
Overflow
==
other
.
Overflow
&&
PointedIndex
==
other
.
PointedIndex
&&
EqualValues
(
other
);
}
public
override
bool
Equals
(
IpV4Option
other
)
{
return
Equals
(
other
as
IpV4OptionTimestamp
);
}
internal
static
IpV4OptionTimestamp
ReadOptionTimestamp
(
byte
[]
buffer
,
ref
int
offset
,
int
length
)
{
if
(
length
<
OptionMinimumLength
-
1
)
return
null
;
byte
optionLength
=
buffer
[
offset
++];
if
(
optionLength
<
OptionMinimumLength
||
optionLength
>
length
+
1
||
optionLength
%
4
!=
0
)
return
null
;
byte
pointer
=
buffer
[
offset
++];
if
(
pointer
%
4
!=
1
||
pointer
<
5
)
return
null
;
byte
pointedIndex
=
(
byte
)(
pointer
/
4
-
1
);
byte
overflow
=
buffer
[
offset
++];
IpV4OptionTimestampType
timestampType
=
(
IpV4OptionTimestampType
)(
overflow
&
0x0F
);
overflow
>>=
4
;
int
numValues
=
optionLength
/
4
-
1
;
switch
(
timestampType
)
{
case
IpV4OptionTimestampType
.
TimestampOnly
:
return
IpV4OptionTimestampOnly
.
Read
(
overflow
,
pointedIndex
,
buffer
,
ref
offset
,
numValues
);
case
IpV4OptionTimestampType
.
AddressAndTimestamp
:
case
IpV4OptionTimestampType
.
AddressPrespecified
:
return
IpV4OptionTimestampAndAddress
.
Read
(
timestampType
,
overflow
,
pointedIndex
,
buffer
,
ref
offset
,
numValues
);
default
:
return
null
;
}
}
internal
override
void
Write
(
byte
[]
buffer
,
ref
int
offset
)
{
base
.
Write
(
buffer
,
ref
offset
);
buffer
[
offset
++]
=
(
byte
)
Length
;
buffer
[
offset
++]
=
(
byte
)(
OptionMinimumLength
+
1
+
PointedIndex
*
4
);
buffer
[
offset
++]
=
(
byte
)(((
byte
)(
Overflow
<<
4
))
|
(
byte
)
TimestampType
);
WriteValues
(
buffer
,
ref
offset
);
}
protected
IpV4OptionTimestamp
(
IpV4OptionTimestampType
timestampType
,
byte
overflow
,
byte
pointedIndex
)
:
base
(
IpV4OptionType
.
InternetTimestamp
)
{
_timestampType
=
timestampType
;
_overflow
=
overflow
;
_pointedIndex
=
pointedIndex
;
}
protected
abstract
int
ValuesLength
{
get
;
}
protected
abstract
bool
EqualValues
(
IpV4OptionTimestamp
other
);
protected
abstract
void
WriteValues
(
byte
[]
buffer
,
ref
int
offset
);
protected
static
TimeSpan
ReadTimeOfDay
(
byte
[]
buffer
,
ref
int
offset
)
{
return
TimeSpan
.
FromMilliseconds
(
buffer
.
ReadUInt
(
ref
offset
,
Endianity
.
Big
));
}
private
readonly
IpV4OptionTimestampType
_timestampType
;
private
readonly
byte
_overflow
;
private
readonly
byte
_pointedIndex
;
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionTimestampAndAddress.cs
0 → 100644
View file @
be9615bd
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
namespace
Packets
{
public
class
IpV4OptionTimestampAndAddress
:
IpV4OptionTimestamp
{
public
IpV4OptionTimestampAndAddress
(
IpV4OptionTimestampType
timestampType
,
byte
overflow
,
byte
pointedIndex
,
KeyValuePair
<
IpV4Address
,
TimeSpan
>[]
addressesAndTimestamps
)
:
base
(
timestampType
,
overflow
,
pointedIndex
)
{
_addressesAndTimestamps
=
addressesAndTimestamps
;
}
internal
static
IpV4OptionTimestampAndAddress
Read
(
IpV4OptionTimestampType
timestampType
,
byte
overflow
,
byte
pointedIndex
,
byte
[]
buffer
,
ref
int
offset
,
int
numValues
)
{
if
(
numValues
%
2
!=
0
)
return
null
;
KeyValuePair
<
IpV4Address
,
TimeSpan
>[]
addressesAndTimestamps
=
new
KeyValuePair
<
IpV4Address
,
TimeSpan
>[
numValues
/
2
];
for
(
int
i
=
0
;
i
!=
numValues
/
2
;
++
i
)
{
addressesAndTimestamps
[
i
]
=
new
KeyValuePair
<
IpV4Address
,
TimeSpan
>(
new
IpV4Address
(
buffer
.
ReadUInt
(
ref
offset
,
Endianity
.
Big
)),
ReadTimeOfDay
(
buffer
,
ref
offset
));
}
return
new
IpV4OptionTimestampAndAddress
(
timestampType
,
overflow
,
pointedIndex
,
addressesAndTimestamps
);
}
protected
override
int
ValuesLength
{
get
{
return
_addressesAndTimestamps
.
Length
*
2
*
4
;
}
}
protected
override
bool
EqualValues
(
IpV4OptionTimestamp
other
)
{
return
_addressesAndTimestamps
.
SequenceEqual
(((
IpV4OptionTimestampAndAddress
)
other
).
_addressesAndTimestamps
);
}
protected
override
void
WriteValues
(
byte
[]
buffer
,
ref
int
offset
)
{
foreach
(
KeyValuePair
<
IpV4Address
,
TimeSpan
>
addressAndTimestamp
in
_addressesAndTimestamps
)
{
buffer
.
Write
(
ref
offset
,
addressAndTimestamp
.
Key
.
ToValue
(),
Endianity
.
Big
);
buffer
.
Write
(
ref
offset
,
(
uint
)
addressAndTimestamp
.
Value
.
TotalMilliseconds
,
Endianity
.
Big
);
}
}
private
readonly
KeyValuePair
<
IpV4Address
,
TimeSpan
>[]
_addressesAndTimestamps
;
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionTimestampOnly.cs
0 → 100644
View file @
be9615bd
using
System
;
using
System.Linq
;
namespace
Packets
{
public
class
IpV4OptionTimestampOnly
:
IpV4OptionTimestamp
{
public
IpV4OptionTimestampOnly
(
byte
overflow
,
byte
pointedIndex
,
params
TimeSpan
[]
timestamps
)
:
base
(
IpV4OptionTimestampType
.
TimestampOnly
,
overflow
,
pointedIndex
)
{
_timestamps
=
timestamps
;
}
internal
static
IpV4OptionTimestampOnly
Read
(
byte
overflow
,
byte
pointedIndex
,
byte
[]
buffer
,
ref
int
offset
,
int
numValues
)
{
TimeSpan
[]
timestamps
=
new
TimeSpan
[
numValues
];
for
(
int
i
=
0
;
i
!=
numValues
;
++
i
)
timestamps
[
i
]
=
ReadTimeOfDay
(
buffer
,
ref
offset
);
return
new
IpV4OptionTimestampOnly
(
overflow
,
pointedIndex
,
timestamps
);
}
protected
override
int
ValuesLength
{
get
{
return
_timestamps
.
Length
*
4
;
}
}
protected
override
bool
EqualValues
(
IpV4OptionTimestamp
other
)
{
return
_timestamps
.
SequenceEqual
(((
IpV4OptionTimestampOnly
)
other
).
_timestamps
);
}
protected
override
void
WriteValues
(
byte
[]
buffer
,
ref
int
offset
)
{
foreach
(
TimeSpan
timestamp
in
_timestamps
)
buffer
.
Write
(
ref
offset
,
(
uint
)
timestamp
.
TotalMilliseconds
,
Endianity
.
Big
);
}
private
readonly
TimeSpan
[]
_timestamps
;
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionTimestampType.cs
0 → 100644
View file @
be9615bd
using
System
;
namespace
Packets
{
[
Flags
]
public
enum
IpV4OptionTimestampType
:
byte
{
TimestampOnly
=
0
,
AddressAndTimestamp
=
1
,
AddressPrespecified
=
3
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4OptionType.cs
0 → 100644
View file @
be9615bd
namespace
Packets
{
public
enum
IpV4OptionType
:
byte
{
EndOfOptionList
=
0
,
NoOperation
=
1
,
Security
=
130
,
LooseSourceRouting
=
131
,
StrictSourceRouting
=
137
,
RecordRoute
=
7
,
StreamIdentifier
=
136
,
InternetTimestamp
=
68
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4Options.cs
0 → 100644
View file @
be9615bd
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
namespace
Packets
{
public
class
IpV4Options
:
IEquatable
<
IpV4Options
>
{
public
const
int
MaximumLength
=
IpV4Datagram
.
HeaderMaximumLength
-
IpV4Datagram
.
HeaderMinimumLength
;
public
static
IpV4Options
None
{
get
{
return
_none
;
}
}
public
IpV4Options
(
IEnumerable
<
IpV4Option
>
options
)
{
_options
.
AddRange
(
options
);
foreach
(
IpV4Option
option
in
_options
)
_length
+=
option
.
Length
;
if
(
_length
%
4
!=
0
)
_length
=
(
_length
/
4
+
1
)
*
4
;
}
public
IpV4Options
(
params
IpV4Option
[]
options
)
:
this
((
IEnumerable
<
IpV4Option
>)
options
)
{
}
internal
IpV4Options
()
{
}
internal
IpV4Options
(
byte
[]
buffer
,
int
offset
,
int
length
)
{
_length
=
length
;
int
offsetEnd
=
offset
+
length
;
while
(
offset
!=
offsetEnd
)
{
IpV4Option
option
=
IpV4Option
.
Read
(
buffer
,
ref
offset
,
offsetEnd
-
offset
);
if
(
option
==
null
)
return
;
// Invalid
if
(
option
.
IsAppearsAtMostOnce
&&
_options
.
FindIndex
(
option
.
Equivalent
)
!=
-
1
)
{
return
;
// Invalid
}
_options
.
Add
(
option
);
if
(
option
is
IpV4OptionEndOfOptionsList
)
break
;
// Valid?
}
}
public
int
Length
{
get
{
return
_length
;
}
}
public
bool
Equals
(
IpV4Options
other
)
{
if
(
other
==
null
)
return
false
;
if
(
Length
!=
other
.
Length
)
return
false
;
return
_options
.
SequenceEqual
(
other
.
_options
);
}
public
override
bool
Equals
(
object
obj
)
{
return
Equals
(
obj
as
IpV4Options
);
}
internal
void
Write
(
byte
[]
buffer
,
int
offset
)
{
int
offsetEnd
=
offset
+
Length
;
foreach
(
IpV4Option
option
in
_options
)
option
.
Write
(
buffer
,
ref
offset
);
// Padding
while
(
offset
<
offsetEnd
)
buffer
[
offset
++]
=
0
;
}
private
readonly
List
<
IpV4Option
>
_options
=
new
List
<
IpV4Option
>();
private
readonly
int
_length
;
private
static
readonly
IpV4Options
_none
=
new
IpV4Options
();
}
}
\ No newline at end of file
PcapDotNet/src/Packets/MoreByteArray.cs
View file @
be9615bd
using
System
;
using
System
;
using
System.Net
;
using
System.Net
;
using
PcapDotNet.Base
;
namespace
Packets
namespace
Packets
{
{
...
@@ -33,6 +34,21 @@ namespace Packets
...
@@ -33,6 +34,21 @@ namespace Packets
return
result
;
return
result
;
}
}
public
static
UInt24
ReadUInt24
(
this
byte
[]
buffer
,
int
offset
,
Endianity
endianity
)
{
UInt24
value
=
ReadUInt24
(
buffer
,
offset
);
if
(
IsWrongEndianity
(
endianity
))
value
=
HostToNetworkOrder
(
value
);
return
value
;
}
public
static
UInt24
ReadUInt24
(
this
byte
[]
buffer
,
ref
int
offset
,
Endianity
endianity
)
{
UInt24
result
=
ReadUInt24
(
buffer
,
offset
,
endianity
);
offset
+=
3
;
return
result
;
}
[
System
.
Diagnostics
.
CodeAnalysis
.
SuppressMessage
(
"Microsoft.Naming"
,
"CA1720:IdentifiersShouldNotContainTypeNames"
,
MessageId
=
"uint"
)]
[
System
.
Diagnostics
.
CodeAnalysis
.
SuppressMessage
(
"Microsoft.Naming"
,
"CA1720:IdentifiersShouldNotContainTypeNames"
,
MessageId
=
"uint"
)]
public
static
uint
ReadUInt
(
this
byte
[]
buffer
,
int
offset
,
Endianity
endianity
)
public
static
uint
ReadUInt
(
this
byte
[]
buffer
,
int
offset
,
Endianity
endianity
)
{
{
...
@@ -67,6 +83,25 @@ namespace Packets
...
@@ -67,6 +83,25 @@ namespace Packets
Write
(
buffer
,
offset
,
(
short
)
value
,
endianity
);
Write
(
buffer
,
offset
,
(
short
)
value
,
endianity
);
}
}
public
static
void
Write
(
this
byte
[]
buffer
,
ref
int
offset
,
ushort
value
,
Endianity
endianity
)
{
Write
(
buffer
,
offset
,
value
,
endianity
);
offset
+=
2
;
}
public
static
void
Write
(
this
byte
[]
buffer
,
int
offset
,
UInt24
value
,
Endianity
endianity
)
{
if
(
IsWrongEndianity
(
endianity
))
value
=
HostToNetworkOrder
(
value
);
Write
(
buffer
,
offset
,
value
);
}
public
static
void
Write
(
this
byte
[]
buffer
,
ref
int
offset
,
UInt24
value
,
Endianity
endianity
)
{
Write
(
buffer
,
offset
,
value
,
endianity
);
offset
+=
3
;
}
public
static
void
Write
(
this
byte
[]
buffer
,
int
offset
,
int
value
,
Endianity
endianity
)
public
static
void
Write
(
this
byte
[]
buffer
,
int
offset
,
int
value
,
Endianity
endianity
)
{
{
if
(
IsWrongEndianity
(
endianity
))
if
(
IsWrongEndianity
(
endianity
))
...
@@ -79,11 +114,32 @@ namespace Packets
...
@@ -79,11 +114,32 @@ namespace Packets
Write
(
buffer
,
offset
,
(
int
)
value
,
endianity
);
Write
(
buffer
,
offset
,
(
int
)
value
,
endianity
);
}
}
public
static
void
Write
(
this
byte
[]
buffer
,
ref
int
offset
,
uint
value
,
Endianity
endianity
)
{
Write
(
buffer
,
offset
,
value
,
endianity
);
offset
+=
4
;
}
private
static
bool
IsWrongEndianity
(
Endianity
endianity
)
private
static
bool
IsWrongEndianity
(
Endianity
endianity
)
{
{
return
(
BitConverter
.
IsLittleEndian
==
(
endianity
==
Endianity
.
Big
));
return
(
BitConverter
.
IsLittleEndian
==
(
endianity
==
Endianity
.
Big
));
}
}
private
static
UInt24
HostToNetworkOrder
(
UInt24
value
)
{
UInt24
result
=
value
;
unsafe
{
UInt24
*
ptr
=
&
result
;
byte
*
bytePtr
=
(
byte
*)
ptr
;
byte
tmp
=
bytePtr
[
0
];
bytePtr
[
0
]
=
bytePtr
[
2
];
bytePtr
[
2
]
=
tmp
;
}
return
result
;
}
private
static
short
ReadShort
(
byte
[]
buffer
,
int
offset
)
private
static
short
ReadShort
(
byte
[]
buffer
,
int
offset
)
{
{
unsafe
unsafe
...
@@ -95,6 +151,17 @@ namespace Packets
...
@@ -95,6 +151,17 @@ namespace Packets
}
}
}
}
private
static
UInt24
ReadUInt24
(
byte
[]
buffer
,
int
offset
)
{
unsafe
{
fixed
(
byte
*
ptr
=
&
buffer
[
offset
])
{
return
*((
UInt24
*)
ptr
);
}
}
}
private
static
int
ReadInt
(
byte
[]
buffer
,
int
offset
)
private
static
int
ReadInt
(
byte
[]
buffer
,
int
offset
)
{
{
unsafe
unsafe
...
@@ -117,6 +184,17 @@ namespace Packets
...
@@ -117,6 +184,17 @@ namespace Packets
}
}
}
}
private
static
void
Write
(
byte
[]
buffer
,
int
offset
,
UInt24
value
)
{
unsafe
{
fixed
(
byte
*
ptr
=
&
buffer
[
offset
])
{
*((
UInt24
*)
ptr
)
=
value
;
}
}
}
private
static
void
Write
(
byte
[]
buffer
,
int
offset
,
int
value
)
private
static
void
Write
(
byte
[]
buffer
,
int
offset
,
int
value
)
{
{
unsafe
unsafe
...
...
PcapDotNet/src/Packets/Packets.csproj
View file @
be9615bd
...
@@ -69,6 +69,22 @@
...
@@ -69,6 +69,22 @@
<Compile
Include=
"IpV4\IpV4Datagram.cs"
/>
<Compile
Include=
"IpV4\IpV4Datagram.cs"
/>
<Compile
Include=
"IpV4\IpV4Fragmentation.cs"
/>
<Compile
Include=
"IpV4\IpV4Fragmentation.cs"
/>
<Compile
Include=
"IpV4\IpV4FragmentationFlags.cs"
/>
<Compile
Include=
"IpV4\IpV4FragmentationFlags.cs"
/>
<Compile
Include=
"IpV4\IpV4Option.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionEndOfOptionsList.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionLooseSourceRouting.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionNoOperation.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionRecordRoute.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionRoute.cs"
/>
<Compile
Include=
"IpV4\IpV4Options.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionSecurity.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionSecurityLevel.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionStreamIdentifier.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionStrictSourceRouting.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionTimestamp.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionTimestampAndAddress.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionTimestampOnly.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionTimestampType.cs"
/>
<Compile
Include=
"IpV4\IpV4OptionType.cs"
/>
<Compile
Include=
"IpV4\IpV4Protocol.cs"
/>
<Compile
Include=
"IpV4\IpV4Protocol.cs"
/>
<Compile
Include=
"MoreByteArray.cs"
/>
<Compile
Include=
"MoreByteArray.cs"
/>
<Compile
Include=
"Packet.cs"
/>
<Compile
Include=
"Packet.cs"
/>
...
@@ -81,6 +97,12 @@
...
@@ -81,6 +97,12 @@
<ItemGroup>
<ItemGroup>
<CodeAnalysisDictionary
Include=
"CodeAnalysisDictionary.xml"
/>
<CodeAnalysisDictionary
Include=
"CodeAnalysisDictionary.xml"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\PcapDotNet.Base\PcapDotNet.Base.csproj"
>
<Project>
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}
</Project>
<Name>
PcapDotNet.Base
</Name>
</ProjectReference>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
Other similar extension points exist, see Microsoft.Common.targets.
...
...
PcapDotNet/src/PcapDotNet.Base/PcapDotNet.Base.csproj
0 → 100644
View file @
be9615bd
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"3.5"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProductVersion>
9.0.21022
</ProductVersion>
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
PcapDotNet.Base
</RootNamespace>
<AssemblyName>
PcapDotNet.Base
</AssemblyName>
<TargetFrameworkVersion>
v3.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<SccProjectName>
SAK
</SccProjectName>
<SccLocalPath>
SAK
</SccLocalPath>
<SccAuxPath>
SAK
</SccAuxPath>
<SccProvider>
SAK
</SccProvider>
<SignAssembly>
true
</SignAssembly>
<AssemblyOriginatorKeyFile>
..\PcapDotNet.snk
</AssemblyOriginatorKeyFile>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
..\..\bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
..\..\bin\Release\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Xml.Linq"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Data.DataSetExtensions"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"UInt24.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
<None
Include=
"..\PcapDotNet.snk"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
<PropertyGroup>
<PreBuildEvent>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v6.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</PreBuildEvent>
<PostBuildEvent>
cd $(OutDir)
zip Pcap.Net.Binary.zip $(TargetFileName) $(ProjectName).pdb $(ProjectName).xml
</PostBuildEvent>
</PropertyGroup>
</Project>
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Base/PcapDotNet.Base.csproj.vspscc
0 → 100644
View file @
be9615bd
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}
PcapDotNet/src/PcapDotNet.Base/Properties/AssemblyInfo.cs
0 → 100644
View file @
be9615bd
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PcapDotNet.Base")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PcapDotNet.Base")]
[assembly: AssemblyCopyright("Copyright © 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("a21d5d4a-18d9-4d3f-a510-c884200ff622")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
PcapDotNet/src/PcapDotNet.Base/UInt24.cs
0 → 100644
View file @
be9615bd
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
namespace
PcapDotNet.Base
{
public
struct
UInt24
{
public
static
readonly
UInt24
MaxValue
=
(
UInt24
)
0x00FFFFFF
;
private
UInt24
(
int
value
)
{
_mostSignificant
=
(
byte
)((
value
>>
16
)
&
0x00FF
);
_leastSignificant
=
(
ushort
)(
value
&
0x0000FFFF
);
}
public
static
explicit
operator
UInt24
(
int
value
)
{
return
new
UInt24
(
value
);
}
public
static
implicit
operator
int
(
UInt24
value
)
{
return
value
.
ToInt
();
}
private
int
ToInt
()
{
return
_mostSignificant
<<
16
+
_leastSignificant
;
}
private
readonly
byte
_mostSignificant
;
private
readonly
ushort
_leastSignificant
;
}
}
PcapDotNet/src/PcapDotNet.Core.Test/DumpPacketsTests.cs
View file @
be9615bd
using
System
;
using
System
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Packets
;
using
Packets
;
using
PcapDotNet.Packets.TestUtils
;
using
PcapDotNet.TestUtils
;
namespace
PcapDotNet.Core.Test
namespace
PcapDotNet.Core.Test
{
{
...
@@ -66,16 +68,23 @@ namespace PcapDotNet.Core.Test
...
@@ -66,16 +68,23 @@ namespace PcapDotNet.Core.Test
Random
random
=
new
Random
();
Random
random
=
new
Random
();
byte
ipV4TypeOfService
=
(
byte
)
random
.
Next
(
256
);
using
(
PacketCommunicator
communicator
=
LivePacketDeviceTests
.
OpenLiveDevice
())
ushort
ipV4Identification
=
(
ushort
)
random
.
Next
(
65536
);
{
byte
ipV4Ttl
=
(
byte
)
random
.
Next
(
256
);
/*
IpV4FragmentationFlags
ipV4FragmentationFlags
=
(
IpV4FragmentationFlags
)(
random
.
Next
(
4
)
<<
13
);
using (PacketDumpFile dumpFile = communicator.OpenDump(@"c:\wow.pcap"))
ushort
ipV4FragmentationOffset
=
(
ushort
)
random
.
Next
(
65536
);
{
for (int i = 0; i != 1000; ++i)
{
byte ipV4TypeOfService = random.NextByte();
ushort ipV4Identification = random.NextUShort();
byte ipV4Ttl = random.NextByte();
IpV4FragmentationFlags ipV4FragmentationFlags = random.NextEnum<IpV4FragmentationFlags>();
ushort ipV4FragmentationOffset = random.NextUShort();
IpV4Fragmentation ipV4Fragmentation = new IpV4Fragmentation(ipV4FragmentationFlags, ipV4FragmentationOffset);
IpV4Fragmentation ipV4Fragmentation = new IpV4Fragmentation(ipV4FragmentationFlags, ipV4FragmentationOffset);
const
IpV4Protocol
ipV4Protocol
=
IpV4Protocol
.
Tcp
;
IpV4Protocol ipV4Protocol = random.NextEnum<IpV4Protocol>()
;
IpV4Address
ipV4Source
=
new
IpV4Address
((
uint
)
random
.
Nex
t
());
IpV4Address ipV4Source = new IpV4Address(random.NextUIn
t());
IpV4Address
ipV4Destination
=
new
IpV4Address
((
uint
)
random
.
Nex
t
());
IpV4Address ipV4Destination = new IpV4Address(random.NextUIn
t());
IpV4Options
ipV4Options
=
IpV4Options
.
None
;
IpV4Options ipV4Options = random.NextIpV4Options()
;
byte[] ipV4PayloadBuffer = new byte[random.Next(0, 50 * 1024)];
byte[] ipV4PayloadBuffer = new byte[random.Next(0, 50 * 1024)];
random.NextBytes(ipV4PayloadBuffer);
random.NextBytes(ipV4PayloadBuffer);
...
@@ -87,12 +96,11 @@ namespace PcapDotNet.Core.Test
...
@@ -87,12 +96,11 @@ namespace PcapDotNet.Core.Test
ipV4Source, ipV4Destination, ipV4Options,
ipV4Source, ipV4Destination, ipV4Options,
ipV4Payload);
ipV4Payload);
using
(
PacketCommunicator
communicator
=
LivePacketDeviceTests
.
OpenLiveDevice
())
dumpFile.Dump(packet);
{
dumpFile.Flush();
// using (PacketDumpFile dumpFile = communicator.OpenDump(@"c:\wow.pcap"))
}
// {
}
// dumpFile.Dump(packet);
*/
// }
}
}
}
}
}
}
...
...
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
View file @
be9615bd
...
@@ -729,7 +729,7 @@ namespace PcapDotNet.Core.Test
...
@@ -729,7 +729,7 @@ namespace PcapDotNet.Core.Test
Assert
.
AreEqual
(
totalStatistics
.
GetHashCode
(),
totalStatistics
.
GetHashCode
());
Assert
.
AreEqual
(
totalStatistics
.
GetHashCode
(),
totalStatistics
.
GetHashCode
());
Assert
.
IsTrue
(
totalStatistics
.
Equals
(
totalStatistics
));
Assert
.
IsTrue
(
totalStatistics
.
Equals
(
totalStatistics
));
Assert
.
AreNotEqual
(
null
,
totalStatistics
);
Assert
.
AreNotEqual
(
null
,
totalStatistics
);
Assert
.
AreEqual
<
uint
>(
0
,
totalStatistics
.
PacketsCaptured
,
"PacketsCaptured"
);
MoreAssert
.
IsSmallerOrEqual
<
uint
>(
1
,
totalStatistics
.
PacketsCaptured
,
"PacketsCaptured"
);
Assert
.
AreEqual
<
uint
>(
0
,
totalStatistics
.
PacketsDroppedByDriver
,
"PacketsDroppedByDriver"
);
Assert
.
AreEqual
<
uint
>(
0
,
totalStatistics
.
PacketsDroppedByDriver
,
"PacketsDroppedByDriver"
);
Assert
.
AreEqual
<
uint
>(
0
,
totalStatistics
.
PacketsDroppedByInterface
,
"PacketsDroppedByInterface"
);
Assert
.
AreEqual
<
uint
>(
0
,
totalStatistics
.
PacketsDroppedByInterface
,
"PacketsDroppedByInterface"
);
Assert
.
AreEqual
<
uint
>(
0
,
totalStatistics
.
PacketsReceived
,
"PacketsReceived"
);
Assert
.
AreEqual
<
uint
>(
0
,
totalStatistics
.
PacketsReceived
,
"PacketsReceived"
);
...
...
PcapDotNet/src/PcapDotNet.Core.Test/MoreAssert.cs
View file @
be9615bd
...
@@ -27,11 +27,16 @@ namespace PcapDotNet.Core.Test
...
@@ -27,11 +27,16 @@ namespace PcapDotNet.Core.Test
"> Actual: <"
+
actual
+
">."
);
"> Actual: <"
+
actual
+
">."
);
}
}
public
static
void
IsSmallerOrEqual
<
T
>(
T
expectedMaximum
,
T
actual
)
where
T
:
IComparable
<
T
>
public
static
void
IsSmallerOrEqual
<
T
>(
T
expectedMaximum
,
T
actual
,
string
message
)
where
T
:
IComparable
<
T
>
{
{
if
(
expectedMaximum
.
CompareTo
(
actual
)
<
0
)
if
(
expectedMaximum
.
CompareTo
(
actual
)
<
0
)
throw
new
AssertFailedException
(
"Assert.IsSmallerOrEqual failed. Expected maximum: <"
+
expectedMaximum
+
throw
new
AssertFailedException
(
"Assert.IsSmallerOrEqual failed. Expected maximum: <"
+
expectedMaximum
+
"> Actual: <"
+
actual
+
">."
);
"> Actual: <"
+
actual
+
">. "
+
message
);
}
public
static
void
IsSmallerOrEqual
<
T
>(
T
expectedMaximum
,
T
actual
)
where
T
:
IComparable
<
T
>
{
IsSmallerOrEqual
(
expectedMaximum
,
actual
,
string
.
Empty
);
}
}
public
static
void
IsInRange
<
T
>(
T
expectedMinimum
,
T
expectedMaximum
,
T
actual
)
where
T
:
IComparable
<
T
>
public
static
void
IsInRange
<
T
>(
T
expectedMinimum
,
T
expectedMaximum
,
T
actual
)
where
T
:
IComparable
<
T
>
...
...
PcapDotNet/src/PcapDotNet.Core.Test/PcapDotNet.Core.Test.csproj
View file @
be9615bd
...
@@ -63,6 +63,14 @@
...
@@ -63,6 +63,14 @@
<Project>{89C63BE1-AF9A-472E-B256-A4F56B1655A7}</Project>
<Project>{89C63BE1-AF9A-472E-B256-A4F56B1655A7}</Project>
<Name>PcapDotNet.Core</Name>
<Name>PcapDotNet.Core</Name>
</ProjectReference>
</ProjectReference>
<ProjectReference Include="..\PcapDotNet.Packets.TestUtils\PcapDotNet.Packets.TestUtils.csproj">
<Project>{194D3B9A-AD99-44ED-991A-73C4A7EE550F}</Project>
<Name>PcapDotNet.Packets.TestUtils</Name>
</ProjectReference>
<ProjectReference Include="..\PcapDotNet.TestUtils\PcapDotNet.TestUtils.csproj">
<Project>{540F21A8-CD9F-4288-ADCA-DB17027FF309}</Project>
<Name>PcapDotNet.TestUtils</Name>
</ProjectReference>
</ItemGroup>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
...
...
PcapDotNet/src/PcapDotNet.Packets.TestUtils/MoreRandomPackets.cs
0 → 100644
View file @
be9615bd
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
Packets
;
using
PcapDotNet.TestUtils
;
namespace
PcapDotNet.Packets.TestUtils
{
public
static
class
MoreRandomPackets
{
public
static
IpV4Address
NextIpV4Address
(
this
Random
random
)
{
return
new
IpV4Address
(
random
.
NextUInt
());
}
public
static
IpV4Options
NextIpV4Options
(
this
Random
random
)
{
int
optionsLength
=
random
.
Next
(
IpV4Options
.
MaximumLength
)
/
4
*
4
;
List
<
IpV4Option
>
options
=
new
List
<
IpV4Option
>();
while
(
optionsLength
>
0
)
{
IpV4Option
option
=
null
;
IpV4OptionType
optionType
=
random
.
NextEnum
<
IpV4OptionType
>();
switch
(
optionType
)
{
case
IpV4OptionType
.
EndOfOptionList
:
option
=
new
IpV4OptionEndOfOptionsList
();
break
;
case
IpV4OptionType
.
NoOperation
:
option
=
new
IpV4OptionNoOperation
();
break
;
case
IpV4OptionType
.
Security
:
if
(
optionsLength
<
IpV4OptionSecurity
.
OptionLength
)
break
;
option
=
new
IpV4OptionSecurity
(
random
.
NextEnum
<
IpV4OptionSecurityLevel
>(),
random
.
NextUShort
(),
random
.
NextUShort
(),
random
.
NextUInt24
());
break
;
case
IpV4OptionType
.
LooseSourceRouting
:
case
IpV4OptionType
.
StrictSourceRouting
:
case
IpV4OptionType
.
RecordRoute
:
if
(
optionsLength
<
IpV4OptionRoute
.
OptionMinimumLength
)
break
;
int
numAddresses
=
random
.
Next
((
optionsLength
-
IpV4OptionRoute
.
OptionMinimumLength
)
/
4
+
1
);
IpV4Address
[]
addresses
=
new
IpV4Address
[
numAddresses
];
for
(
int
addressIndex
=
0
;
addressIndex
!=
numAddresses
;
++
addressIndex
)
addresses
[
addressIndex
]
=
random
.
NextIpV4Address
();
byte
pointedAddressIndex
;
if
(
random
.
NextBool
())
pointedAddressIndex
=
random
.
NextByte
(
IpV4OptionRoute
.
PointedAddressIndexMaxValue
+
1
);
else
pointedAddressIndex
=
random
.
NextByte
(
10
);
switch
(
optionType
)
{
case
IpV4OptionType
.
LooseSourceRouting
:
option
=
new
IpV4OptionLooseSourceRouting
(
addresses
,
pointedAddressIndex
);
break
;
case
IpV4OptionType
.
StrictSourceRouting
:
option
=
new
IpV4OptionStrictSourceRouting
(
addresses
,
pointedAddressIndex
);
break
;
case
IpV4OptionType
.
RecordRoute
:
option
=
new
IpV4OptionRecordRoute
(
addresses
,
pointedAddressIndex
);
break
;
}
break
;
case
IpV4OptionType
.
StreamIdentifier
:
if
(
optionsLength
<
IpV4OptionStreamIdentifier
.
OptionLength
)
break
;
option
=
new
IpV4OptionStreamIdentifier
(
random
.
NextUShort
());
break
;
case
IpV4OptionType
.
InternetTimestamp
:
if
(
optionsLength
<
IpV4OptionTimestamp
.
OptionMinimumLength
)
break
;
IpV4OptionTimestampType
timestampType
=
random
.
NextEnum
<
IpV4OptionTimestampType
>();
byte
overflow
=
random
.
NextByte
(
16
);
byte
pointedIndex
;
if
(
random
.
NextBool
())
pointedIndex
=
random
.
NextByte
(
IpV4OptionTimestamp
.
PointedIndexMaxValue
+
1
);
else
pointedIndex
=
random
.
NextByte
(
10
);
switch
(
timestampType
)
{
case
IpV4OptionTimestampType
.
TimestampOnly
:
int
numTimestamps
=
random
.
Next
((
optionsLength
-
IpV4OptionTimestamp
.
OptionMinimumLength
)
/
4
+
1
);
TimeSpan
[]
timestamps
=
new
TimeSpan
[
numTimestamps
];
for
(
int
i
=
0
;
i
!=
numTimestamps
;
++
i
)
timestamps
[
i
]
=
TimeSpan
.
FromMilliseconds
((
uint
)
random
.
NextDateTime
().
TimeOfDay
.
TotalMilliseconds
);
option
=
new
IpV4OptionTimestampOnly
(
overflow
,
pointedIndex
,
timestamps
);
break
;
case
IpV4OptionTimestampType
.
AddressAndTimestamp
:
int
numPairs
=
random
.
Next
((
optionsLength
-
IpV4OptionTimestamp
.
OptionMinimumLength
)
/
8
+
1
);
KeyValuePair
<
IpV4Address
,
TimeSpan
>[]
pairs
=
new
KeyValuePair
<
IpV4Address
,
TimeSpan
>[
numPairs
];
for
(
int
i
=
0
;
i
!=
numPairs
;
++
i
)
pairs
[
i
]
=
new
KeyValuePair
<
IpV4Address
,
TimeSpan
>(
random
.
NextIpV4Address
(),
TimeSpan
.
FromMilliseconds
((
uint
)
random
.
NextDateTime
().
TimeOfDay
.
TotalMilliseconds
));
option
=
new
IpV4OptionTimestampAndAddress
(
timestampType
,
overflow
,
pointedIndex
,
pairs
);
break
;
}
break
;
}
if
(
option
==
null
)
continue
;
if
(
option
.
IsAppearsAtMostOnce
&&
options
.
FindIndex
(
option
.
Equivalent
)
!=
-
1
)
{
continue
;
}
options
.
Add
(
option
);
optionsLength
-=
option
.
Length
;
if
(
option
is
IpV4OptionEndOfOptionsList
)
break
;
}
return
new
IpV4Options
(
options
);
}
}
}
PcapDotNet/src/PcapDotNet.Packets.TestUtils/PcapDotNet.Packets.TestUtils.csproj
0 → 100644
View file @
be9615bd
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"3.5"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProductVersion>
9.0.21022
</ProductVersion>
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{194D3B9A-AD99-44ED-991A-73C4A7EE550F}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
PcapDotNet.Packets.TestUtils
</RootNamespace>
<AssemblyName>
PcapDotNet.Packets.TestUtils
</AssemblyName>
<TargetFrameworkVersion>
v3.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<SccProjectName>
SAK
</SccProjectName>
<SccLocalPath>
SAK
</SccLocalPath>
<SccAuxPath>
SAK
</SccAuxPath>
<SccProvider>
SAK
</SccProvider>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Xml.Linq"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Data.DataSetExtensions"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"MoreRandomPackets.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\Packets\Packets.csproj"
>
<Project>
{8A184AF5-E46C-482C-81A3-76D8CE290104}
</Project>
<Name>
Packets
</Name>
</ProjectReference>
<ProjectReference
Include=
"..\PcapDotNet.Base\PcapDotNet.Base.csproj"
>
<Project>
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}
</Project>
<Name>
PcapDotNet.Base
</Name>
</ProjectReference>
<ProjectReference
Include=
"..\PcapDotNet.TestUtils\PcapDotNet.TestUtils.csproj"
>
<Project>
{540F21A8-CD9F-4288-ADCA-DB17027FF309}
</Project>
<Name>
PcapDotNet.TestUtils
</Name>
</ProjectReference>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.TestUtils/PcapDotNet.Packets.TestUtils.csproj.vspscc
0 → 100644
View file @
be9615bd
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}
PcapDotNet/src/PcapDotNet.Packets.TestUtils/Properties/AssemblyInfo.cs
0 → 100644
View file @
be9615bd
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PcapDotNet.Packets.TestUtils")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PcapDotNet.Packets.TestUtils")]
[assembly: AssemblyCopyright("Copyright © 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5a394088-4dca-4d47-9d88-f46c7e9e3550")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
PcapDotNet/src/PcapDotNet.TestUtils/MoreRandom.cs
0 → 100644
View file @
be9615bd
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
PcapDotNet.Base
;
namespace
PcapDotNet.TestUtils
{
public
static
class
MoreRandom
{
public
static
bool
NextBool
(
this
Random
random
)
{
return
random
.
Next
()
%
2
==
0
;
}
public
static
byte
NextByte
(
this
Random
random
,
int
maxValue
)
{
return
(
byte
)
random
.
Next
(
maxValue
);
}
public
static
byte
NextByte
(
this
Random
random
)
{
return
random
.
NextByte
(
byte
.
MaxValue
+
1
);
}
public
static
ushort
NextUShort
(
this
Random
random
)
{
return
(
ushort
)
random
.
Next
(
ushort
.
MaxValue
+
1
);
}
public
static
UInt24
NextUInt24
(
this
Random
random
)
{
return
(
UInt24
)
random
.
Next
(
UInt24
.
MaxValue
+
1
);
}
public
static
uint
NextUInt
(
this
Random
random
)
{
return
(
uint
)
random
.
Next
();
}
public
static
long
NextLong
(
this
Random
random
,
long
minValue
,
long
maxValue
)
{
return
minValue
+
(
long
)
random
.
NextULong
((
ulong
)(
maxValue
-
minValue
));
}
public
static
long
NextLong
(
this
Random
random
)
{
return
(
long
)
random
.
NextULong
();
}
public
static
ulong
NextULong
(
this
Random
random
,
ulong
maxValue
)
{
return
random
.
NextULong
()
%
maxValue
;
}
public
static
ulong
NextULong
(
this
Random
random
)
{
return
((((
ulong
)
random
.
NextUInt
())
<<
32
)
+
random
.
NextUInt
());
}
public
static
DateTime
NextDateTime
(
this
Random
random
)
{
return
new
DateTime
(
random
.
NextLong
(
DateTime
.
MinValue
.
Ticks
,
DateTime
.
MaxValue
.
Ticks
+
1
));
}
public
static
T
NextEnum
<
T
>(
this
Random
random
)
{
Type
type
=
typeof
(
T
);
if
(!
type
.
IsEnum
)
throw
new
ArgumentException
(
"T must be an Enum"
);
Array
enumValues
=
Enum
.
GetValues
(
type
);
if
(
enumValues
.
Length
==
0
)
throw
new
ArgumentException
(
"T is an enum with no values"
,
"T"
);
return
(
T
)
random
.
NextValue
(
enumValues
);
}
public
static
object
NextValue
(
this
Random
random
,
Array
values
)
{
return
values
.
GetValue
(
random
.
Next
(
values
.
Length
));
}
}
}
PcapDotNet/src/PcapDotNet.TestUtils/PcapDotNet.TestUtils.csproj
0 → 100644
View file @
be9615bd
<?xml version="1.0" encoding="utf-8"?>
<Project
ToolsVersion=
"3.5"
DefaultTargets=
"Build"
xmlns=
"http://schemas.microsoft.com/developer/msbuild/2003"
>
<PropertyGroup>
<Configuration
Condition=
" '$(Configuration)' == '' "
>
Debug
</Configuration>
<Platform
Condition=
" '$(Platform)' == '' "
>
AnyCPU
</Platform>
<ProductVersion>
9.0.21022
</ProductVersion>
<SchemaVersion>
2.0
</SchemaVersion>
<ProjectGuid>
{540F21A8-CD9F-4288-ADCA-DB17027FF309}
</ProjectGuid>
<OutputType>
Library
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
PcapDotNet.TestUtils
</RootNamespace>
<AssemblyName>
PcapDotNet.TestUtils
</AssemblyName>
<TargetFrameworkVersion>
v3.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<SccProjectName>
SAK
</SccProjectName>
<SccLocalPath>
SAK
</SccLocalPath>
<SccAuxPath>
SAK
</SccAuxPath>
<SccProvider>
SAK
</SccProvider>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' "
>
<DebugSymbols>
true
</DebugSymbols>
<DebugType>
full
</DebugType>
<Optimize>
false
</Optimize>
<OutputPath>
bin\Debug\
</OutputPath>
<DefineConstants>
DEBUG;TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<PropertyGroup
Condition=
" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "
>
<DebugType>
pdbonly
</DebugType>
<Optimize>
true
</Optimize>
<OutputPath>
bin\Release\
</OutputPath>
<DefineConstants>
TRACE
</DefineConstants>
<ErrorReport>
prompt
</ErrorReport>
<WarningLevel>
4
</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Xml.Linq"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Data.DataSetExtensions"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"MoreRandom.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<ItemGroup>
<ProjectReference
Include=
"..\PcapDotNet.Base\PcapDotNet.Base.csproj"
>
<Project>
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}
</Project>
<Name>
PcapDotNet.Base
</Name>
</ProjectReference>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
PcapDotNet/src/PcapDotNet.TestUtils/PcapDotNet.TestUtils.csproj.vspscc
0 → 100644
View file @
be9615bd
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}
PcapDotNet/src/PcapDotNet.TestUtils/Properties/AssemblyInfo.cs
0 → 100644
View file @
be9615bd
using
System.Reflection
;
using
System.Runtime.CompilerServices
;
using
System.Runtime.InteropServices
;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("PcapDotNet.TestUtils")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("PcapDotNet.TestUtils")]
[assembly: AssemblyCopyright("Copyright © 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("6c5bc970-d9fa-4866-989f-3b4be5754df4")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
PcapDotNet/src/PcapDotNet.sln
View file @
be9615bd
...
@@ -17,9 +17,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Packets", "Packets\Packets.
...
@@ -17,9 +17,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Packets", "Packets\Packets.
EndProject
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Packets.Test", "Packets.Test\Packets.Test.csproj", "{6C7326EB-F230-4934-B74B-F99F87204E44}"
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Packets.Test", "Packets.Test\Packets.Test.csproj", "{6C7326EB-F230-4934-B74B-F99F87204E44}"
EndProject
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PcapDotNet.TestUtils", "PcapDotNet.TestUtils\PcapDotNet.TestUtils.csproj", "{540F21A8-CD9F-4288-ADCA-DB17027FF309}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PcapDotNet.Packets.TestUtils", "PcapDotNet.Packets.TestUtils\PcapDotNet.Packets.TestUtils.csproj", "{194D3B9A-AD99-44ED-991A-73C4A7EE550F}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "PcapDotNet.Base", "PcapDotNet.Base\PcapDotNet.Base.csproj", "{83E805C9-4D29-4E34-A27E-5A78690FBD2B}"
EndProject
Global
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects =
6
SccNumberOfProjects =
9
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://tfs06.codeplex.com/
SccTeamFoundationServer = https://tfs06.codeplex.com/
SccLocalPath0 = .
SccLocalPath0 = .
...
@@ -38,6 +44,15 @@ Global
...
@@ -38,6 +44,15 @@ Global
SccProjectUniqueName5 = Packets.Test\\Packets.Test.csproj
SccProjectUniqueName5 = Packets.Test\\Packets.Test.csproj
SccProjectName5 = Packets.Test
SccProjectName5 = Packets.Test
SccLocalPath5 = Packets.Test
SccLocalPath5 = Packets.Test
SccProjectUniqueName6 = PcapDotNet.TestUtils\\PcapDotNet.TestUtils.csproj
SccProjectName6 = PcapDotNet.TestUtils
SccLocalPath6 = PcapDotNet.TestUtils
SccProjectUniqueName7 = PcapDotNet.Packets.TestUtils\\PcapDotNet.Packets.TestUtils.csproj
SccProjectName7 = PcapDotNet.Packets.TestUtils
SccLocalPath7 = PcapDotNet.Packets.TestUtils
SccProjectUniqueName8 = PcapDotNet.Base\\PcapDotNet.Base.csproj
SccProjectName8 = PcapDotNet.Base
SccLocalPath8 = PcapDotNet.Base
EndGlobalSection
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = PcapDotNet.vsmdi
CategoryFile = PcapDotNet.vsmdi
...
@@ -103,6 +118,36 @@ Global
...
@@ -103,6 +118,36 @@ Global
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Win32.ActiveCfg = Release|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Win32.ActiveCfg = Release|Any CPU
{540F21A8-CD9F-4288-ADCA-DB17027FF309}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{540F21A8-CD9F-4288-ADCA-DB17027FF309}.Debug|Any CPU.Build.0 = Debug|Any CPU
{540F21A8-CD9F-4288-ADCA-DB17027FF309}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{540F21A8-CD9F-4288-ADCA-DB17027FF309}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{540F21A8-CD9F-4288-ADCA-DB17027FF309}.Debug|Win32.ActiveCfg = Debug|Any CPU
{540F21A8-CD9F-4288-ADCA-DB17027FF309}.Release|Any CPU.ActiveCfg = Release|Any CPU
{540F21A8-CD9F-4288-ADCA-DB17027FF309}.Release|Any CPU.Build.0 = Release|Any CPU
{540F21A8-CD9F-4288-ADCA-DB17027FF309}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{540F21A8-CD9F-4288-ADCA-DB17027FF309}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{540F21A8-CD9F-4288-ADCA-DB17027FF309}.Release|Win32.ActiveCfg = Release|Any CPU
{194D3B9A-AD99-44ED-991A-73C4A7EE550F}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{194D3B9A-AD99-44ED-991A-73C4A7EE550F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{194D3B9A-AD99-44ED-991A-73C4A7EE550F}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{194D3B9A-AD99-44ED-991A-73C4A7EE550F}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{194D3B9A-AD99-44ED-991A-73C4A7EE550F}.Debug|Win32.ActiveCfg = Debug|Any CPU
{194D3B9A-AD99-44ED-991A-73C4A7EE550F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{194D3B9A-AD99-44ED-991A-73C4A7EE550F}.Release|Any CPU.Build.0 = Release|Any CPU
{194D3B9A-AD99-44ED-991A-73C4A7EE550F}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{194D3B9A-AD99-44ED-991A-73C4A7EE550F}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{194D3B9A-AD99-44ED-991A-73C4A7EE550F}.Release|Win32.ActiveCfg = Release|Any CPU
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}.Debug|Any CPU.Build.0 = Debug|Any CPU
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}.Debug|Win32.ActiveCfg = Debug|Any CPU
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}.Release|Any CPU.ActiveCfg = Release|Any CPU
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}.Release|Any CPU.Build.0 = Release|Any CPU
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{83E805C9-4D29-4E34-A27E-5A78690FBD2B}.Release|Win32.ActiveCfg = Release|Any CPU
EndGlobalSection
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
HideSolutionNode = FALSE
...
...
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