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
b5224c38
Commit
b5224c38
authored
Jan 27, 2012
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DNS
Code coverage 94.28%
parent
16498b62
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
108 additions
and
14 deletions
+108
-14
LivePacketDeviceTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
+2
-2
DnsTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/DnsTests.cs
+102
-11
DnsResourceData.cs
...rc/PcapDotNet.Packets/Dns/ResourceData/DnsResourceData.cs
+2
-0
DnsResourceDataNamingAuthorityPointer.cs
...Dns/ResourceData/DnsResourceDataNamingAuthorityPointer.cs
+2
-1
No files found.
PcapDotNet/src/PcapDotNet.Core.Test/LivePacketDeviceTests.cs
View file @
b5224c38
...
...
@@ -161,7 +161,7 @@ namespace PcapDotNet.Core.Test
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
/
2
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
Ok
,
NumPacketsToSend
/
2
,
0
,
0.04
);
// Wait for more packets
TestReceivePackets
(
NumPacketsToSend
,
0
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.
14
);
TestReceivePackets
(
NumPacketsToSend
,
0
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.
45
);
TestReceivePackets
(
NumPacketsToSend
,
-
1
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.3
);
TestReceivePackets
(
NumPacketsToSend
,
NumPacketsToSend
+
1
,
int
.
MaxValue
,
2
,
PacketSize
,
PacketCommunicatorReceiveResult
.
None
,
NumPacketsToSend
,
2
,
2.12
);
...
...
@@ -319,7 +319,7 @@ namespace PcapDotNet.Core.Test
// Wait for less statistics
TestGetStatistics
(
SourceMac
,
DestinationMac
,
NumPacketsToSend
,
NumStatisticsToGather
/
2
,
int
.
MaxValue
,
5
,
PacketSize
,
PacketCommunicatorReceiveResult
.
Ok
,
NumStatisticsToGather
/
2
,
NumPacketsToSend
,
NumStatisticsToGather
/
2
,
NumStatisticsToGather
/
2
+
0.
053
);
PacketCommunicatorReceiveResult
.
Ok
,
NumStatisticsToGather
/
2
,
NumPacketsToSend
,
NumStatisticsToGather
/
2
,
NumStatisticsToGather
/
2
+
0.
17
);
// Wait for more statistics
TestGetStatistics
(
SourceMac
,
DestinationMac
,
NumPacketsToSend
,
0
,
int
.
MaxValue
,
5.5
,
PacketSize
,
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/DnsTests.cs
View file @
b5224c38
...
...
@@ -88,15 +88,17 @@ namespace PcapDotNet.Packets.Test
foreach
(
var
record
in
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
ResourceRecords
)
{
Assert
.
AreEqual
<
object
>(
record
,
record
);
Assert
.
AreEqual
<
object
>(
record
.
DomainName
,
record
.
DomainName
);
Assert
.
IsTrue
(
record
.
Equals
(
record
));
Assert
.
IsTrue
(
record
.
DomainName
.
Equals
((
object
)
record
.
DomainName
));
Assert
.
IsTrue
(
record
.
DomainName
.
Equals
((
object
)
record
.
DomainName
));
}
foreach
(
var
record
in
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
DataResourceRecords
)
{
MoreAssert
.
IsBiggerOrEqual
(
9
,
record
.
ToString
().
Length
);
Assert
.
AreEqual
<
object
>(
record
,
record
);
Assert
.
IsTrue
(
record
.
Equals
((
object
)
record
)
);
Assert
.
IsInstanceOfType
(
record
.
Data
,
DnsResourceData
.
GetDnsResourceDataType
(
record
.
Type
)
??
typeof
(
DnsResourceDataAnything
));
Assert
.
IsTrue
(
record
.
DomainName
.
Equals
((
object
)
record
.
DomainName
));
}
}
}
...
...
@@ -163,6 +165,27 @@ namespace PcapDotNet.Packets.Test
TestDomainNameCompression
(
6
,
dnsLayer
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
DnsCompressionInvalidModeTest
()
{
DnsLayer
dnsLayer
=
new
DnsLayer
{
DomainNameCompressionMode
=
(
DnsDomainNameCompressionMode
)
int
.
MaxValue
,
Answers
=
new
List
<
DnsDataResourceRecord
>(
new
[]
{
new
DnsDataResourceRecord
(
new
DnsDomainName
(
"a"
),
DnsType
.
A
,
DnsClass
.
In
,
10
,
new
DnsResourceDataIpV4
(
IpV4Address
.
Zero
))
}),
};
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
(),
new
UdpLayer
(),
dnsLayer
);
Assert
.
IsNull
(
packet
);
Assert
.
Fail
();
}
[
TestMethod
]
public
void
DnsOptResourceRecordTest
()
{
...
...
@@ -248,11 +271,48 @@ namespace PcapDotNet.Packets.Test
Assert
.
Fail
();
}
[
TestMethod
]
public
void
DnsResourceDataNamingAuthorityPointerTest
()
{
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
NaPtr
,
new
DnsResourceDataNamingAuthorityPointer
(
0
,
0
,
DataSegment
.
Empty
,
DataSegment
.
Empty
,
DataSegment
.
Empty
,
DnsDomainName
.
Root
),
-
1
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
NaPtr
,
new
DnsResourceDataNamingAuthorityPointer
(
0
,
0
,
new
DataSegment
(
Encoding
.
ASCII
.
GetBytes
(
"abcd"
)),
DataSegment
.
Empty
,
DataSegment
.
Empty
,
DnsDomainName
.
Root
),
-
4
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
NaPtr
,
new
DnsResourceDataNamingAuthorityPointer
(
0
,
0
,
DataSegment
.
Empty
,
new
DataSegment
(
Encoding
.
ASCII
.
GetBytes
(
"abc"
)),
DataSegment
.
Empty
,
DnsDomainName
.
Root
),
-
3
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
NaPtr
,
new
DnsResourceDataNamingAuthorityPointer
(
0
,
0
,
DataSegment
.
Empty
,
DataSegment
.
Empty
,
new
DataSegment
(
Encoding
.
ASCII
.
GetBytes
(
"ab"
)),
DnsDomainName
.
Root
),
-
2
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
NaPtr
,
new
DnsResourceDataNamingAuthorityPointer
(
0
,
0
,
DataSegment
.
Empty
,
DataSegment
.
Empty
,
DataSegment
.
Empty
,
new
DnsDomainName
(
"a"
)),
-
1
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
NaPtr
,
new
DnsResourceDataNamingAuthorityPointer
(
0
,
0
,
DataSegment
.
Empty
,
DataSegment
.
Empty
,
DataSegment
.
Empty
,
DnsDomainName
.
Root
),
1
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
DnsResourceDataNamingAuthorityPointerIllegalFlagsTest
()
{
var
resourceData
=
new
DnsResourceDataNamingAuthorityPointer
(
0
,
0
,
new
DataSegment
(
new
byte
[]
{(
byte
)
'%'
}),
var
resourceData
=
new
DnsResourceDataNamingAuthorityPointer
(
0
,
0
,
new
DataSegment
(
new
[]
{(
byte
)
'%'
}),
DataSegment
.
Empty
,
DataSegment
.
Empty
,
DnsDomainName
.
Root
);
Assert
.
IsNull
(
resourceData
);
...
...
@@ -386,7 +446,7 @@ namespace PcapDotNet.Packets.Test
public
void
DnsAddressPrefixAddressFamilyDependentPartTest
()
{
var
dnsAddressPrefix
=
new
DnsAddressPrefix
(
AddressFamily
.
IpV4
,
0
,
false
,
new
DataSegment
(
new
byte
[
127
]));
Assert
.
AreEqual
<
object
>(
dnsAddressPrefix
,
dnsAddressPrefix
);
Assert
.
IsTrue
(
dnsAddressPrefix
.
Equals
((
object
)
dnsAddressPrefix
)
);
}
[
TestMethod
]
...
...
@@ -413,24 +473,24 @@ namespace PcapDotNet.Packets.Test
public
void
DnsGatewayTest
()
{
DnsGateway
gateway
=
new
DnsGatewayIpV6
(
IpV6Address
.
Zero
);
Assert
.
AreEqual
<
object
>(
gateway
,
gateway
);
Assert
.
AreNotEqual
<
object
>(
gateway
,
null
);
Assert
.
IsTrue
(
gateway
.
Equals
((
object
)
gateway
)
);
Assert
.
IsFalse
(
gateway
.
Equals
(
null
as
object
)
);
}
[
TestMethod
]
public
void
DnsOptionTest
()
{
DnsOption
option
=
new
DnsOptionAnything
(
DnsOptionCode
.
UpdateLease
,
DataSegment
.
Empty
);
Assert
.
AreEqual
<
object
>(
option
,
option
);
Assert
.
AreNotEqual
<
object
>(
option
,
null
);
Assert
.
IsTrue
(
option
.
Equals
((
object
)
option
)
);
Assert
.
IsFalse
(
option
.
Equals
(
null
as
object
)
);
}
[
TestMethod
]
public
void
DnsOptionsTest
()
{
DnsOptions
options
=
new
DnsOptions
();
Assert
.
AreEqual
<
object
>(
options
,
options
);
Assert
.
AreNotEqual
<
object
>(
options
,
null
);
Assert
.
IsTrue
(
options
.
Equals
((
object
)
options
)
);
Assert
.
IsFalse
(
options
.
Equals
(
null
as
object
)
);
}
[
TestMethod
]
...
...
@@ -465,5 +525,36 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
uncompressedPacket
.
Length
,
compressedPacket
.
Length
+
expectedCompressionBenefit
,
expectedCompressionBenefit
.
ToString
());
}
private
static
void
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
dnsType
,
DnsResourceData
resourceData
,
int
dataLengthDiff
)
{
var
resourceRecord
=
new
DnsDataResourceRecord
(
DnsDomainName
.
Root
,
dnsType
,
DnsClass
.
In
,
0
,
resourceData
);
var
paddingResourceRecord
=
new
DnsDataResourceRecord
(
DnsDomainName
.
Root
,
DnsType
.
Null
,
DnsClass
.
In
,
0
,
new
DnsResourceDataAnything
(
new
DataSegment
(
new
byte
[
100
])));
Packet
packet
=
PacketBuilder
.
Build
(
DateTime
.
Now
,
new
EthernetLayer
(),
new
IpV4Layer
(),
new
UdpLayer
(),
new
DnsLayer
{
Answers
=
new
List
<
DnsDataResourceRecord
>(
new
[]
{
resourceRecord
,
paddingResourceRecord
}),
});
Assert
.
AreEqual
(
2
,
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
Answers
.
Count
);
Assert
.
AreEqual
(
resourceRecord
,
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
Answers
[
0
]);
Assert
.
AreEqual
(
paddingResourceRecord
,
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
Answers
[
1
]);
byte
[]
buffer
=
new
byte
[
packet
.
Length
];
buffer
.
Write
(
0
,
packet
.
Ethernet
);
const
int
dataLengthOffset
=
EthernetDatagram
.
HeaderLength
+
IpV4Datagram
.
HeaderMinimumLength
+
UdpDatagram
.
HeaderLength
+
DnsDatagram
.
HeaderLength
+
5
+
4
;
ushort
oldDataLength
=
buffer
.
ReadUShort
(
dataLengthOffset
,
Endianity
.
Big
);
ushort
newDataLength
=
(
ushort
)(
oldDataLength
+
dataLengthDiff
);
buffer
.
Write
(
dataLengthOffset
,
newDataLength
,
Endianity
.
Big
);
packet
=
new
Packet
(
buffer
,
DateTime
.
Now
,
DataLinkKind
.
Ethernet
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
Answers
.
Any
());
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Dns/ResourceData/DnsResourceData.cs
View file @
b5224c38
...
...
@@ -10,6 +10,8 @@ namespace PcapDotNet.Packets.Dns
{
public
abstract
class
DnsResourceData
:
IEquatable
<
DnsResourceData
>
{
internal
const
int
StringMinimumLength
=
sizeof
(
byte
);
public
static
Type
GetDnsResourceDataType
(
DnsType
dnsType
)
{
DnsResourceData
prototype
=
TryGetPrototype
(
dnsType
);
...
...
PcapDotNet/src/PcapDotNet.Packets/Dns/ResourceData/DnsResourceDataNamingAuthorityPointer.cs
View file @
b5224c38
...
...
@@ -38,6 +38,7 @@ namespace PcapDotNet.Packets.Dns
}
private
const
int
ConstantPartLength
=
Offset
.
Flags
;
private
const
int
MinimumLength
=
ConstantPartLength
+
StringMinimumLength
+
StringMinimumLength
+
StringMinimumLength
+
DnsDomainName
.
RootLength
;
public
DnsResourceDataNamingAuthorityPointer
(
ushort
order
,
ushort
preference
,
DataSegment
flags
,
DataSegment
services
,
DataSegment
regexp
,
DnsDomainName
replacement
)
{
...
...
@@ -160,7 +161,7 @@ namespace PcapDotNet.Packets.Dns
internal
override
DnsResourceData
CreateInstance
(
DnsDatagram
dns
,
int
offsetInDns
,
int
length
)
{
if
(
length
<
ConstantPart
Length
)
if
(
length
<
Minimum
Length
)
return
null
;
ushort
order
=
dns
.
ReadUShort
(
offsetInDns
+
Offset
.
Order
,
Endianity
.
Big
);
...
...
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