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
c56980ec
Commit
c56980ec
authored
Nov 04, 2011
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DNS
Remove PcapDotNet.Analysis dependency
parent
34309d46
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
23 changed files
with
733 additions
and
59 deletions
+733
-59
PcapDotNet.Analysis.csproj
...alysis/src/PcapDotNet.Analysis/PcapDotNet.Analysis.csproj
+1
-1
PcapDotNet.Base.csproj
PcapDotNet/src/PcapDotNet.Base/PcapDotNet.Base.csproj
+1
-1
PcapDotNet.Core.Extensions.csproj
...pDotNet.Core.Extensions/PcapDotNet.Core.Extensions.csproj
+1
-1
PacketCommunicator.cpp
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.cpp
+0
-2
PacketCommunicator.h
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.h
+0
-1
PacketSendBuffer.cpp
PcapDotNet/src/PcapDotNet.Core/PacketSendBuffer.cpp
+0
-2
PcapDotNet.Core.vcxproj
PcapDotNet/src/PcapDotNet.Core/PcapDotNet.Core.vcxproj
+28
-11
ByteArrayExtensionsTests.cs
...t/src/PcapDotNet.Packets.Test/ByteArrayExtensionsTests.cs
+10
-0
DnsTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/DnsTests.cs
+25
-0
IpV4Tests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
+1
-1
RandomDnsExtensions.cs
...t/src/PcapDotNet.Packets.TestUtils/RandomDnsExtensions.cs
+44
-8
RandomGreExtensions.cs
...t/src/PcapDotNet.Packets.TestUtils/RandomGreExtensions.cs
+3
-7
RandomHttpExtensions.cs
.../src/PcapDotNet.Packets.TestUtils/RandomHttpExtensions.cs
+6
-12
ByteArrayExtensions.cs
PcapDotNet/src/PcapDotNet.Packets/ByteArrayExtensions.cs
+48
-1
DataSegment.cs
PcapDotNet/src/PcapDotNet.Packets/DataSegment.cs
+5
-0
DnsDataResourceRecord.cs
...otNet/src/PcapDotNet.Packets/Dns/DnsDataResourceRecord.cs
+74
-1
DnsDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsDatagram.cs
+19
-2
DnsOptionAnything.cs
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsOptionAnything.cs
+30
-0
DnsResourceData.cs
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsResourceData.cs
+407
-0
DnsResourceRecord.cs
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsResourceRecord.cs
+1
-0
Options.cs
PcapDotNet/src/PcapDotNet.Packets/Options.cs
+1
-1
PcapDotNet.Packets.csproj
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
+2
-1
RandomExtensions.cs
PcapDotNet/src/PcapDotNet.TestUtils/RandomExtensions.cs
+26
-6
No files found.
PcapDotNet.Analysis/src/PcapDotNet.Analysis/PcapDotNet.Analysis.csproj
View file @
c56980ec
...
@@ -77,7 +77,7 @@
...
@@ -77,7 +77,7 @@
</ItemGroup>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<Import
Project=
"$(MSBuildToolsPath)\Microsoft.CSharp.targets"
/>
<PropertyGroup>
<PropertyGroup>
<PreBuildEvent>
if not exist "$(SolutionDir)..\..\PcapDotNet\src\PcapDotNet.snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v
6
.0A\bin\sn.exe" -k "$(SolutionDir)..\..\PcapDotNet\src\PcapDotNet.snk")
</PreBuildEvent>
<PreBuildEvent>
if not exist "$(SolutionDir)..\..\PcapDotNet\src\PcapDotNet.snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v
7
.0A\bin\sn.exe" -k "$(SolutionDir)..\..\PcapDotNet\src\PcapDotNet.snk")
</PreBuildEvent>
</PropertyGroup>
</PropertyGroup>
<PropertyGroup>
<PropertyGroup>
<PostBuildEvent>
if not exist "$(SolutionDir)..\..\PcapDotNet\3rdParty\PcapDotNet.Analysis\" (mkdir "$(SolutionDir)..\..\PcapDotNet\3rdParty\PcapDotNet.Analysis\")
<PostBuildEvent>
if not exist "$(SolutionDir)..\..\PcapDotNet\3rdParty\PcapDotNet.Analysis\" (mkdir "$(SolutionDir)..\..\PcapDotNet\3rdParty\PcapDotNet.Analysis\")
...
...
PcapDotNet/src/PcapDotNet.Base/PcapDotNet.Base.csproj
View file @
c56980ec
...
@@ -139,7 +139,7 @@
...
@@ -139,7 +139,7 @@
</Target>
</Target>
-->
-->
<PropertyGroup>
<PropertyGroup>
<PreBuildEvent>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v
6
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</PreBuildEvent>
<PreBuildEvent>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v
7
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</PreBuildEvent>
<PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</PropertyGroup>
...
...
PcapDotNet/src/PcapDotNet.Core.Extensions/PcapDotNet.Core.Extensions.csproj
View file @
c56980ec
...
@@ -130,7 +130,7 @@
...
@@ -130,7 +130,7 @@
</Target>
</Target>
-->
-->
<PropertyGroup>
<PropertyGroup>
<PreBuildEvent>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v
6
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</PreBuildEvent>
<PreBuildEvent>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v
7
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</PreBuildEvent>
<PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</PropertyGroup>
...
...
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.cpp
View file @
c56980ec
...
@@ -244,7 +244,6 @@ void PacketCommunicator::SendPacket(Packet^ packet)
...
@@ -244,7 +244,6 @@ void PacketCommunicator::SendPacket(Packet^ packet)
pin_ptr
<
Byte
>
unamangedPacketBytes
=
&
packet
->
Buffer
[
0
];
pin_ptr
<
Byte
>
unamangedPacketBytes
=
&
packet
->
Buffer
[
0
];
if
(
pcap_sendpacket
(
_pcapDescriptor
,
unamangedPacketBytes
,
packet
->
Length
)
!=
0
)
if
(
pcap_sendpacket
(
_pcapDescriptor
,
unamangedPacketBytes
,
packet
->
Length
)
!=
0
)
throw
BuildInvalidOperation
(
"Failed writing to device"
);
throw
BuildInvalidOperation
(
"Failed writing to device"
);
PcapDotNet
::
Analysis
::
PcapDotNetAnalysis
::
PacketSent
();
}
}
BerkeleyPacketFilter
^
PacketCommunicator
::
CreateFilter
(
String
^
filterValue
)
BerkeleyPacketFilter
^
PacketCommunicator
::
CreateFilter
(
String
^
filterValue
)
...
@@ -307,7 +306,6 @@ InvalidOperationException^ PacketCommunicator::BuildInvalidOperation(System::Str
...
@@ -307,7 +306,6 @@ InvalidOperationException^ PacketCommunicator::BuildInvalidOperation(System::Str
// static
// static
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
)
{
{
PcapDotNet
::
Analysis
::
PcapDotNetAnalysis
::
PacketReceived
();
DateTime
timestamp
;
DateTime
timestamp
;
PacketTimestamp
::
PcapTimestampToDateTime
(
packetHeader
.
ts
,
timestamp
);
PacketTimestamp
::
PcapTimestampToDateTime
(
packetHeader
.
ts
,
timestamp
);
...
...
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.h
View file @
c56980ec
...
@@ -25,7 +25,6 @@ namespace PcapDotNet { namespace Core
...
@@ -25,7 +25,6 @@ namespace PcapDotNet { namespace Core
private
:
private
:
static
PacketCommunicator
()
static
PacketCommunicator
()
{
{
PcapDotNet
::
Analysis
::
PcapDotNetAnalysis
::
Initialize
();
}
}
public
:
public
:
...
...
PcapDotNet/src/PcapDotNet.Core/PacketSendBuffer.cpp
View file @
c56980ec
...
@@ -41,6 +41,4 @@ void PacketSendBuffer::Transmit(pcap_t* pcapDescriptor, bool isSync)
...
@@ -41,6 +41,4 @@ void PacketSendBuffer::Transmit(pcap_t* pcapDescriptor, bool isSync)
unsigned
int
numBytesTransmitted
=
pcap_sendqueue_transmit
(
pcapDescriptor
,
_pcapSendQueue
,
isSync
);
unsigned
int
numBytesTransmitted
=
pcap_sendqueue_transmit
(
pcapDescriptor
,
_pcapSendQueue
,
isSync
);
if
(
numBytesTransmitted
<
_pcapSendQueue
->
len
)
if
(
numBytesTransmitted
<
_pcapSendQueue
->
len
)
throw
PcapError
::
BuildInvalidOperation
(
"Failed transmiting packets from queue"
,
pcapDescriptor
);
throw
PcapError
::
BuildInvalidOperation
(
"Failed transmiting packets from queue"
,
pcapDescriptor
);
PcapDotNet
::
Analysis
::
PcapDotNetAnalysis
::
PacketSent
(
Length
);
}
}
PcapDotNet/src/PcapDotNet.Core/PcapDotNet.Core.vcxproj
View file @
c56980ec
...
@@ -22,9 +22,6 @@
...
@@ -22,9 +22,6 @@
<CodeAnalysisDictionary
Include=
"..\PcapDotNet.CodeAnalysisDictionary.xml"
/>
<CodeAnalysisDictionary
Include=
"..\PcapDotNet.CodeAnalysisDictionary.xml"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Reference
Include=
"PcapDotNet.Analysis, Version=0.8.0.0, Culture=neutral, PublicKeyToken=4b6f3e583145a652"
>
<HintPath>
..\..\3rdParty\PcapDotNet.Analysis\PcapDotNet.Analysis.dll
</HintPath>
</Reference>
<Reference
Include=
"System"
>
<Reference
Include=
"System"
>
<CopyLocalSatelliteAssemblies>
true
</CopyLocalSatelliteAssemblies>
<CopyLocalSatelliteAssemblies>
true
</CopyLocalSatelliteAssemblies>
<ReferenceOutputAssembly>
true
</ReferenceOutputAssembly>
<ReferenceOutputAssembly>
true
</ReferenceOutputAssembly>
...
@@ -206,11 +203,27 @@
...
@@ -206,11 +203,27 @@
<CodeAnalysisRuleAssemblies
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
/>
<CodeAnalysisRuleAssemblies
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
/>
<CodeAnalysisRuleSet
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
..\PcapDotNet.ruleset
</CodeAnalysisRuleSet>
<CodeAnalysisRuleSet
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
..\PcapDotNet.ruleset
</CodeAnalysisRuleSet>
<CodeAnalysisRuleAssemblies
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
/>
<CodeAnalysisRuleAssemblies
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
/>
<PostBuildEventUseInBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
true
</PostBuildEventUseInBuild>
<PostBuildEventUseInBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
true
</PostBuildEventUseInBuild>
<PostBuildEventUseInBuild
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
true
</PostBuildEventUseInBuild>
<PostBuildEventUseInBuild
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
true
</PostBuildEventUseInBuild>
<LinkKeyFile
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
..\$(SolutionName).snk
</LinkKeyFile>
<LinkKeyFile
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
..\$(SolutionName).snk
</LinkKeyFile>
<LinkKeyFile
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
..\$(SolutionName).snk
</LinkKeyFile>
<LinkKeyFile
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
..\$(SolutionName).snk
</LinkKeyFile>
<LinkDelaySign
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
</LinkDelaySign>
<LinkDelaySign
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
</LinkDelaySign>
<LinkDelaySign
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
</LinkDelaySign>
<LinkDelaySign
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
</LinkDelaySign>
</PropertyGroup>
</PropertyGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|Win32'"
>
<PreBuildEvent>
<PreBuildEvent>
<Message>
Create Public/Private Key Pair
</Message>
<Message>
Create Public/Private Key Pair
</Message>
<Command>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%PROGRAMFILES%\Microsoft SDKs\Windows\v
6
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</Command>
<Command>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%PROGRAMFILES%\Microsoft SDKs\Windows\v
7
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</Command>
</PreBuildEvent>
</PreBuildEvent>
<ClCompile>
<ClCompile>
<Optimization>
Disabled
</Optimization>
<Optimization>
Disabled
</Optimization>
...
@@ -240,13 +253,14 @@
...
@@ -240,13 +253,14 @@
<Command>
sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"
</Command>
<Command>
sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"
</Command>
</PostBuildEvent>
</PostBuildEvent>
<PreLinkEvent>
<PreLinkEvent>
<Command>
sn -Ra "$(SolutionDir)\..\3rdParty\PcapDotNet.Analysis\PcapDotNet.Analysis.dll" "$(SolutionDir)$(SolutionName).snk"
</Command>
<Command>
</Command>
</PreLinkEvent>
</PreLinkEvent>
</ItemDefinitionGroup>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Debug|x64'"
>
<PreBuildEvent>
<PreBuildEvent>
<Message>
Create Public/Private Key Pair
</Message>
<Message>
Create Public/Private Key Pair
</Message>
<Command>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%PROGRAMFILES%\Microsoft SDKs\Windows\v
6
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</Command>
<Command>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%PROGRAMFILES%\Microsoft SDKs\Windows\v
7
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</Command>
</PreBuildEvent>
</PreBuildEvent>
<Midl>
<Midl>
<TargetEnvironment>
X64
</TargetEnvironment>
<TargetEnvironment>
X64
</TargetEnvironment>
...
@@ -279,13 +293,14 @@
...
@@ -279,13 +293,14 @@
<Command>
sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"
</Command>
<Command>
sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"
</Command>
</PostBuildEvent>
</PostBuildEvent>
<PreLinkEvent>
<PreLinkEvent>
<Command>
sn -Ra "$(SolutionDir)\..\3rdParty\PcapDotNet.Analysis\PcapDotNet.Analysis.dll" "$(SolutionDir)$(SolutionName).snk"
</Command>
<Command>
</Command>
</PreLinkEvent>
</PreLinkEvent>
</ItemDefinitionGroup>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|Win32'"
>
<PreBuildEvent>
<PreBuildEvent>
<Message>
Create Public/Private Key Pair
</Message>
<Message>
Create Public/Private Key Pair
</Message>
<Command>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%PROGRAMFILES%\Microsoft SDKs\Windows\v
6
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</Command>
<Command>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%PROGRAMFILES%\Microsoft SDKs\Windows\v
7
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</Command>
</PreBuildEvent>
</PreBuildEvent>
<ClCompile>
<ClCompile>
<AdditionalIncludeDirectories>
..\..\3rdParty\WpdPack\Include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
<AdditionalIncludeDirectories>
..\..\3rdParty\WpdPack\Include;%(AdditionalIncludeDirectories)
</AdditionalIncludeDirectories>
...
@@ -313,13 +328,14 @@
...
@@ -313,13 +328,14 @@
<Command>
sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"
</Command>
<Command>
sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"
</Command>
</PostBuildEvent>
</PostBuildEvent>
<PreLinkEvent>
<PreLinkEvent>
<Command>
sn -Ra "$(SolutionDir)\..\3rdParty\PcapDotNet.Analysis\PcapDotNet.Analysis.dll" "$(SolutionDir)$(SolutionName).snk"
</Command>
<Command>
</Command>
</PreLinkEvent>
</PreLinkEvent>
</ItemDefinitionGroup>
</ItemDefinitionGroup>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<ItemDefinitionGroup
Condition=
"'$(Configuration)|$(Platform)'=='Release|x64'"
>
<PreBuildEvent>
<PreBuildEvent>
<Message>
Create Public/Private Key Pair
</Message>
<Message>
Create Public/Private Key Pair
</Message>
<Command>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%PROGRAMFILES%\Microsoft SDKs\Windows\v
6
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</Command>
<Command>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%PROGRAMFILES%\Microsoft SDKs\Windows\v
7
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</Command>
</PreBuildEvent>
</PreBuildEvent>
<Midl>
<Midl>
<TargetEnvironment>
X64
</TargetEnvironment>
<TargetEnvironment>
X64
</TargetEnvironment>
...
@@ -350,7 +366,8 @@
...
@@ -350,7 +366,8 @@
<Command>
sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"
</Command>
<Command>
sn -Ra "$(TargetPath)" "$(SolutionDir)$(SolutionName).snk"
</Command>
</PostBuildEvent>
</PostBuildEvent>
<PreLinkEvent>
<PreLinkEvent>
<Command>
sn -Ra "$(SolutionDir)\..\3rdParty\PcapDotNet.Analysis\PcapDotNet.Analysis.dll" "$(SolutionDir)$(SolutionName).snk"
</Command>
<Command>
</Command>
</PreLinkEvent>
</PreLinkEvent>
</ItemDefinitionGroup>
</ItemDefinitionGroup>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
<Import
Project=
"$(VCTargetsPath)\Microsoft.Cpp.targets"
/>
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/ByteArrayExtensionsTests.cs
View file @
c56980ec
...
@@ -158,5 +158,15 @@ namespace PcapDotNet.Packets.Test
...
@@ -158,5 +158,15 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
expectedValue
,
actualValue
);
Assert
.
AreEqual
(
expectedValue
,
actualValue
);
}
}
}
}
[
TestMethod
]
public
void
ByteArrayULongTest
()
{
ulong
expectedValue
=
10
;
byte
[]
buffer
=
new
byte
[
8
];
buffer
.
Write
(
0
,
expectedValue
,
Endianity
.
Big
);
ulong
actualValue
=
buffer
.
ReadULong
(
0
,
Endianity
.
Big
);
Assert
.
AreEqual
(
expectedValue
,
actualValue
);
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.Test/DnsTests.cs
View file @
c56980ec
...
@@ -10,6 +10,7 @@ using PcapDotNet.Packets.Ethernet;
...
@@ -10,6 +10,7 @@ using PcapDotNet.Packets.Ethernet;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.TestUtils
;
using
PcapDotNet.Packets.TestUtils
;
using
PcapDotNet.Packets.Transport
;
using
PcapDotNet.Packets.Transport
;
using
PcapDotNet.TestUtils
;
namespace
PcapDotNet.Packets.Test
namespace
PcapDotNet.Packets.Test
{
{
...
@@ -144,6 +145,30 @@ namespace PcapDotNet.Packets.Test
...
@@ -144,6 +145,30 @@ namespace PcapDotNet.Packets.Test
TestDomainNameCompression
(
6
,
dnsLayer
);
TestDomainNameCompression
(
6
,
dnsLayer
);
}
}
[
TestMethod
]
public
void
DnsOptResourceRecordTest
()
{
Random
random
=
new
Random
();
for
(
int
i
=
0
;
i
!=
100
;
++
i
)
{
DnsDomainName
domainName
=
random
.
NextDnsDomainName
();
ushort
sendersUdpPayloadSize
=
random
.
NextUShort
();
byte
extendedRcode
=
random
.
NextByte
();
DnsOptVersion
version
=
(
DnsOptVersion
)
random
.
NextByte
();
DnsOptFlags
flags
=
(
DnsOptFlags
)
random
.
NextUShort
();
DnsResourceDataOptions
data
=
(
DnsResourceDataOptions
)
random
.
NextDnsResourceData
(
DnsType
.
Opt
);
DnsOptResourceRecord
record
=
new
DnsOptResourceRecord
(
domainName
,
sendersUdpPayloadSize
,
extendedRcode
,
version
,
flags
,
data
);
Assert
.
AreEqual
(
domainName
,
record
.
DomainName
);
Assert
.
AreEqual
(
sendersUdpPayloadSize
,
record
.
SendersUdpPayloadSize
);
Assert
.
AreEqual
(
extendedRcode
,
record
.
ExtendedRcode
);
Assert
.
AreEqual
(
version
,
record
.
Version
);
Assert
.
AreEqual
(
flags
,
record
.
Flags
);
Assert
.
AreEqual
(
data
,
record
.
Data
);
}
}
[
TestMethod
]
[
TestMethod
]
public
void
SimpleDnsTest
()
public
void
SimpleDnsTest
()
{
{
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
View file @
c56980ec
...
@@ -96,7 +96,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -96,7 +96,7 @@ namespace PcapDotNet.Packets.Test
IpV4Layer
ipV4Layer
=
random
.
NextIpV4Layer
();
IpV4Layer
ipV4Layer
=
random
.
NextIpV4Layer
();
ipV4Layer
.
HeaderChecksum
=
null
;
ipV4Layer
.
HeaderChecksum
=
null
;
PayloadLayer
payloadLayer
=
random
.
NextPayloadLayer
(
random
.
Next
(
0
,
50
*
1024
));
PayloadLayer
payloadLayer
=
random
.
NextPayloadLayer
(
random
.
Next
Int
(
0
,
50
*
1024
));
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
ethernetLayer
,
ipV4Layer
,
payloadLayer
);
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
ethernetLayer
,
ipV4Layer
,
payloadLayer
);
...
...
PcapDotNet/src/PcapDotNet.Packets.TestUtils/RandomDnsExtensions.cs
View file @
c56980ec
...
@@ -57,8 +57,41 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -57,8 +57,41 @@ namespace PcapDotNet.Packets.TestUtils
public
static
DnsDataResourceRecord
NextDnsDataResourceRecord
(
this
Random
random
)
public
static
DnsDataResourceRecord
NextDnsDataResourceRecord
(
this
Random
random
)
{
{
DnsType
type
=
random
.
NextEnum
<
DnsType
>();
DnsType
type
=
random
.
NextEnum
<
DnsType
>();
DnsDataResourceRecord
record
=
new
DnsDataResourceRecord
(
random
.
NextDnsDomainName
(),
type
,
random
.
NextEnum
<
DnsClass
>(),
random
.
Next
(),
random
.
NextDnsResourceData
(
type
));
if
(
type
==
DnsType
.
Opt
)
return
record
;
{
return
new
DnsOptResourceRecord
(
random
.
NextDnsDomainName
(),
random
.
NextUShort
(),
random
.
NextByte
(),
(
DnsOptVersion
)
random
.
NextByte
(),
random
.
NextFlags
<
DnsOptFlags
>(),
(
DnsResourceDataOptions
)
random
.
NextDnsResourceData
(
type
));
}
return
new
DnsDataResourceRecord
(
random
.
NextDnsDomainName
(),
type
,
random
.
NextEnum
<
DnsClass
>(),
random
.
Next
(),
random
.
NextDnsResourceData
(
type
));
}
public
static
DnsOptions
NextDnsOptions
(
this
Random
random
)
{
return
new
DnsOptions
(((
Func
<
DnsOption
>)(()
=>
random
.
NextDnsOption
())).
GenerateArray
(
random
.
Next
(
10
)));
}
public
static
DnsOption
NextDnsOption
(
this
Random
random
)
{
if
(
random
.
NextBool
())
{
return
new
DnsOptionAnything
((
DnsOptionCode
)
random
.
NextUShort
(
4
,
ushort
.
MaxValue
+
1
),
random
.
NextDataSegment
(
random
.
Next
(
20
)));
}
switch
(
random
.
NextEnum
<
DnsOptionCode
>())
{
case
DnsOptionCode
.
LongLivedQuery
:
return
new
DnsOptionLongLivedQuery
(
random
.
NextUShort
(),
random
.
NextEnum
<
DnsLongLivedQueryOpcode
>(),
random
.
NextEnum
<
DnsLongLivedQueryErrorCode
>(),
random
.
NextULong
(),
random
.
NextUInt
());
case
DnsOptionCode
.
UpdateLease
:
return
new
DnsOptionUpdateLease
(
random
.
NextInt
());
case
DnsOptionCode
.
NameServerIdentifier
:
return
new
DnsOptionAnything
(
DnsOptionCode
.
NameServerIdentifier
,
random
.
NextDataSegment
(
random
.
NextInt
(
0
,
100
)));
default
:
throw
new
InvalidOperationException
(
"Invalid value"
);
}
}
}
public
static
DnsDomainName
NextDnsDomainName
(
this
Random
random
)
public
static
DnsDomainName
NextDnsDomainName
(
this
Random
random
)
...
@@ -152,18 +185,18 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -152,18 +185,18 @@ namespace PcapDotNet.Packets.TestUtils
return
new
DnsResourceDataX400Pointer
(
random
.
NextUShort
(),
random
.
NextDnsDomainName
(),
random
.
NextDnsDomainName
());
return
new
DnsResourceDataX400Pointer
(
random
.
NextUShort
(),
random
.
NextDnsDomainName
(),
random
.
NextDnsDomainName
());
case
DnsType
.
GPos
:
case
DnsType
.
GPos
:
return
new
DnsResourceDataGeographicalPosition
((
random
.
Next
(-
90
,
90
)
*
random
.
NextDouble
()).
ToString
(
"0.##########"
),
return
new
DnsResourceDataGeographicalPosition
((
random
.
Next
Int
(-
90
,
90
)
*
random
.
NextDouble
()).
ToString
(
"0.##########"
),
(
random
.
Next
(-
180
,
180
)
*
random
.
NextDouble
()).
ToString
(
"0.##########"
),
(
random
.
Next
Int
(-
180
,
180
)
*
random
.
NextDouble
()).
ToString
(
"0.##########"
),
(
random
.
Next
(-
500
,
50000
)
*
random
.
NextDouble
()).
ToString
(
"0.##########"
));
(
random
.
Next
Int
(-
500
,
50000
)
*
random
.
NextDouble
()).
ToString
(
"0.##########"
));
case
DnsType
.
Aaaa
:
case
DnsType
.
Aaaa
:
return
new
DnsResourceDataIpV6
(
random
.
NextIpV6Address
());
return
new
DnsResourceDataIpV6
(
random
.
NextIpV6Address
());
case
DnsType
.
Loc
:
case
DnsType
.
Loc
:
return
new
DnsResourceDataLocationInformation
(
random
.
NextByte
(),
return
new
DnsResourceDataLocationInformation
(
random
.
NextByte
(),
(
ulong
)(
random
.
Next
(
10
)
*
Math
.
Pow
(
10
,
random
.
Next
(
10
))),
(
ulong
)(
random
.
Next
Int
(
0
,
10
)
*
Math
.
Pow
(
10
,
random
.
NextInt
(
0
,
10
))),
(
ulong
)(
random
.
Next
(
10
)
*
Math
.
Pow
(
10
,
random
.
Next
(
10
))),
(
ulong
)(
random
.
Next
Int
(
0
,
10
)
*
Math
.
Pow
(
10
,
random
.
NextInt
(
0
,
10
))),
(
ulong
)(
random
.
Next
(
10
)
*
Math
.
Pow
(
10
,
random
.
Next
(
10
))),
(
ulong
)(
random
.
Next
Int
(
0
,
10
)
*
Math
.
Pow
(
10
,
random
.
NextInt
(
0
,
10
))),
random
.
NextUInt
(),
random
.
NextUInt
(),
random
.
NextUInt
());
random
.
NextUInt
(),
random
.
NextUInt
(),
random
.
NextUInt
());
case
DnsType
.
Nxt
:
case
DnsType
.
Nxt
:
...
@@ -210,6 +243,9 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -210,6 +243,9 @@ namespace PcapDotNet.Packets.TestUtils
case
DnsType
.
Sink
:
case
DnsType
.
Sink
:
return
new
DnsResourceDataSink
(
random
.
NextEnum
<
DnsSinkCoding
>(),
random
.
NextByte
(),
random
.
NextDataSegment
(
random
.
Next
(
100
)));
return
new
DnsResourceDataSink
(
random
.
NextEnum
<
DnsSinkCoding
>(),
random
.
NextByte
(),
random
.
NextDataSegment
(
random
.
Next
(
100
)));
case
DnsType
.
Opt
:
return
new
DnsResourceDataOptions
(
random
.
NextDnsOptions
());
default
:
default
:
return
new
DnsResourceDataAnything
(
random
.
NextDataSegment
(
random
.
Next
(
100
)));
return
new
DnsResourceDataAnything
(
random
.
NextDataSegment
(
random
.
Next
(
100
)));
}
}
...
...
PcapDotNet/src/PcapDotNet.Packets.TestUtils/RandomGreExtensions.cs
View file @
c56980ec
...
@@ -39,25 +39,21 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -39,25 +39,21 @@ namespace PcapDotNet.Packets.TestUtils
{
{
case
GreSourceRouteEntryAddressFamily
.
AsSourceRoute
:
case
GreSourceRouteEntryAddressFamily
.
AsSourceRoute
:
{
{
ushort
[]
asNumbers
=
new
ushort
[
random
.
Next
(
1
,
5
)];
ushort
[]
asNumbers
=
((
Func
<
ushort
>)(()
=>
random
.
NextUShort
())).
GenerateArray
(
random
.
NextInt
(
1
,
5
));
for
(
int
j
=
0
;
j
!=
asNumbers
.
Length
;
++
j
)
asNumbers
[
j
]
=
random
.
NextUShort
();
routing
[
i
]
=
new
GreSourceRouteEntryAs
(
asNumbers
.
AsReadOnly
(),
random
.
Next
(
asNumbers
.
Length
+
1
));
routing
[
i
]
=
new
GreSourceRouteEntryAs
(
asNumbers
.
AsReadOnly
(),
random
.
Next
(
asNumbers
.
Length
+
1
));
break
;
break
;
}
}
case
GreSourceRouteEntryAddressFamily
.
IpSourceRoute
:
case
GreSourceRouteEntryAddressFamily
.
IpSourceRoute
:
{
{
IpV4Address
[]
ips
=
new
IpV4Address
[
random
.
Next
(
1
,
5
)];
IpV4Address
[]
ips
=
((
Func
<
IpV4Address
>)(()
=>
random
.
NextIpV4Address
())).
GenerateArray
(
random
.
NextInt
(
1
,
5
));
for
(
int
j
=
0
;
j
!=
ips
.
Length
;
++
j
)
ips
[
j
]
=
random
.
NextIpV4Address
();
routing
[
i
]
=
new
GreSourceRouteEntryIp
(
ips
.
AsReadOnly
(),
random
.
Next
(
ips
.
Length
+
1
));
routing
[
i
]
=
new
GreSourceRouteEntryIp
(
ips
.
AsReadOnly
(),
random
.
Next
(
ips
.
Length
+
1
));
break
;
break
;
}
}
default
:
default
:
{
{
int
dataLength
=
random
.
Next
(
1
,
100
);
int
dataLength
=
random
.
Next
Int
(
1
,
100
);
routing
[
i
]
=
new
GreSourceRouteEntryUnknown
(
family
,
random
.
NextDatagram
(
dataLength
),
random
.
Next
(
dataLength
+
1
));
routing
[
i
]
=
new
GreSourceRouteEntryUnknown
(
family
,
random
.
NextDatagram
(
dataLength
),
random
.
Next
(
dataLength
+
1
));
break
;
break
;
}
}
...
...
PcapDotNet/src/PcapDotNet.Packets.TestUtils/RandomHttpExtensions.cs
View file @
c56980ec
...
@@ -65,11 +65,8 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -65,11 +65,8 @@ namespace PcapDotNet.Packets.TestUtils
public
static
string
NextHttpToken
(
this
Random
random
)
public
static
string
NextHttpToken
(
this
Random
random
)
{
{
int
tokenLength
=
random
.
Next
(
1
,
100
);
char
[]
httpToken
=
((
Func
<
char
>)(()
=>
random
.
NextHttpTokenChar
())).
GenerateArray
(
random
.
NextInt
(
1
,
100
));
StringBuilder
stringBuilder
=
new
StringBuilder
();
return
new
string
(
httpToken
);
for
(
int
i
=
0
;
i
!=
tokenLength
;
++
i
)
stringBuilder
.
Append
(
random
.
NextHttpTokenChar
());
return
stringBuilder
.
ToString
();
}
}
public
static
char
NextHttpTokenChar
(
this
Random
random
)
public
static
char
NextHttpTokenChar
(
this
Random
random
)
...
@@ -85,7 +82,7 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -85,7 +82,7 @@ namespace PcapDotNet.Packets.TestUtils
public
static
string
NextHttpFieldValue
(
this
Random
random
)
public
static
string
NextHttpFieldValue
(
this
Random
random
)
{
{
int
valueLength
=
random
.
Next
(
1
,
100
);
int
valueLength
=
random
.
Next
Int
(
1
,
100
);
StringBuilder
stringBuilder
=
new
StringBuilder
();
StringBuilder
stringBuilder
=
new
StringBuilder
();
while
(
stringBuilder
.
Length
<
valueLength
)
while
(
stringBuilder
.
Length
<
valueLength
)
{
{
...
@@ -178,10 +175,7 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -178,10 +175,7 @@ namespace PcapDotNet.Packets.TestUtils
return
HttpField
.
CreateField
(
fieldName
,
random
.
NextHttpFieldValue
());
return
HttpField
.
CreateField
(
fieldName
,
random
.
NextHttpFieldValue
());
case
HttpTransferEncodingField
.
FieldNameUpper
:
case
HttpTransferEncodingField
.
FieldNameUpper
:
int
numTransferCodings
=
random
.
Next
(
1
,
10
);
string
[]
transferCodings
=
((
Func
<
string
>)(()
=>
random
.
NextHttpTransferCoding
())).
GenerateArray
(
random
.
NextInt
(
1
,
10
));
List
<
string
>
transferCodings
=
new
List
<
string
>(
numTransferCodings
);
for
(
int
i
=
0
;
i
!=
numTransferCodings
;
++
i
)
transferCodings
.
Add
(
random
.
NextHttpTransferCoding
());
return
new
HttpTransferEncodingField
(
transferCodings
);
return
new
HttpTransferEncodingField
(
transferCodings
);
case
HttpContentLengthField
.
FieldNameUpper
:
case
HttpContentLengthField
.
FieldNameUpper
:
...
@@ -267,7 +261,7 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -267,7 +261,7 @@ namespace PcapDotNet.Packets.TestUtils
int
numChunks
=
random
.
Next
(
10
);
int
numChunks
=
random
.
Next
(
10
);
for
(
int
i
=
0
;
i
!=
numChunks
;
++
i
)
for
(
int
i
=
0
;
i
!=
numChunks
;
++
i
)
{
{
int
chunkSize
=
random
.
Next
(
1
,
1000
);
int
chunkSize
=
random
.
Next
Int
(
1
,
1000
);
chunkedBody
.
AddRange
(
Encoding
.
ASCII
.
GetBytes
(
chunkSize
.
ToString
(
"x"
)));
chunkedBody
.
AddRange
(
Encoding
.
ASCII
.
GetBytes
(
chunkSize
.
ToString
(
"x"
)));
var
chunkExtension
=
random
.
NextHttpFieldParameters
();
var
chunkExtension
=
random
.
NextHttpFieldParameters
();
foreach
(
var
parameter
in
chunkExtension
)
foreach
(
var
parameter
in
chunkExtension
)
...
@@ -281,7 +275,7 @@ namespace PcapDotNet.Packets.TestUtils
...
@@ -281,7 +275,7 @@ namespace PcapDotNet.Packets.TestUtils
chunkedBody
.
AddRange
(
random
.
NextDatagram
(
chunkSize
));
chunkedBody
.
AddRange
(
random
.
NextDatagram
(
chunkSize
));
chunkedBody
.
AddRange
(
Encoding
.
ASCII
.
GetBytes
(
"\r\n"
));
chunkedBody
.
AddRange
(
Encoding
.
ASCII
.
GetBytes
(
"\r\n"
));
}
}
int
numZeros
=
random
.
Next
(
1
,
10
);
int
numZeros
=
random
.
Next
Int
(
1
,
10
);
for
(
int
i
=
0
;
i
!=
numZeros
;
++
i
)
for
(
int
i
=
0
;
i
!=
numZeros
;
++
i
)
chunkedBody
.
Add
((
byte
)
'0'
);
chunkedBody
.
Add
((
byte
)
'0'
);
var
lastChunkExtension
=
random
.
NextHttpFieldParameters
();
var
lastChunkExtension
=
random
.
NextHttpFieldParameters
();
...
...
PcapDotNet/src/PcapDotNet.Packets/ByteArrayExtensions.cs
View file @
c56980ec
...
@@ -320,6 +320,19 @@ namespace PcapDotNet.Packets
...
@@ -320,6 +320,19 @@ namespace PcapDotNet.Packets
return
result
;
return
result
;
}
}
public
static
long
ReadLong
(
this
byte
[]
buffer
,
int
offset
,
Endianity
endianity
)
{
long
value
=
ReadLong
(
buffer
,
offset
);
if
(
IsWrongEndianity
(
endianity
))
value
=
IPAddress
.
HostToNetworkOrder
(
value
);
return
value
;
}
public
static
ulong
ReadULong
(
this
byte
[]
buffer
,
int
offset
,
Endianity
endianity
)
{
return
(
ulong
)
buffer
.
ReadLong
(
offset
,
endianity
);
}
/// <summary>
/// <summary>
/// Reads 16 bytes from a specific offset as a UInt128 with a given endianity.
/// Reads 16 bytes from a specific offset as a UInt128 with a given endianity.
/// </summary>
/// </summary>
...
@@ -617,10 +630,22 @@ namespace PcapDotNet.Packets
...
@@ -617,10 +630,22 @@ namespace PcapDotNet.Packets
/// <param name="endianity">The endianity to use when converting the value to bytes.</param>
/// <param name="endianity">The endianity to use when converting the value to bytes.</param>
public
static
void
Write
(
this
byte
[]
buffer
,
ref
int
offset
,
UInt48
value
,
Endianity
endianity
)
public
static
void
Write
(
this
byte
[]
buffer
,
ref
int
offset
,
UInt48
value
,
Endianity
endianity
)
{
{
Write
(
buffer
,
offset
,
value
,
endianity
);
buffer
.
Write
(
offset
,
value
,
endianity
);
offset
+=
UInt48
.
SizeOf
;
offset
+=
UInt48
.
SizeOf
;
}
}
public
static
void
Write
(
this
byte
[]
buffer
,
int
offset
,
long
value
,
Endianity
endianity
)
{
if
(
IsWrongEndianity
(
endianity
))
value
=
IPAddress
.
HostToNetworkOrder
(
value
);
Write
(
buffer
,
offset
,
value
);
}
public
static
void
Write
(
this
byte
[]
buffer
,
int
offset
,
ulong
value
,
Endianity
endianity
)
{
buffer
.
Write
(
offset
,
(
long
)
value
,
endianity
);
}
/// <summary>
/// <summary>
/// Writes the given value to the buffer using the given endianity.
/// Writes the given value to the buffer using the given endianity.
/// </summary>
/// </summary>
...
@@ -919,6 +944,17 @@ namespace PcapDotNet.Packets
...
@@ -919,6 +944,17 @@ namespace PcapDotNet.Packets
}
}
}
}
private
static
long
ReadLong
(
byte
[]
buffer
,
int
offset
)
{
unsafe
{
fixed
(
byte
*
ptr
=
&
buffer
[
offset
])
{
return
*((
long
*)
ptr
);
}
}
}
private
static
UInt128
ReadUInt128
(
byte
[]
buffer
,
int
offset
)
private
static
UInt128
ReadUInt128
(
byte
[]
buffer
,
int
offset
)
{
{
unsafe
unsafe
...
@@ -974,6 +1010,17 @@ namespace PcapDotNet.Packets
...
@@ -974,6 +1010,17 @@ namespace PcapDotNet.Packets
}
}
}
}
private
static
void
Write
(
byte
[]
buffer
,
int
offset
,
long
value
)
{
unsafe
{
fixed
(
byte
*
ptr
=
&
buffer
[
offset
])
{
*((
long
*)
ptr
)
=
value
;
}
}
}
private
static
void
Write
(
byte
[]
buffer
,
int
offset
,
UInt128
value
)
private
static
void
Write
(
byte
[]
buffer
,
int
offset
,
UInt128
value
)
{
{
unsafe
unsafe
...
...
PcapDotNet/src/PcapDotNet.Packets/DataSegment.cs
View file @
c56980ec
...
@@ -234,6 +234,11 @@ namespace PcapDotNet.Packets
...
@@ -234,6 +234,11 @@ namespace PcapDotNet.Packets
return
Buffer
.
ReadUInt48
(
StartOffset
+
offset
,
endianity
);
return
Buffer
.
ReadUInt48
(
StartOffset
+
offset
,
endianity
);
}
}
internal
ulong
ReadULong
(
int
offset
,
Endianity
endianity
)
{
return
Buffer
.
ReadULong
(
StartOffset
+
offset
,
endianity
);
}
internal
BigInteger
ReadUnsignedBigInteger
(
int
offset
,
int
length
,
Endianity
endianity
)
internal
BigInteger
ReadUnsignedBigInteger
(
int
offset
,
int
length
,
Endianity
endianity
)
{
{
return
Buffer
.
ReadUnsignedBigInteger
(
StartOffset
+
offset
,
length
,
endianity
);
return
Buffer
.
ReadUnsignedBigInteger
(
StartOffset
+
offset
,
length
,
endianity
);
...
...
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsDataResourceRecord.cs
View file @
c56980ec
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
namespace
PcapDotNet.Packets.Dns
namespace
PcapDotNet.Packets.Dns
{
{
public
sealed
class
DnsDataResourceRecord
:
DnsResourceRecord
,
IEquatable
<
DnsDataResourceRecord
>
public
class
DnsDataResourceRecord
:
DnsResourceRecord
,
IEquatable
<
DnsDataResourceRecord
>
{
{
private
static
class
OffsetAfterBase
private
static
class
OffsetAfterBase
{
{
...
@@ -73,6 +73,8 @@ namespace PcapDotNet.Packets.Dns
...
@@ -73,6 +73,8 @@ namespace PcapDotNet.Packets.Dns
return
null
;
return
null
;
numBytesRead
+=
dataLength
;
numBytesRead
+=
dataLength
;
if
(
type
==
DnsType
.
Opt
)
return
new
DnsOptResourceRecord
(
domainName
,
dnsClass
,
ttl
,
data
);
return
new
DnsDataResourceRecord
(
domainName
,
type
,
dnsClass
,
ttl
,
data
);
return
new
DnsDataResourceRecord
(
domainName
,
type
,
dnsClass
,
ttl
,
data
);
}
}
...
@@ -90,4 +92,75 @@ namespace PcapDotNet.Packets.Dns
...
@@ -90,4 +92,75 @@ namespace PcapDotNet.Packets.Dns
return
length
;
return
length
;
}
}
}
}
public
enum
DnsOptVersion
:
byte
{
Version0
=
0
,
}
[
Flags
]
public
enum
DnsOptFlags
:
ushort
{
DnsSecOk
=
0x8000
,
}
/// <summary>
/// RFC 2671.
/// <pre>
/// +------+----------------+----------+
/// | bit | 0-7 | 8-15 |
/// +------+----------------+----------+
/// | 0 | Name |
/// | ... | |
/// +------+---------------------------+
/// | | Type = OPT |
/// +------+---------------------------+
/// | | Sender's UDP payload size |
/// +------+----------------+----------+
/// | | EXTENDED-RCODE | VERSION |
/// +------+----------------+----------+
/// | | Flags |
/// +------+---------------------------+
/// | | Resource Data Length |
/// +------+---------------------------+
/// | | Resource Data |
/// | ... | |
/// +------+---------------------------+
/// </pre>
/// </summary>
public
sealed
class
DnsOptResourceRecord
:
DnsDataResourceRecord
{
public
DnsOptResourceRecord
(
DnsDomainName
domainName
,
ushort
sendersUdpPayloadSize
,
byte
extendedRcode
,
DnsOptVersion
version
,
DnsOptFlags
flags
,
DnsResourceDataOptions
data
)
:
this
(
domainName
,
(
DnsClass
)
sendersUdpPayloadSize
,
(
extendedRcode
<<
24
)
|
((
byte
)
version
<<
16
)
|
(
ushort
)
flags
,
data
)
{
}
/// <summary>
/// The number of octets of the largest UDP payload that can be reassembled and delivered in the sender's network stack.
/// Note that path MTU, with or without fragmentation, may be smaller than this.
/// </summary>
public
ushort
SendersUdpPayloadSize
{
get
{
return
(
ushort
)
DnsClass
;
}
}
/// <summary>
/// Forms upper 8 bits of extended 12-bit RCODE.
/// Note that EXTENDED-RCODE value "0" indicates that an unextended RCODE is in use (values "0" through "15").
/// </summary>
public
byte
ExtendedRcode
{
get
{
return
(
byte
)(
Ttl
>>
24
);
}
}
/// <summary>
/// Indicates the implementation level of whoever sets it.
/// Full conformance with this specification is indicated by version "0".
/// Requestors are encouraged to set this to the lowest implemented level capable of expressing a transaction,
/// to minimize the responder and network load of discovering the greatest common implementation level between requestor and responder.
/// A requestor's version numbering strategy should ideally be a run time configuration option.
/// </summary>
public
DnsOptVersion
Version
{
get
{
return
(
DnsOptVersion
)(
Ttl
>>
16
);
}}
public
DnsOptFlags
Flags
{
get
{
return
(
DnsOptFlags
)
Ttl
;
}
}
internal
DnsOptResourceRecord
(
DnsDomainName
domainName
,
DnsClass
dnsClass
,
int
ttl
,
DnsResourceData
data
)
:
base
(
domainName
,
DnsType
.
Opt
,
dnsClass
,
ttl
,
data
)
{
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsDatagram.cs
View file @
c56980ec
...
@@ -241,6 +241,15 @@ namespace PcapDotNet.Packets.Dns
...
@@ -241,6 +241,15 @@ namespace PcapDotNet.Packets.Dns
}
}
}
}
public
DnsOptResourceRecord
OptionsRecord
{
get
{
ParseAdditionals
();
return
_options
;
}
}
/// <summary>
/// <summary>
/// Creates a Layer that represents the datagram to be used with PacketBuilder.
/// Creates a Layer that represents the datagram to be used with PacketBuilder.
/// </summary>
/// </summary>
...
@@ -398,12 +407,16 @@ namespace PcapDotNet.Packets.Dns
...
@@ -398,12 +407,16 @@ namespace PcapDotNet.Packets.Dns
private
void
ParseAdditionals
()
private
void
ParseAdditionals
()
{
{
int
nextOffset
=
0
;
int
nextOffset
=
0
;
ParseRecords
(
AdditionalsOffset
,
()
=>
AdditionalCount
,
DnsDataResourceRecord
.
Parse
,
ref
_additionals
,
ref
nextOffset
);
if
(
ParseRecords
(
AdditionalsOffset
,
()
=>
AdditionalCount
,
DnsDataResourceRecord
.
Parse
,
ref
_additionals
,
ref
nextOffset
)
&&
_additionals
!=
null
)
{
_options
=
(
DnsOptResourceRecord
)
_additionals
.
FirstOrDefault
(
additional
=>
additional
.
Type
==
DnsType
.
Opt
);
}
}
}
private
delegate
TRecord
ParseRecord
<
out
TRecord
>(
DnsDatagram
dns
,
int
offset
,
out
int
numBytesRead
);
private
delegate
TRecord
ParseRecord
<
out
TRecord
>(
DnsDatagram
dns
,
int
offset
,
out
int
numBytesRead
);
private
void
ParseRecords
<
TRecord
>(
int
offset
,
Func
<
ushort
>
countDelegate
,
ParseRecord
<
TRecord
>
parseRecord
,
private
bool
ParseRecords
<
TRecord
>(
int
offset
,
Func
<
ushort
>
countDelegate
,
ParseRecord
<
TRecord
>
parseRecord
,
ref
ReadOnlyCollection
<
TRecord
>
parsedRecords
,
ref
int
nextOffset
)
where
TRecord
:
DnsResourceRecord
ref
ReadOnlyCollection
<
TRecord
>
parsedRecords
,
ref
int
nextOffset
)
where
TRecord
:
DnsResourceRecord
{
{
if
(
parsedRecords
==
null
&&
Length
>=
offset
)
if
(
parsedRecords
==
null
&&
Length
>=
offset
)
...
@@ -424,13 +437,17 @@ namespace PcapDotNet.Packets.Dns
...
@@ -424,13 +437,17 @@ namespace PcapDotNet.Packets.Dns
}
}
parsedRecords
=
new
ReadOnlyCollection
<
TRecord
>(
records
.
ToArray
());
parsedRecords
=
new
ReadOnlyCollection
<
TRecord
>(
records
.
ToArray
());
nextOffset
=
offset
;
nextOffset
=
offset
;
return
true
;
}
}
return
false
;
}
}
private
ReadOnlyCollection
<
DnsQueryResourceRecord
>
_queries
;
private
ReadOnlyCollection
<
DnsQueryResourceRecord
>
_queries
;
private
ReadOnlyCollection
<
DnsDataResourceRecord
>
_answers
;
private
ReadOnlyCollection
<
DnsDataResourceRecord
>
_answers
;
private
ReadOnlyCollection
<
DnsDataResourceRecord
>
_authorities
;
private
ReadOnlyCollection
<
DnsDataResourceRecord
>
_authorities
;
private
ReadOnlyCollection
<
DnsDataResourceRecord
>
_additionals
;
private
ReadOnlyCollection
<
DnsDataResourceRecord
>
_additionals
;
private
DnsOptResourceRecord
_options
;
private
int
_answersOffset
;
private
int
_answersOffset
;
private
int
_authoritiesOffset
;
private
int
_authoritiesOffset
;
...
...
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsOptionAnything.cs
0 → 100644
View file @
c56980ec
using
System
;
namespace
PcapDotNet.Packets.Dns
{
public
class
DnsOptionAnything
:
DnsOption
{
public
DnsOptionAnything
(
DnsOptionCode
code
,
DataSegment
data
)
:
base
(
code
)
{
Data
=
data
;
}
public
DataSegment
Data
{
get
;
private
set
;
}
public
override
int
DataLength
{
get
{
return
Data
.
Length
;
}
}
internal
override
bool
EqualsData
(
DnsOption
other
)
{
return
Data
.
Equals
(((
DnsOptionAnything
)
other
).
Data
);
}
internal
override
void
WriteData
(
byte
[]
buffer
,
ref
int
offset
)
{
Data
.
Write
(
buffer
,
ref
offset
);
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsResourceData.cs
View file @
c56980ec
This diff is collapsed.
Click to expand it.
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsResourceRecord.cs
View file @
c56980ec
...
@@ -26,6 +26,7 @@ namespace PcapDotNet.Packets.Dns
...
@@ -26,6 +26,7 @@ namespace PcapDotNet.Packets.Dns
/// | ... | |
/// | ... | |
/// +------+-------------------------------------------------+
/// +------+-------------------------------------------------+
/// </pre>
/// </pre>
/// </summary>
public
abstract
class
DnsResourceRecord
public
abstract
class
DnsResourceRecord
{
{
private
static
class
OffsetAfterDomainName
private
static
class
OffsetAfterDomainName
...
...
PcapDotNet/src/PcapDotNet.Packets/Options.cs
View file @
c56980ec
...
@@ -114,7 +114,7 @@ namespace PcapDotNet.Packets
...
@@ -114,7 +114,7 @@ namespace PcapDotNet.Packets
private
Options
(
IList
<
T
>
options
,
bool
isValid
)
private
Options
(
IList
<
T
>
options
,
bool
isValid
)
{
{
_options
=
new
ReadOnlyCollection
<
T
>(
options
);
_options
=
options
.
AsReadOnly
(
);
IsValid
=
isValid
;
IsValid
=
isValid
;
...
...
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
View file @
c56980ec
...
@@ -101,6 +101,7 @@
...
@@ -101,6 +101,7 @@
<Compile
Include=
"Dns\DnsDomainNameCompressionMode.cs"
/>
<Compile
Include=
"Dns\DnsDomainNameCompressionMode.cs"
/>
<Compile
Include=
"Dns\DnsLayer.cs"
/>
<Compile
Include=
"Dns\DnsLayer.cs"
/>
<Compile
Include=
"Dns\DnsOpcode.cs"
/>
<Compile
Include=
"Dns\DnsOpcode.cs"
/>
<Compile
Include=
"Dns\DnsOptionAnything.cs"
/>
<Compile
Include=
"Dns\DnsQueryResourceRecord.cs"
/>
<Compile
Include=
"Dns\DnsQueryResourceRecord.cs"
/>
<Compile
Include=
"Dns\DnsResourceData.cs"
/>
<Compile
Include=
"Dns\DnsResourceData.cs"
/>
<Compile
Include=
"Dns\DnsResourceDataAnything.cs"
/>
<Compile
Include=
"Dns\DnsResourceDataAnything.cs"
/>
...
@@ -342,7 +343,7 @@
...
@@ -342,7 +343,7 @@
</Target>
</Target>
-->
-->
<PropertyGroup>
<PropertyGroup>
<PreBuildEvent>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v
6
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</PreBuildEvent>
<PreBuildEvent>
if not exist "$(SolutionDir)$(SolutionName).snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v
7
.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")
</PreBuildEvent>
<PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</PropertyGroup>
...
...
PcapDotNet/src/PcapDotNet.TestUtils/RandomExtensions.cs
View file @
c56980ec
...
@@ -16,12 +16,12 @@ namespace PcapDotNet.TestUtils
...
@@ -16,12 +16,12 @@ namespace PcapDotNet.TestUtils
public
static
byte
NextByte
(
this
Random
random
,
int
minValue
,
int
maxValue
)
public
static
byte
NextByte
(
this
Random
random
,
int
minValue
,
int
maxValue
)
{
{
return
(
byte
)
random
.
Next
(
minValue
,
maxValue
);
return
(
byte
)
random
.
Next
Int
(
minValue
,
maxValue
);
}
}
public
static
byte
NextByte
(
this
Random
random
,
int
maxValue
)
public
static
byte
NextByte
(
this
Random
random
,
int
maxValue
)
{
{
return
(
byte
)
random
.
Next
(
maxValue
);
return
(
byte
)
random
.
Next
Int
(
0
,
maxValue
);
}
}
public
static
byte
NextByte
(
this
Random
random
)
public
static
byte
NextByte
(
this
Random
random
)
...
@@ -38,12 +38,17 @@ namespace PcapDotNet.TestUtils
...
@@ -38,12 +38,17 @@ namespace PcapDotNet.TestUtils
public
static
char
NextChar
(
this
Random
random
,
char
minValue
,
char
maxValue
)
public
static
char
NextChar
(
this
Random
random
,
char
minValue
,
char
maxValue
)
{
{
return
(
char
)
random
.
Next
(
minValue
,
maxValue
);
return
(
char
)
random
.
Next
Int
(
minValue
,
maxValue
);
}
}
public
static
ushort
NextUShort
(
this
Random
random
,
int
maxValue
)
public
static
ushort
NextUShort
(
this
Random
random
,
int
maxValue
)
{
{
return
(
ushort
)
random
.
Next
(
maxValue
);
return
(
ushort
)
random
.
NextInt
(
0
,
maxValue
);
}
public
static
ushort
NextUShort
(
this
Random
random
,
ushort
minValue
,
int
maxValue
)
{
return
(
ushort
)
random
.
NextInt
(
minValue
,
maxValue
);
}
}
public
static
ushort
NextUShort
(
this
Random
random
)
public
static
ushort
NextUShort
(
this
Random
random
)
...
@@ -53,12 +58,27 @@ namespace PcapDotNet.TestUtils
...
@@ -53,12 +58,27 @@ namespace PcapDotNet.TestUtils
public
static
UInt24
NextUInt24
(
this
Random
random
)
public
static
UInt24
NextUInt24
(
this
Random
random
)
{
{
return
(
UInt24
)
random
.
Next
(
UInt24
.
MaxValue
+
1
);
return
(
UInt24
)
random
.
NextInt
(
0
,
UInt24
.
MaxValue
+
1
);
}
public
static
int
NextInt
(
this
Random
random
)
{
return
random
.
Next
(
int
.
MinValue
,
int
.
MaxValue
);
}
public
static
int
NextInt
(
this
Random
random
,
int
maxValue
)
{
return
random
.
Next
(
int
.
MinValue
,
maxValue
);
}
public
static
int
NextInt
(
this
Random
random
,
int
minValue
,
int
maxValue
)
{
return
random
.
Next
(
minValue
,
maxValue
);
}
}
public
static
uint
NextUInt
(
this
Random
random
)
public
static
uint
NextUInt
(
this
Random
random
)
{
{
return
(
uint
)
random
.
Next
(
int
.
MinValue
,
int
.
MaxValue
);
return
(
uint
)
random
.
Next
Int
(
);
}
}
public
static
uint
NextUInt
(
this
Random
random
,
uint
maxValue
)
public
static
uint
NextUInt
(
this
Random
random
,
uint
maxValue
)
...
...
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