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
74bbb693
Commit
74bbb693
authored
Mar 24, 2012
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Code coverage 94.34%
parent
90666599
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
136 additions
and
9 deletions
+136
-9
PacketDumpFileTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PacketDumpFileTests.cs
+1
-1
DnsTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/DnsTests.cs
+130
-2
DnsResourceDataA6.cs
.../PcapDotNet.Packets/Dns/ResourceData/DnsResourceDataA6.cs
+5
-5
DnsResourceDataHostIdentityProtocol.cs
...s/Dns/ResourceData/DnsResourceDataHostIdentityProtocol.cs
+0
-1
No files found.
PcapDotNet/src/PcapDotNet.Core.Test/PacketDumpFileTests.cs
View file @
74bbb693
...
...
@@ -67,7 +67,7 @@ namespace PcapDotNet.Core.Test
PacketCommunicatorReceiveResult
result
=
communicator
.
ReceivePacket
(
out
actualPacket
);
Assert
.
AreEqual
(
PacketCommunicatorReceiveResult
.
Ok
,
result
);
Assert
.
AreEqual
(
expectedPacket
,
actualPacket
);
MoreAssert
.
IsInRange
(
expectedPacket
.
Timestamp
.
AddMicroseconds
(-
1
),
expectedPacket
.
Timestamp
.
AddMicroseconds
(
1
),
actualPacket
.
Timestamp
);
MoreAssert
.
IsInRange
(
expectedPacket
.
Timestamp
.
AddMicroseconds
(-
2
),
expectedPacket
.
Timestamp
.
AddMicroseconds
(
1
),
actualPacket
.
Timestamp
);
}
}
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/DnsTests.cs
View file @
74bbb693
...
...
@@ -3,8 +3,6 @@ using System.Collections.Generic;
using
System.Linq
;
using
System.Text
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Base
;
using
PcapDotNet.Packets.Arp
;
using
PcapDotNet.Packets.Dns
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.IpV4
;
...
...
@@ -91,6 +89,7 @@ namespace PcapDotNet.Packets.Test
Assert
.
IsTrue
(
record
.
Equals
(
record
));
Assert
.
IsTrue
(
record
.
DomainName
.
Equals
((
object
)
record
.
DomainName
));
Assert
.
IsTrue
(
record
.
DomainName
.
Equals
((
object
)
record
.
DomainName
));
Assert
.
AreEqual
(
record
.
GetHashCode
(),
record
.
GetHashCode
());
}
foreach
(
var
record
in
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
DataResourceRecords
)
...
...
@@ -186,6 +185,15 @@ namespace PcapDotNet.Packets.Test
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentNullException
))]
public
void
DnsDomainNameConstructorNullStringTest
()
{
DnsDomainName
domainName
=
new
DnsDomainName
(
null
);
Assert
.
IsNotNull
(
domainName
);
Assert
.
Fail
();
}
[
TestMethod
]
public
void
DnsOptResourceRecordTest
()
{
...
...
@@ -319,6 +327,26 @@ namespace PcapDotNet.Packets.Test
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentNullException
))]
public
void
DnsResourceDataTransactionKeyConstructorNullKeyTest
()
{
var
resourceData
=
new
DnsResourceDataTransactionKey
(
DnsDomainName
.
Root
,
0
,
0
,
DnsTransactionKeyMode
.
KeyDeletion
,
DnsResponseCode
.
NoError
,
null
,
DataSegment
.
Empty
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentNullException
))]
public
void
DnsResourceDataTransactionKeyConstructorNullOtherTest
()
{
var
resourceData
=
new
DnsResourceDataTransactionKey
(
DnsDomainName
.
Root
,
0
,
0
,
DnsTransactionKeyMode
.
KeyDeletion
,
DnsResponseCode
.
NoError
,
DataSegment
.
Empty
,
null
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataTransactionKeyTooBigKeyTest
()
...
...
@@ -339,6 +367,35 @@ namespace PcapDotNet.Packets.Test
Assert
.
Fail
();
}
[
TestMethod
]
public
void
DnsResourceDataTransactionKeyParseTooShortTest
()
{
var
resourceData
=
new
DnsResourceDataTransactionKey
(
new
DnsDomainName
(
"pcapdot.net"
),
0
,
0
,
DnsTransactionKeyMode
.
KeyDeletion
,
DnsResponseCode
.
NoError
,
new
DataSegment
(
new
byte
[
5
]),
new
DataSegment
(
new
byte
[
5
]));
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
TKey
,
resourceData
,
-
1
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
TKey
,
resourceData
,
-
6
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
TKey
,
resourceData
,
-
11
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
TKey
,
resourceData
,
-
23
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentNullException
))]
public
void
DnsResourceDataTransactionSignatureConstructorNullMessageAuthenticationCodeTest
()
{
var
resourceData
=
new
DnsResourceDataTransactionSignature
(
DnsDomainName
.
Root
,
0
,
0
,
null
,
0
,
DnsResponseCode
.
NoError
,
DataSegment
.
Empty
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentNullException
))]
public
void
DnsResourceDataTransactionSignatureConstructorNullOtherTest
()
{
var
resourceData
=
new
DnsResourceDataTransactionSignature
(
DnsDomainName
.
Root
,
0
,
0
,
DataSegment
.
Empty
,
0
,
DnsResponseCode
.
NoError
,
null
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataTransactionSignatureTooBigMessageAuthenticationCodeTest
()
...
...
@@ -359,6 +416,17 @@ namespace PcapDotNet.Packets.Test
Assert
.
Fail
();
}
[
TestMethod
]
public
void
DnsResourceDataTransactionSignatureParseWrongSizeTest
()
{
var
resourceData
=
new
DnsResourceDataTransactionSignature
(
new
DnsDomainName
(
"pcapdot.net"
),
0
,
0
,
new
DataSegment
(
new
byte
[
5
]),
0
,
DnsResponseCode
.
NoError
,
new
DataSegment
(
new
byte
[
5
]));
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
TransactionSignature
,
resourceData
,
1
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
TransactionSignature
,
resourceData
,
-
6
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
TransactionSignature
,
resourceData
,
-
11
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
TransactionSignature
,
resourceData
,
-
23
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataHostIdentityProtocolTooBigHostIdentityTagTest
()
...
...
@@ -379,6 +447,38 @@ namespace PcapDotNet.Packets.Test
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentNullException
))]
public
void
DnsResourceDataHostIdentityProtocolConstructorNullHostIdentityTagTest
()
{
var
resourceData
=
new
DnsResourceDataHostIdentityProtocol
(
null
,
DnsPublicKeyAlgorithm
.
None
,
DataSegment
.
Empty
,
new
DnsDomainName
[
0
]);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentNullException
))]
public
void
DnsResourceDataHostIdentityProtocolConstructorNullPublicKeyTest
()
{
var
resourceData
=
new
DnsResourceDataHostIdentityProtocol
(
DataSegment
.
Empty
,
DnsPublicKeyAlgorithm
.
None
,
null
,
new
DnsDomainName
[
0
]);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
public
void
DnsResourceDataHostIdentityProtocolParseWrongLengthTest
()
{
var
resourceData
=
new
DnsResourceDataHostIdentityProtocol
(
new
DataSegment
(
new
byte
[
5
]),
DnsPublicKeyAlgorithm
.
None
,
new
DataSegment
(
new
byte
[
5
]),
new
[]
{
new
DnsDomainName
(
"pcapdot.net"
),
new
DnsDomainName
(
"pcapdotnet.codeplex.com"
)
});
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
Hip
,
resourceData
,
-
1
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
Hip
,
resourceData
,
-
39
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
Hip
,
resourceData
,
-
49
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataLocationInformationInvalidSizeTest
()
...
...
@@ -509,6 +609,34 @@ namespace PcapDotNet.Packets.Test
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataA6ConstructorAddressSuffixTooSmallTest
()
{
var
resourceData
=
new
DnsResourceDataA6
(
127
,
IpV6Address
.
Zero
,
DnsDomainName
.
Root
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataA6ConstructorAddressSuffixTooBigTest
()
{
var
resourceData
=
new
DnsResourceDataA6
(
1
,
IpV6Address
.
MaxValue
,
DnsDomainName
.
Root
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
public
void
DnsResourceDataA6ParseToShortTest
()
{
var
resourceData
=
new
DnsResourceDataA6
(
100
,
new
IpV6Address
(
"::F12:3456"
),
new
DnsDomainName
(
"pcapdot.net"
));
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
A6
,
resourceData
,
1
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
A6
,
resourceData
,
-
1
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
A6
,
resourceData
,
-
14
);
TestResourceRecordIsNotCreatedWithNewLength
(
DnsType
.
A6
,
resourceData
,
-
17
);
}
private
static
void
TestDomainNameCompression
(
int
expectedCompressionBenefit
,
DnsLayer
dnsLayer
)
{
dnsLayer
.
DomainNameCompressionMode
=
DnsDomainNameCompressionMode
.
Nothing
;
...
...
PcapDotNet/src/PcapDotNet.Packets/Dns/ResourceData/DnsResourceDataA6.cs
View file @
74bbb693
...
...
@@ -44,10 +44,10 @@ namespace PcapDotNet.Packets.Dns
/// <param name="prefixName">The name of the prefix, encoded as a domain name. This name must not be compressed. </param>
public
DnsResourceDataA6
(
byte
prefixLength
,
IpV6Address
addressSuffix
,
DnsDomainName
prefixName
)
{
if
(
IsAddressSuffixToo
Big
(
prefixLength
,
addressSuffix
))
if
(
IsAddressSuffixToo
Small
(
prefixLength
,
addressSuffix
))
throw
new
ArgumentOutOfRangeException
(
"addressSuffix"
,
string
.
Format
(
CultureInfo
.
InvariantCulture
,
"Value is too small for prefix length {0}"
,
prefixLength
));
if
(
IsAddressSuffixToo
Small
(
prefixLength
,
addressSuffix
))
if
(
IsAddressSuffixToo
Big
(
prefixLength
,
addressSuffix
))
throw
new
ArgumentOutOfRangeException
(
"addressSuffix"
,
string
.
Format
(
CultureInfo
.
InvariantCulture
,
"Value is too big for prefix length {0}"
,
prefixLength
));
...
...
@@ -144,7 +144,7 @@ namespace PcapDotNet.Packets.Dns
offsetInDns
+=
addressSuffixLength
;
length
-=
addressSuffixLength
;
if
(
IsAddressSuffixToo
Big
(
prefixLength
,
addressSuffix
)
||
IsAddressSuffixTooSmall
(
prefixLength
,
addressSuffix
))
if
(
IsAddressSuffixToo
Small
(
prefixLength
,
addressSuffix
)
||
IsAddressSuffixTooBig
(
prefixLength
,
addressSuffix
))
return
null
;
DnsDomainName
prefixName
;
...
...
@@ -157,12 +157,12 @@ namespace PcapDotNet.Packets.Dns
return
new
DnsResourceDataA6
(
prefixLength
,
addressSuffix
,
prefixName
);
}
private
static
bool
IsAddressSuffixToo
Big
(
byte
prefixLength
,
IpV6Address
addressSuffix
)
private
static
bool
IsAddressSuffixToo
Small
(
byte
prefixLength
,
IpV6Address
addressSuffix
)
{
return
(
prefixLength
<
128
&&
(
addressSuffix
.
ToValue
()
<
(
UInt128
.
One
<<
(
127
-
prefixLength
))));
}
private
static
bool
IsAddressSuffixToo
Small
(
byte
prefixLength
,
IpV6Address
addressSuffix
)
private
static
bool
IsAddressSuffixToo
Big
(
byte
prefixLength
,
IpV6Address
addressSuffix
)
{
return
(
prefixLength
>
0
&&
(
addressSuffix
.
ToValue
()
>=
(
UInt128
.
One
<<
(
128
-
prefixLength
))));
}
...
...
PcapDotNet/src/PcapDotNet.Packets/Dns/ResourceData/DnsResourceDataHostIdentityProtocol.cs
View file @
74bbb693
...
...
@@ -184,7 +184,6 @@ namespace PcapDotNet.Packets.Dns
rendezvousServers
.
Add
(
rendezvousServer
);
offsetInDns
+=
rendezvousServerLength
;
length
-=
rendezvousServerLength
;
}
return
new
DnsResourceDataHostIdentityProtocol
(
hostIdentityTag
,
publicKeyAlgorithm
,
publicKey
,
rendezvousServers
);
...
...
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