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
ff603078
Commit
ff603078
authored
Sep 19, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Packet validation for TCP and ARP.
Constructor check for IPv4 Basic Security Option. Code Coverage 94.34%.
parent
d9ff3069
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
245 additions
and
7 deletions
+245
-7
ArpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/ArpTests.cs
+2
-0
IpV4Tests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
+168
-4
TcpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/TcpTests.cs
+52
-1
ArpDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Arp/ArpDatagram.cs
+10
-0
IpV4Datagram.cs
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4Datagram.cs
+0
-2
IpV4OptionBasicSecurity.cs
...et/src/PcapDotNet.Packets/IpV4/IpV4OptionBasicSecurity.cs
+8
-0
TcpDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Transport/TcpDatagram.cs
+5
-0
No files found.
PcapDotNet/src/PcapDotNet.Packets.Test/ArpTests.cs
View file @
ff603078
...
@@ -71,6 +71,8 @@ namespace PcapDotNet.Packets.Test
...
@@ -71,6 +71,8 @@ namespace PcapDotNet.Packets.Test
arpSenderHardwareAddress
,
arpSenderProtocolAddress
,
arpSenderHardwareAddress
,
arpSenderProtocolAddress
,
arpTargetHardwareAddress
,
arpTargetProtocolAddress
);
arpTargetHardwareAddress
,
arpTargetProtocolAddress
);
Assert
.
IsTrue
(
packet
.
IsValid
,
"IsValid"
);
// Ethernet
// Ethernet
Assert
.
AreEqual
(
packet
.
Length
-
EthernetDatagram
.
HeaderLength
,
packet
.
Ethernet
.
PayloadLength
,
"PayloadLength"
);
Assert
.
AreEqual
(
packet
.
Length
-
EthernetDatagram
.
HeaderLength
,
packet
.
Ethernet
.
PayloadLength
,
"PayloadLength"
);
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
View file @
ff603078
...
@@ -168,8 +168,9 @@ namespace PcapDotNet.Packets.Test
...
@@ -168,8 +168,9 @@ namespace PcapDotNet.Packets.Test
Assert
.
IsNotNull
(
packet
.
Ethernet
.
IpV4
.
Options
.
ToString
());
Assert
.
IsNotNull
(
packet
.
Ethernet
.
IpV4
.
Options
.
ToString
());
for
(
int
optionIndex
=
0
;
optionIndex
!=
ipV4Options
.
Count
;
++
optionIndex
)
for
(
int
optionIndex
=
0
;
optionIndex
!=
ipV4Options
.
Count
;
++
optionIndex
)
{
{
Assert
.
AreEqual
(
ipV4Options
[
optionIndex
],
packet
.
Ethernet
.
IpV4
.
Options
[
optionIndex
]);
IpV4Option
option
=
ipV4Options
[
optionIndex
];
Assert
.
AreNotEqual
(
null
,
packet
.
Ethernet
.
IpV4
.
Options
[
optionIndex
]);
Assert
.
AreEqual
(
option
,
packet
.
Ethernet
.
IpV4
.
Options
[
optionIndex
]);
Assert
.
IsFalse
(
option
.
Equals
(
null
));
}
}
if
(
packet
.
Ethernet
.
IpV4
.
Protocol
==
IpV4Protocol
.
Tcp
)
if
(
packet
.
Ethernet
.
IpV4
.
Protocol
==
IpV4Protocol
.
Tcp
)
...
@@ -203,6 +204,49 @@ namespace PcapDotNet.Packets.Test
...
@@ -203,6 +204,49 @@ namespace PcapDotNet.Packets.Test
Assert
.
Fail
();
Assert
.
Fail
();
}
}
[
TestMethod
]
public
void
IpV4OptionTimestampFactoryCreateInstanceErrorTest
()
{
Packet
packet
=
PacketBuilder
.
EthernetIpV4
(
DateTime
.
Now
,
new
MacAddress
(),
new
MacAddress
(),
0
,
0
,
new
IpV4Fragmentation
(),
0
,
0
,
new
IpV4Address
(),
new
IpV4Address
(),
new
IpV4Options
(
new
IpV4OptionTimestampOnly
(
0
,
0
)),
Datagram
.
Empty
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
// Bad Length
byte
[]
buffer
=
packet
.
Buffer
;
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
1
]
=
2
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
1
]
=
4
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
1
]
=
5
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
1
]
=
4
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
// Bad Pointer
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
2
]
=
1
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
2
]
=
5
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
2
]
=
6
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
}
[
TestMethod
]
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
IpV4OptionRoutePointedAddressIndexErrorTest
()
public
void
IpV4OptionRoutePointedAddressIndexErrorTest
()
...
@@ -213,6 +257,49 @@ namespace PcapDotNet.Packets.Test
...
@@ -213,6 +257,49 @@ namespace PcapDotNet.Packets.Test
Assert
.
Fail
();
Assert
.
Fail
();
}
}
[
TestMethod
]
public
void
IpV4OptionRouteTryReadErrorTest
()
{
// Small Length
Packet
packet
=
PacketBuilder
.
EthernetIpV4
(
DateTime
.
Now
,
new
MacAddress
(),
new
MacAddress
(),
0
,
0
,
new
IpV4Fragmentation
(),
0
,
0
,
new
IpV4Address
(),
new
IpV4Address
(),
new
IpV4Options
(
new
IpV4OptionLooseSourceRouting
()),
Datagram
.
Empty
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
byte
[]
buffer
=
packet
.
Buffer
;
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
1
]
=
2
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
1
]
=
3
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
// Bad Length
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
1
]
=
4
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
1
]
=
3
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
// Bad Pointer
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
2
]
=
0
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
2
]
=
4
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
2
]
=
5
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
}
[
TestMethod
]
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
IpV4OptionsTooLongErrorTest
()
public
void
IpV4OptionsTooLongErrorTest
()
...
@@ -270,7 +357,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -270,7 +357,7 @@ namespace PcapDotNet.Packets.Test
[
TestMethod
]
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
[
ExpectedException
(
typeof
(
ArgumentOutOfRangeException
))]
public
void
IpV4OptionBasicSecur
tiy
BadLengthTest
()
public
void
IpV4OptionBasicSecur
ityConstructor
BadLengthTest
()
{
{
IpV4OptionBasicSecurity
option
=
new
IpV4OptionBasicSecurity
(
IpV4OptionSecurityClassificationLevel
.
Secret
,
IpV4OptionSecurityProtectionAuthorities
.
None
,
1
);
IpV4OptionBasicSecurity
option
=
new
IpV4OptionBasicSecurity
(
IpV4OptionSecurityClassificationLevel
.
Secret
,
IpV4OptionSecurityProtectionAuthorities
.
None
,
1
);
Assert
.
IsNotNull
(
option
);
Assert
.
IsNotNull
(
option
);
...
@@ -279,13 +366,73 @@ namespace PcapDotNet.Packets.Test
...
@@ -279,13 +366,73 @@ namespace PcapDotNet.Packets.Test
[
TestMethod
]
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
IpV4OptionBasicSecur
tiy
NoProtectionAuthoritiesButWithValueTest
()
public
void
IpV4OptionBasicSecur
ityConstructor
NoProtectionAuthoritiesButWithValueTest
()
{
{
IpV4OptionBasicSecurity
option
=
new
IpV4OptionBasicSecurity
(
IpV4OptionSecurityClassificationLevel
.
Secret
,
IpV4OptionSecurityProtectionAuthorities
.
Nsa
,
3
);
IpV4OptionBasicSecurity
option
=
new
IpV4OptionBasicSecurity
(
IpV4OptionSecurityClassificationLevel
.
Secret
,
IpV4OptionSecurityProtectionAuthorities
.
Nsa
,
3
);
Assert
.
IsNotNull
(
option
);
Assert
.
IsNotNull
(
option
);
Assert
.
Fail
();
Assert
.
Fail
();
}
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
IpV4OptionBasicSecurityConstructorBadClassificationLevelTest
()
{
IpV4OptionBasicSecurity
option
=
new
IpV4OptionBasicSecurity
(
IpV4OptionSecurityClassificationLevel
.
None
);
Assert
.
IsNotNull
(
option
);
Assert
.
Fail
();
}
[
TestMethod
]
public
void
IpV4OptionBasicSecurityCreateInstanceErrorTest
()
{
// Invalid Length
Packet
packet
=
PacketBuilder
.
EthernetIpV4
(
DateTime
.
Now
,
new
MacAddress
(),
new
MacAddress
(),
0
,
0
,
new
IpV4Fragmentation
(),
0
,
0
,
new
IpV4Address
(),
new
IpV4Address
(),
new
IpV4Options
(
new
IpV4OptionBasicSecurity
()),
Datagram
.
Empty
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
byte
[]
buffer
=
packet
.
Buffer
;
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
1
]
=
2
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
// Invalid classification level
packet
=
PacketBuilder
.
EthernetIpV4
(
DateTime
.
Now
,
new
MacAddress
(),
new
MacAddress
(),
0
,
0
,
new
IpV4Fragmentation
(),
0
,
0
,
new
IpV4Address
(),
new
IpV4Address
(),
new
IpV4Options
(
new
IpV4OptionBasicSecurity
(
IpV4OptionSecurityClassificationLevel
.
Secret
)),
Datagram
.
Empty
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
=
packet
.
Buffer
;
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
2
]
=
0
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
// Invalid protection authorities bytes
packet
=
PacketBuilder
.
EthernetIpV4
(
DateTime
.
Now
,
new
MacAddress
(),
new
MacAddress
(),
0
,
0
,
new
IpV4Fragmentation
(),
0
,
0
,
new
IpV4Address
(),
new
IpV4Address
(),
new
IpV4Options
(
new
IpV4OptionBasicSecurity
(
IpV4OptionSecurityClassificationLevel
.
Confidential
,
IpV4OptionSecurityProtectionAuthorities
.
Nsa
,
5
)),
Datagram
.
Empty
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
=
packet
.
Buffer
;
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
3
]
=
0
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
3
]
=
1
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
IpV4Datagram
.
HeaderMinimumLength
+
4
]
=
1
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Options
.
IsValid
);
}
[
TestMethod
]
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
IpV4OptionQuickStartBadFunctionTest
()
public
void
IpV4OptionQuickStartBadFunctionTest
()
...
@@ -338,6 +485,23 @@ namespace PcapDotNet.Packets.Test
...
@@ -338,6 +485,23 @@ namespace PcapDotNet.Packets.Test
Assert
.
IsFalse
(
badPacket
.
IsValid
,
"badPacket.IsValid"
);
Assert
.
IsFalse
(
badPacket
.
IsValid
,
"badPacket.IsValid"
);
}
}
[
TestMethod
]
public
void
IpV4DatagramInvalidHeaderChecksumTest
()
{
Packet
packet
=
PacketBuilder
.
EthernetIpV4
(
DateTime
.
Now
,
new
MacAddress
(),
new
MacAddress
(),
0
,
0
,
new
IpV4Fragmentation
(),
0
,
0
,
IpV4Address
.
Zero
,
IpV4Address
.
Zero
,
IpV4Options
.
None
,
Datagram
.
Empty
);
Assert
.
IsTrue
(
packet
.
IsValid
);
byte
[]
buffer
=
packet
.
Buffer
;
++
buffer
[
packet
.
Length
-
packet
.
Ethernet
.
IpV4
.
Length
+
1
];
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
IsValid
);
}
[
TestMethod
]
[
TestMethod
]
public
void
IpV4BadChecksumTest
()
public
void
IpV4BadChecksumTest
()
{
{
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/TcpTests.cs
View file @
ff603078
using
System
;
using
System
;
using
System.Collections.Generic
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV4
;
...
@@ -115,7 +116,8 @@ namespace PcapDotNet.Packets.Test
...
@@ -115,7 +116,8 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
option
,
option
);
Assert
.
AreEqual
(
option
,
option
);
Assert
.
AreEqual
(
option
.
GetHashCode
(),
option
.
GetHashCode
());
Assert
.
AreEqual
(
option
.
GetHashCode
(),
option
.
GetHashCode
());
Assert
.
IsFalse
(
string
.
IsNullOrEmpty
(
option
.
ToString
()));
Assert
.
IsFalse
(
string
.
IsNullOrEmpty
(
option
.
ToString
()));
Assert
.
IsFalse
(
option
.
Equals
(
null
));
Assert
.
IsFalse
(
option
.
Equals
(
2
));
}
}
Assert
.
AreEqual
(
tcpOptions
,
packet
.
Ethernet
.
IpV4
.
Tcp
.
Options
,
"Options"
);
Assert
.
AreEqual
(
tcpOptions
,
packet
.
Ethernet
.
IpV4
.
Tcp
.
Options
,
"Options"
);
Assert
.
AreEqual
((
tcpControlBits
&
TcpControlBits
.
Acknowledgment
)
==
TcpControlBits
.
Acknowledgment
,
packet
.
Ethernet
.
IpV4
.
Tcp
.
IsAcknowledgment
,
"IsAcknowledgment"
);
Assert
.
AreEqual
((
tcpControlBits
&
TcpControlBits
.
Acknowledgment
)
==
TcpControlBits
.
Acknowledgment
,
packet
.
Ethernet
.
IpV4
.
Tcp
.
IsAcknowledgment
,
"IsAcknowledgment"
);
...
@@ -132,5 +134,54 @@ namespace PcapDotNet.Packets.Test
...
@@ -132,5 +134,54 @@ namespace PcapDotNet.Packets.Test
Assert
.
AreEqual
(
tcpPayload
,
packet
.
Ethernet
.
IpV4
.
Tcp
.
Payload
,
"Payload"
);
Assert
.
AreEqual
(
tcpPayload
,
packet
.
Ethernet
.
IpV4
.
Tcp
.
Payload
,
"Payload"
);
}
}
}
}
[
TestMethod
]
public
void
TcpOptionSelectiveAcknowledgmentBlockTest
()
{
TcpOptionSelectiveAcknowledgmentBlock
block1
=
new
TcpOptionSelectiveAcknowledgmentBlock
();
Assert
.
AreEqual
<
uint
>(
0
,
block1
.
LeftEdge
);
Assert
.
AreEqual
<
uint
>(
0
,
block1
.
RightEdge
);
block1
=
new
TcpOptionSelectiveAcknowledgmentBlock
(
1
,
2
);
Assert
.
AreEqual
<
uint
>(
1
,
block1
.
LeftEdge
);
Assert
.
AreEqual
<
uint
>(
2
,
block1
.
RightEdge
);
TcpOptionSelectiveAcknowledgmentBlock
block2
=
new
TcpOptionSelectiveAcknowledgmentBlock
();
Assert
.
AreNotEqual
(
block1
,
block2
);
Assert
.
IsTrue
(
block1
!=
block2
);
Assert
.
IsFalse
(
block1
==
block2
);
block2
=
new
TcpOptionSelectiveAcknowledgmentBlock
(
1
,
2
);
Assert
.
AreEqual
(
block1
,
block2
);
Assert
.
IsFalse
(
block1
!=
block2
);
Assert
.
IsTrue
(
block1
==
block2
);
}
[
TestMethod
]
[
ExpectedException
(
typeof
(
ArgumentException
))]
public
void
TcpOptionMd5SignatureConstructorErrorDataLengthTest
()
{
new
TcpOptionMd5Signature
(
new
byte
[
10
]);
Assert
.
Fail
();
}
[
TestMethod
]
public
void
TcpOptionMd5SignatureCreateInstanceErrorDataLengthTest
()
{
Packet
packet
=
PacketBuilder
.
EthernetIpV4Tcp
(
DateTime
.
Now
,
new
MacAddress
(),
new
MacAddress
(),
0
,
0
,
new
IpV4Fragmentation
(),
0
,
new
IpV4Address
(),
new
IpV4Address
(),
new
IpV4Options
(),
0
,
0
,
0
,
0
,
new
TcpControlBits
(),
0
,
0
,
new
TcpOptions
(
new
TcpOptionMd5Signature
(
new
byte
[]{
1
,
2
,
3
,
4
,
5
,
6
,
7
,
8
,
9
,
10
,
11
,
12
,
13
,
14
,
15
,
16
})),
Datagram
.
Empty
);
Assert
.
IsTrue
(
packet
.
IsValid
);
Assert
.
IsTrue
(
packet
.
Ethernet
.
IpV4
.
Tcp
.
Options
.
IsValid
);
byte
[]
buffer
=
packet
.
Buffer
;
buffer
[
buffer
.
Length
-
packet
.
Ethernet
.
IpV4
.
Tcp
.
Length
+
TcpDatagram
.
HeaderMinimumLength
+
1
]
=
2
;
packet
=
new
Packet
(
buffer
,
packet
.
Timestamp
,
packet
.
DataLink
);
Assert
.
IsFalse
(
packet
.
Ethernet
.
IpV4
.
Tcp
.
Options
.
IsValid
);
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/Arp/ArpDatagram.cs
View file @
ff603078
...
@@ -44,6 +44,11 @@ namespace PcapDotNet.Packets.Arp
...
@@ -44,6 +44,11 @@ namespace PcapDotNet.Packets.Arp
public
const
int
HeaderBaseLength
=
8
;
public
const
int
HeaderBaseLength
=
8
;
public
int
HeaderLength
{
get
{
return
GetHeaderLength
(
HardwareLength
,
ProtocolLength
);
}
}
/// <summary>
/// <summary>
/// Each data link layer protocol is assigned a number used in this field.
/// Each data link layer protocol is assigned a number used in this field.
/// </summary>
/// </summary>
...
@@ -117,6 +122,11 @@ namespace PcapDotNet.Packets.Arp
...
@@ -117,6 +122,11 @@ namespace PcapDotNet.Packets.Arp
get
{
return
ReadBytes
(
OffsetTargetProtocolAddress
,
ProtocolLength
);
}
get
{
return
ReadBytes
(
OffsetTargetProtocolAddress
,
ProtocolLength
);
}
}
}
protected
override
bool
CalculateIsValid
()
{
return
Length
>=
HeaderBaseLength
&&
Length
==
HeaderLength
;
}
internal
ArpDatagram
(
byte
[]
buffer
,
int
offset
,
int
length
)
internal
ArpDatagram
(
byte
[]
buffer
,
int
offset
,
int
length
)
:
base
(
buffer
,
offset
,
length
)
:
base
(
buffer
,
offset
,
length
)
{
{
...
...
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4Datagram.cs
View file @
ff603078
...
@@ -329,8 +329,6 @@ namespace PcapDotNet.Packets.IpV4
...
@@ -329,8 +329,6 @@ namespace PcapDotNet.Packets.IpV4
switch
(
Protocol
)
switch
(
Protocol
)
{
{
// case IpV4Protocol.Tcp:
// return Tcp.IsValid; //&& IsTransportChecksumCorrect;
case
IpV4Protocol
.
Tcp
:
case
IpV4Protocol
.
Tcp
:
case
IpV4Protocol
.
Udp
:
case
IpV4Protocol
.
Udp
:
return
Transport
.
IsValid
&&
(
Transport
.
IsChecksumOptional
&&
Transport
.
Checksum
==
0
||
return
Transport
.
IsValid
&&
(
Transport
.
IsChecksumOptional
&&
Transport
.
Checksum
==
0
||
...
...
PcapDotNet/src/PcapDotNet.Packets/IpV4/IpV4OptionBasicSecurity.cs
View file @
ff603078
...
@@ -79,6 +79,14 @@ namespace PcapDotNet.Packets.IpV4
...
@@ -79,6 +79,14 @@ namespace PcapDotNet.Packets.IpV4
"protectionAuthorities"
);
"protectionAuthorities"
);
}
}
if
(
classificationLevel
!=
IpV4OptionSecurityClassificationLevel
.
Confidential
&&
classificationLevel
!=
IpV4OptionSecurityClassificationLevel
.
Secret
&&
classificationLevel
!=
IpV4OptionSecurityClassificationLevel
.
TopSecret
&&
classificationLevel
!=
IpV4OptionSecurityClassificationLevel
.
Unclassified
)
{
throw
new
ArgumentException
(
"Invalid classification level "
+
classificationLevel
);
}
_classificationLevel
=
classificationLevel
;
_classificationLevel
=
classificationLevel
;
_protectionAuthorities
=
protectionAuthorities
;
_protectionAuthorities
=
protectionAuthorities
;
_length
=
length
;
_length
=
length
;
...
...
PcapDotNet/src/PcapDotNet.Packets/Transport/TcpDatagram.cs
View file @
ff603078
...
@@ -230,6 +230,11 @@ namespace PcapDotNet.Packets.Transport
...
@@ -230,6 +230,11 @@ namespace PcapDotNet.Packets.Transport
get
{
return
(
ControlBits
&
TcpControlBits
.
Fin
)
==
TcpControlBits
.
Fin
;
}
get
{
return
(
ControlBits
&
TcpControlBits
.
Fin
)
==
TcpControlBits
.
Fin
;
}
}
}
protected
override
bool
CalculateIsValid
()
{
return
Length
>=
HeaderMinimumLength
&&
Length
>=
HeaderLength
&&
Options
.
IsValid
;
}
internal
TcpDatagram
(
byte
[]
buffer
,
int
offset
,
int
length
)
internal
TcpDatagram
(
byte
[]
buffer
,
int
offset
,
int
length
)
:
base
(
buffer
,
offset
,
length
)
:
base
(
buffer
,
offset
,
length
)
{
{
...
...
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