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
16498b62
Commit
16498b62
authored
Jan 27, 2012
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
DNS
Code coverage 93.95%
parent
a31b8194
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
257 additions
and
4 deletions
+257
-4
DnsTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/DnsTests.cs
+243
-0
DnsDataResourceRecord.cs
...otNet/src/PcapDotNet.Packets/Dns/DnsDataResourceRecord.cs
+1
-1
DnsDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsDatagram.cs
+10
-0
DnsResourceDataHostIdentityProtocol.cs
...s/Dns/ResourceData/DnsResourceDataHostIdentityProtocol.cs
+1
-1
DnsResourceDataTransactionKey.cs
...Packets/Dns/ResourceData/DnsResourceDataTransactionKey.cs
+1
-1
DnsTypeBitmaps.cs
...src/PcapDotNet.Packets/Dns/ResourceData/DnsTypeBitmaps.cs
+1
-1
No files found.
PcapDotNet/src/PcapDotNet.Packets.Test/DnsTests.cs
View file @
16498b62
...
...
@@ -8,6 +8,7 @@ using PcapDotNet.Packets.Arp;
using
PcapDotNet.Packets.Dns
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV6
;
using
PcapDotNet.Packets.TestUtils
;
using
PcapDotNet.Packets.Transport
;
using
PcapDotNet.TestUtils
;
...
...
@@ -80,6 +81,23 @@ namespace PcapDotNet.Packets.Test
// DNS
DnsLayer
actualLayer
=
(
DnsLayer
)
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
ExtractLayer
();
Assert
.
AreEqual
(
dnsLayer
,
actualLayer
,
"DNS Layer"
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
IsValid
);
DnsDataResourceRecord
opt
=
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
Additionals
.
FirstOrDefault
(
additional
=>
additional
.
Type
==
DnsType
.
Opt
);
Assert
.
AreEqual
(
opt
,
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
OptionsRecord
);
foreach
(
var
record
in
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
ResourceRecords
)
{
Assert
.
AreEqual
<
object
>(
record
,
record
);
Assert
.
AreEqual
<
object
>(
record
.
DomainName
,
record
.
DomainName
);
}
foreach
(
var
record
in
packet
.
Ethernet
.
IpV4
.
Udp
.
Dns
.
DataResourceRecords
)
{
MoreAssert
.
IsBiggerOrEqual
(
9
,
record
.
ToString
().
Length
);
Assert
.
AreEqual
<
object
>(
record
,
record
);
Assert
.
IsInstanceOfType
(
record
.
Data
,
DnsResourceData
.
GetDnsResourceDataType
(
record
.
Type
)
??
typeof
(
DnsResourceDataAnything
));
}
}
}
...
...
@@ -169,6 +187,24 @@ namespace PcapDotNet.Packets.Test
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
DnsQueryResourceRecordTtlGetTest
()
{
var
query
=
new
DnsQueryResourceRecord
(
DnsDomainName
.
Root
,
DnsType
.
A
,
DnsClass
.
In
);
Assert
.
IsNull
(
query
.
Ttl
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
InvalidOperationException
))]
public
void
DnsQueryResourceRecordDataGetTest
()
{
var
query
=
new
DnsQueryResourceRecord
(
DnsDomainName
.
Root
,
DnsType
.
A
,
DnsClass
.
In
);
Assert
.
IsNull
(
query
.
Data
);
Assert
.
Fail
();
}
[
TestMethod
]
public
void
DnsResourceDataNextDomainTest
()
{
...
...
@@ -178,6 +214,18 @@ namespace PcapDotNet.Packets.Test
Assert
.
IsTrue
(
resourceData
.
IsTypePresentForOwner
(
DnsType
.
A
));
Assert
.
IsTrue
(
resourceData
.
IsTypePresentForOwner
(
DnsType
.
Aaaa
));
Assert
.
IsFalse
(
resourceData
.
IsTypePresentForOwner
(
DnsType
.
Ns
));
bitMap
=
DnsResourceDataNextDomain
.
CreateTypeBitMap
(
new
DnsType
[]
{
0
});
Assert
.
AreEqual
(
DataSegment
.
Empty
,
bitMap
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataNextDomainTooBigDnsType
()
{
DnsResourceDataNextDomain
resourceData
=
new
DnsResourceDataNextDomain
(
new
DnsDomainName
(
"a.b.c"
),
DataSegment
.
Empty
);
Assert
.
IsNull
(
resourceData
.
IsTypePresentForOwner
((
DnsType
)(
8
*
16
+
1
)));
Assert
.
Fail
();
}
[
TestMethod
]
...
...
@@ -200,6 +248,201 @@ namespace PcapDotNet.Packets.Test
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
DnsResourceDataNamingAuthorityPointerIllegalFlagsTest
()
{
var
resourceData
=
new
DnsResourceDataNamingAuthorityPointer
(
0
,
0
,
new
DataSegment
(
new
byte
[]
{(
byte
)
'%'
}),
DataSegment
.
Empty
,
DataSegment
.
Empty
,
DnsDomainName
.
Root
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataTransactionKeyTooBigKeyTest
()
{
var
resourceData
=
new
DnsResourceDataTransactionKey
(
DnsDomainName
.
Root
,
0
,
0
,
DnsTransactionKeyMode
.
KeyDeletion
,
DnsResponseCode
.
NoError
,
new
DataSegment
(
new
byte
[
ushort
.
MaxValue
+
1
]),
DataSegment
.
Empty
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataTransactionKeyTooBigOtherTest
()
{
var
resourceData
=
new
DnsResourceDataTransactionKey
(
DnsDomainName
.
Root
,
0
,
0
,
DnsTransactionKeyMode
.
KeyDeletion
,
DnsResponseCode
.
NoError
,
DataSegment
.
Empty
,
new
DataSegment
(
new
byte
[
ushort
.
MaxValue
+
1
]));
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataTransactionSignatureTooBigMessageAuthenticationCodeTest
()
{
var
resourceData
=
new
DnsResourceDataTransactionSignature
(
DnsDomainName
.
Root
,
0
,
0
,
new
DataSegment
(
new
byte
[
ushort
.
MaxValue
+
1
]),
0
,
DnsResponseCode
.
NoError
,
DataSegment
.
Empty
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataTransactionSignatureTooBigOtherTest
()
{
var
resourceData
=
new
DnsResourceDataTransactionSignature
(
DnsDomainName
.
Root
,
0
,
0
,
DataSegment
.
Empty
,
0
,
DnsResponseCode
.
NoError
,
new
DataSegment
(
new
byte
[
ushort
.
MaxValue
+
1
]));
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataHostIdentityProtocolTooBigHostIdentityTagTest
()
{
var
resourceData
=
new
DnsResourceDataHostIdentityProtocol
(
new
DataSegment
(
new
byte
[
byte
.
MaxValue
+
1
]),
DnsPublicKeyAlgorithm
.
None
,
DataSegment
.
Empty
,
new
DnsDomainName
[
0
]);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataHostIdentityProtocolTooBigPublicKeyTest
()
{
var
resourceData
=
new
DnsResourceDataHostIdentityProtocol
(
DataSegment
.
Empty
,
DnsPublicKeyAlgorithm
.
None
,
new
DataSegment
(
new
byte
[
ushort
.
MaxValue
+
1
]),
new
DnsDomainName
[
0
]);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataLocationInformationInvalidSizeTest
()
{
var
resourceData
=
new
DnsResourceDataLocationInformation
(
0
,
9000000001L
,
0
,
0
,
0
,
0
,
0
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataLocationInformationInvalidHorizontalPrecisionTest
()
{
var
resourceData
=
new
DnsResourceDataLocationInformation
(
0
,
0
,
9000000001L
,
0
,
0
,
0
,
0
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataLocationInformationInvalidVerticalPrecisionTest
()
{
var
resourceData
=
new
DnsResourceDataLocationInformation
(
0
,
0
,
0
,
9000000001L
,
0
,
0
,
0
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
public
void
DnsResourceDataNextDomainSecureTest
()
{
var
types
=
new
[]
{
DnsType
.
A
,
DnsType
.
Aaaa
,
DnsType
.
A6
,
DnsType
.
Any
,
DnsType
.
NaPtr
};
var
resourceData
=
new
DnsResourceDataNextDomainSecure
(
DnsDomainName
.
Root
,
types
);
foreach
(
var
type
in
Enum
.
GetValues
(
typeof
(
DnsType
)))
{
Assert
.
AreEqual
(
types
.
Contains
((
DnsType
)
type
),
resourceData
.
IsTypePresentForOwner
((
DnsType
)
type
));
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataNetworkServiceAccessPointAreaAddressTooSmallTest
()
{
var
resourceData
=
new
DnsResourceDataNetworkServiceAccessPoint
(
DataSegment
.
Empty
,
0
,
0
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
public
void
DnsResourceDataNetworkServiceAccessPointTest
()
{
var
resourceData
=
new
DnsResourceDataNetworkServiceAccessPoint
(
new
DataSegment
(
new
byte
[]{
1
,
2
,
3
,
4
,
5
}),
0
,
0
);
Assert
.
AreEqual
(
1
,
resourceData
.
AuthorityAndFormatIdentifier
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsAddressPrefixAddressFamilyDependentPartTooBigTest
()
{
var
dnsAddressPrefix
=
new
DnsAddressPrefix
(
AddressFamily
.
IpV4
,
0
,
false
,
new
DataSegment
(
new
byte
[
128
]));
Assert
.
IsNull
(
dnsAddressPrefix
);
Assert
.
Fail
();
}
[
TestMethod
]
public
void
DnsAddressPrefixAddressFamilyDependentPartTest
()
{
var
dnsAddressPrefix
=
new
DnsAddressPrefix
(
AddressFamily
.
IpV4
,
0
,
false
,
new
DataSegment
(
new
byte
[
127
]));
Assert
.
AreEqual
<
object
>(
dnsAddressPrefix
,
dnsAddressPrefix
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataNextDomainSecure3NextHashedOwnerNameTooBigTest
()
{
var
resourceData
=
new
DnsResourceDataNextDomainSecure3
(
DnsSecNSec3HashAlgorithm
.
Sha1
,
DnsSecNSec3Flags
.
None
,
0
,
DataSegment
.
Empty
,
new
DataSegment
(
new
byte
[
byte
.
MaxValue
+
1
]),
new
DnsType
[
0
]);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataNextDomainSecure3SaltTooBigTest
()
{
var
resourceData
=
new
DnsResourceDataNextDomainSecure3
(
DnsSecNSec3HashAlgorithm
.
Sha1
,
DnsSecNSec3Flags
.
None
,
0
,
new
DataSegment
(
new
byte
[
byte
.
MaxValue
+
1
]),
DataSegment
.
Empty
,
new
DnsType
[
0
]);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
[
TestMethod
]
public
void
DnsGatewayTest
()
{
DnsGateway
gateway
=
new
DnsGatewayIpV6
(
IpV6Address
.
Zero
);
Assert
.
AreEqual
<
object
>(
gateway
,
gateway
);
Assert
.
AreNotEqual
<
object
>(
gateway
,
null
);
}
[
TestMethod
]
public
void
DnsOptionTest
()
{
DnsOption
option
=
new
DnsOptionAnything
(
DnsOptionCode
.
UpdateLease
,
DataSegment
.
Empty
);
Assert
.
AreEqual
<
object
>(
option
,
option
);
Assert
.
AreNotEqual
<
object
>(
option
,
null
);
}
[
TestMethod
]
public
void
DnsOptionsTest
()
{
DnsOptions
options
=
new
DnsOptions
();
Assert
.
AreEqual
<
object
>(
options
,
options
);
Assert
.
AreNotEqual
<
object
>(
options
,
null
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
DnsResourceDataCertificationAuthorityAuthorizationTagTooBigTest
()
{
var
resourceData
=
new
DnsResourceDataCertificationAuthorityAuthorization
(
DnsCertificationAuthorityAuthorizationFlags
.
Critical
,
new
DataSegment
(
new
byte
[
byte
.
MaxValue
+
1
]),
DataSegment
.
Empty
);
Assert
.
IsNull
(
resourceData
);
Assert
.
Fail
();
}
private
static
void
TestDomainNameCompression
(
int
expectedCompressionBenefit
,
DnsLayer
dnsLayer
)
{
dnsLayer
.
DomainNameCompressionMode
=
DnsDomainNameCompressionMode
.
Nothing
;
...
...
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsDataResourceRecord.cs
View file @
16498b62
...
...
@@ -47,7 +47,7 @@ namespace PcapDotNet.Packets.Dns
Data
.
Equals
(
other
.
Data
);
}
public
override
bool
Equals
(
object
obj
)
public
override
bool
Equals
(
object
obj
)
{
return
Equals
(
obj
as
DnsDataResourceRecord
);
}
...
...
PcapDotNet/src/PcapDotNet.Packets/Dns/DnsDatagram.cs
View file @
16498b62
...
...
@@ -291,6 +291,16 @@ namespace PcapDotNet.Packets.Dns
}
}
public
IEnumerable
<
DnsResourceRecord
>
ResourceRecords
{
get
{
return
Queries
.
Cast
<
DnsResourceRecord
>().
Concat
(
DataResourceRecords
);
}
}
public
IEnumerable
<
DnsDataResourceRecord
>
DataResourceRecords
{
get
{
return
Answers
.
Concat
(
Authorities
).
Concat
(
Additionals
);
}
}
public
DnsOptResourceRecord
OptionsRecord
{
get
...
...
PcapDotNet/src/PcapDotNet.Packets/Dns/ResourceData/DnsResourceDataHostIdentityProtocol.cs
View file @
16498b62
...
...
@@ -43,7 +43,7 @@ namespace PcapDotNet.Packets.Dns
{
if
(
hostIdentityTag
.
Length
>
byte
.
MaxValue
)
throw
new
ArgumentOutOfRangeException
(
"hostIdentityTag"
,
hostIdentityTag
.
Length
,
string
.
Format
(
"Cannot be bigger than {0}."
,
byte
.
MaxValue
));
if
(
hostIdentityTag
.
Length
>
ushort
.
MaxValue
)
if
(
publicKey
.
Length
>
ushort
.
MaxValue
)
throw
new
ArgumentOutOfRangeException
(
"publicKey"
,
publicKey
.
Length
,
string
.
Format
(
"Cannot be bigger than {0}."
,
ushort
.
MaxValue
));
HostIdentityTag
=
hostIdentityTag
;
PublicKeyAlgorithm
=
publicKeyAlgorithm
;
...
...
PcapDotNet/src/PcapDotNet.Packets/Dns/ResourceData/DnsResourceDataTransactionKey.cs
View file @
16498b62
...
...
@@ -127,7 +127,7 @@ namespace PcapDotNet.Packets.Dns
Other
.
Equals
(
other
.
Other
);
}
public
override
bool
Equals
(
DnsResourceData
other
)
public
override
bool
Equals
(
DnsResourceData
other
)
{
return
Equals
(
other
as
DnsResourceDataTransactionKey
);
}
...
...
PcapDotNet/src/PcapDotNet.Packets/Dns/ResourceData/DnsTypeBitmaps.cs
View file @
16498b62
...
...
@@ -30,7 +30,7 @@ namespace PcapDotNet.Packets.Dns
TypesExist
.
SequenceEqual
(
other
.
TypesExist
);
}
public
override
bool
Equals
(
object
obj
)
public
override
bool
Equals
(
object
obj
)
{
return
Equals
(
obj
as
DnsTypeBitmaps
);
}
...
...
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