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
caa669f1
Commit
caa669f1
authored
Apr 24, 2010
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
GRE
parent
e3457d59
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
251 additions
and
100 deletions
+251
-100
WiresharkCompareTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
+114
-18
XElementExtensions.cs
PcapDotNet/src/PcapDotNet.Core.Test/XElementExtensions.cs
+58
-38
GreTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/GreTests.cs
+4
-4
GreDatagram.cs
PcapDotNet/src/PcapDotNet.Packets/Gre/GreDatagram.cs
+44
-38
BoolExtensions.cs
PcapDotNet/src/PcapDotNet.TestUtils/BoolExtensions.cs
+10
-0
ByteExtensions.cs
PcapDotNet/src/PcapDotNet.TestUtils/ByteExtensions.cs
+17
-0
PcapDotNet.TestUtils.csproj
...tNet/src/PcapDotNet.TestUtils/PcapDotNet.TestUtils.csproj
+3
-1
RandomExtensions.cs
PcapDotNet/src/PcapDotNet.TestUtils/RandomExtensions.cs
+1
-1
No files found.
PcapDotNet/src/PcapDotNet.Core.Test/WiresharkCompareTests.cs
View file @
caa669f1
...
@@ -13,6 +13,7 @@ using PcapDotNet.Base;
...
@@ -13,6 +13,7 @@ using PcapDotNet.Base;
using
PcapDotNet.Packets
;
using
PcapDotNet.Packets
;
using
PcapDotNet.Packets.Arp
;
using
PcapDotNet.Packets.Arp
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.Ethernet
;
using
PcapDotNet.Packets.Gre
;
using
PcapDotNet.Packets.Icmp
;
using
PcapDotNet.Packets.Icmp
;
using
PcapDotNet.Packets.Igmp
;
using
PcapDotNet.Packets.Igmp
;
using
PcapDotNet.Packets.IpV4
;
using
PcapDotNet.Packets.IpV4
;
...
@@ -99,8 +100,9 @@ namespace PcapDotNet.Core.Test
...
@@ -99,8 +100,9 @@ namespace PcapDotNet.Core.Test
IpV4
,
IpV4
,
Igmp
,
Igmp
,
Icmp
,
Icmp
,
Gre
,
Udp
,
Udp
,
Tcp
Tcp
,
}
}
private
static
Packet
CreateRandomPacket
(
Random
random
)
private
static
Packet
CreateRandomPacket
(
Random
random
)
...
@@ -136,6 +138,13 @@ namespace PcapDotNet.Core.Test
...
@@ -136,6 +138,13 @@ namespace PcapDotNet.Core.Test
IEnumerable
<
ILayer
>
icmpPayloadLayers
=
random
.
NextIcmpPayloadLayers
(
icmpLayer
);
IEnumerable
<
ILayer
>
icmpPayloadLayers
=
random
.
NextIcmpPayloadLayers
(
icmpLayer
);
return
PacketBuilder
.
Build
(
packetTimestamp
,
new
ILayer
[]{
ethernetLayer
,
ipV4Layer
,
icmpLayer
}.
Concat
(
icmpPayloadLayers
));
return
PacketBuilder
.
Build
(
packetTimestamp
,
new
ILayer
[]{
ethernetLayer
,
ipV4Layer
,
icmpLayer
}.
Concat
(
icmpPayloadLayers
));
case
PacketType
.
Gre
:
ethernetLayer
.
EtherType
=
EthernetType
.
None
;
ipV4Layer
.
Protocol
=
null
;
GreLayer
greLayer
=
random
.
NextGreLayer
();
// IEnumerable<ILayer> grePayloadLayers = random.NextIcmpPayloadLayers(icmpLayer);
return
PacketBuilder
.
Build
(
packetTimestamp
,
new
ILayer
[]
{
ethernetLayer
,
ipV4Layer
,
greLayer
});
case
PacketType
.
Udp
:
case
PacketType
.
Udp
:
ethernetLayer
.
EtherType
=
EthernetType
.
None
;
ethernetLayer
.
EtherType
=
EthernetType
.
None
;
ipV4Layer
.
Protocol
=
null
;
ipV4Layer
.
Protocol
=
null
;
...
@@ -289,6 +298,14 @@ namespace PcapDotNet.Core.Test
...
@@ -289,6 +298,14 @@ namespace PcapDotNet.Core.Test
CompareIcmp
(
layer
,
(
IcmpDatagram
)
currentDatagram
);
CompareIcmp
(
layer
,
(
IcmpDatagram
)
currentDatagram
);
break
;
break
;
case
"gre"
:
PropertyInfo
greProperty
=
currentDatagram
.
GetType
().
GetProperty
(
"Gre"
);
if
(
greProperty
==
null
)
break
;
currentDatagram
=
greProperty
.
GetValue
(
currentDatagram
);
CompareGre
(
layer
,
(
GreDatagram
)
currentDatagram
);
break
;
case
"udp"
:
case
"udp"
:
PropertyInfo
udpProperty
=
currentDatagram
.
GetType
().
GetProperty
(
"Udp"
);
PropertyInfo
udpProperty
=
currentDatagram
.
GetType
().
GetProperty
(
"Udp"
);
if
(
udpProperty
==
null
)
if
(
udpProperty
==
null
)
...
@@ -821,23 +838,102 @@ namespace PcapDotNet.Core.Test
...
@@ -821,23 +838,102 @@ namespace PcapDotNet.Core.Test
}
}
CompareProtocols
(
icmpDatagram
,
icmp
);
CompareProtocols
(
icmpDatagram
,
icmp
);
// object currentDatagram = icmpDatagram;
}
// foreach (var layer in icmp.Protocols())
// {
private
static
void
CompareGre
(
XElement
greElement
,
GreDatagram
greDatagram
)
// switch (layer.Name())
{
// {
int
currentEntry
=
-
1
;
// case "ip":
foreach
(
var
field
in
greElement
.
Fields
())
// PropertyInfo ipV4Property = currentDatagram.GetType().GetProperty("IpV4");
{
// if (ipV4Property == null)
switch
(
field
.
Name
())
// break;
{
// currentDatagram = ipV4Property.GetValue(currentDatagram);
case
""
:
// CompareIpV4(layer, (IpV4Datagram)currentDatagram);
if
(
field
.
Show
().
StartsWith
(
"Flags and version: "
))
// break;
{
//
XElement
[]
innerFields
=
field
.
Fields
().
ToArray
();
// default:
Assert
.
AreEqual
(
8
,
innerFields
.
Length
);
// throw new InvalidOperationException("unexpected layer under icmp: " + layer.Name());
foreach
(
var
innerField
in
innerFields
)
// }
{
// }
innerField
.
AssertName
(
""
);
}
innerFields
[
0
].
AssertShow
(
string
.
Format
(
"{0}... .... .... .... = {1}"
,
greDatagram
.
ChecksumPresent
.
ToInt
(),
(
greDatagram
.
ChecksumPresent
?
"Checksum"
:
"No checksum"
)));
innerFields
[
1
].
AssertShow
(
string
.
Format
(
".{0}.. .... .... .... = {1}"
,
greDatagram
.
RoutingPresent
.
ToInt
(),
(
greDatagram
.
RoutingPresent
?
"Routing"
:
"No routing"
)));
innerFields
[
2
].
AssertShow
(
string
.
Format
(
"..{0}. .... .... .... = {1}"
,
greDatagram
.
KeyPresent
.
ToInt
(),
(
greDatagram
.
KeyPresent
?
"Key"
:
"No key"
)));
innerFields
[
3
].
AssertShow
(
string
.
Format
(
"...{0} .... .... .... = {1}"
,
greDatagram
.
SequenceNumberPresent
.
ToInt
(),
(
greDatagram
.
SequenceNumberPresent
?
"Sequence number"
:
"No sequence number"
)));
innerFields
[
4
].
AssertShow
(
string
.
Format
(
".... {0}... .... .... = {1}"
,
greDatagram
.
StrictSourceRoute
.
ToInt
(),
(
greDatagram
.
StrictSourceRoute
?
"Strict source route"
:
"No strict source route"
)));
innerFields
[
5
].
AssertShow
(
string
.
Format
(
".... .{0} .... .... = Recursion control: {1}"
,
greDatagram
.
RecursionControl
.
ToBits
().
Skip
(
5
).
Select
(
b
=>
b
.
ToInt
()).
SequenceToString
(),
greDatagram
.
RecursionControl
));
innerFields
[
6
].
AssertShow
(
string
.
Format
(
".... .... {0}... = Flags: {1}"
,
greDatagram
.
Flags
.
ToBits
().
Skip
(
3
).
Select
(
b
=>
b
.
ToInt
()).
SequenceToString
().
Insert
(
4
,
" "
),
greDatagram
.
Flags
));
innerFields
[
7
].
AssertShow
(
string
.
Format
(
".... .... .... .{0} = Version: {1}"
,
((
byte
)
greDatagram
.
Version
).
ToBits
().
Skip
(
5
).
Select
(
b
=>
b
.
ToInt
()).
SequenceToString
(),
(
byte
)
greDatagram
.
Version
));
}
else
if
(
field
.
Show
().
StartsWith
(
"Checksum: "
))
{
field
.
AssertValue
(
greDatagram
.
Checksum
);
}
else
if
(
field
.
Show
().
StartsWith
(
"Offset: "
))
{
field
.
AssertValue
(
greDatagram
.
RoutingOffset
);
}
else
if
(
field
.
Show
().
StartsWith
(
"Sequence number: "
))
{
field
.
AssertValue
(
greDatagram
.
SequenceNumber
);
}
else
if
(
field
.
Show
().
StartsWith
(
"Address family: "
))
{
++
currentEntry
;
if
(
currentEntry
==
greDatagram
.
Routing
.
Count
)
field
.
AssertValue
((
ushort
)
0
);
else
field
.
AssertValue
((
ushort
)
greDatagram
.
Routing
[
currentEntry
].
AddressFamily
);
}
else
if
(
field
.
Show
().
StartsWith
(
"SRE offset: "
))
{
if
(
currentEntry
==
greDatagram
.
Routing
.
Count
)
field
.
AssertValue
((
byte
)
0
);
else
field
.
AssertValue
(
greDatagram
.
Routing
[
currentEntry
].
PayloadOffset
);
}
else
if
(
field
.
Show
().
StartsWith
(
"SRE length: "
))
{
if
(
currentEntry
==
greDatagram
.
Routing
.
Count
)
field
.
AssertValue
((
byte
)
0
);
else
field
.
AssertValue
(
greDatagram
.
Routing
[
currentEntry
].
PayloadLength
);
}
else
{
Assert
.
Fail
(
"Invalid field "
+
field
.
Show
());
}
break
;
case
"gre.proto"
:
field
.
AssertShowHex
((
ushort
)
greDatagram
.
ProtocolType
);
break
;
case
"gre.key"
:
field
.
AssertShowHex
(
greDatagram
.
Key
);
break
;
default
:
Assert
.
Fail
(
"Invalid field name: "
+
field
.
Name
());
break
;
}
}
}
}
private
static
void
CompareUdp
(
XElement
udpElement
,
IpV4Datagram
ipV4Datagram
)
private
static
void
CompareUdp
(
XElement
udpElement
,
IpV4Datagram
ipV4Datagram
)
...
...
PcapDotNet/src/PcapDotNet.Core.Test/XElementExtensions.cs
View file @
caa669f1
...
@@ -42,99 +42,119 @@ namespace PcapDotNet.Core.Test
...
@@ -42,99 +42,119 @@ namespace PcapDotNet.Core.Test
return
element
.
GetAttributeValue
(
"value"
);
return
element
.
GetAttributeValue
(
"value"
);
}
}
public
static
void
Assert
Show
(
this
XElement
element
,
string
valu
e
)
public
static
void
Assert
Name
(
this
XElement
element
,
string
expectedNam
e
)
{
{
Assert
.
AreEqual
(
element
.
Show
(),
value
,
element
.
Name
()
);
Assert
.
AreEqual
(
element
.
Name
(),
expectedName
);
}
}
public
static
void
AssertShow
(
this
XElement
element
,
IEnumerable
<
byte
>
v
alue
)
public
static
void
AssertShow
(
this
XElement
element
,
string
expectedV
alue
)
{
{
element
.
AssertShow
(
value
.
BytesSequenceToHexadecimalString
(
":"
));
Assert
.
AreEqual
(
expectedValue
,
element
.
Show
(),
element
.
Name
(
));
}
}
public
static
void
AssertShow
Decimal
(
this
XElement
element
,
bool
v
alue
)
public
static
void
AssertShow
(
this
XElement
element
,
IEnumerable
<
byte
>
expectedV
alue
)
{
{
element
.
AssertShow
Decimal
(
value
?
1
:
0
);
element
.
AssertShow
(
expectedValue
.
BytesSequenceToHexadecimalString
(
":"
)
);
}
}
public
static
void
AssertShowDecimal
(
this
XElement
element
,
b
yte
v
alue
)
public
static
void
AssertShowDecimal
(
this
XElement
element
,
b
ool
expectedV
alue
)
{
{
element
.
AssertShow
(
value
.
ToString
()
);
element
.
AssertShow
Decimal
(
expectedValue
?
1
:
0
);
}
}
public
static
void
AssertShowDecimal
(
this
XElement
element
,
short
v
alue
)
public
static
void
AssertShowDecimal
(
this
XElement
element
,
byte
expectedV
alue
)
{
{
element
.
AssertShow
(
v
alue
.
ToString
());
element
.
AssertShow
(
expectedV
alue
.
ToString
());
}
}
public
static
void
AssertShowDecimal
(
this
XElement
element
,
ushort
v
alue
)
public
static
void
AssertShowDecimal
(
this
XElement
element
,
short
expectedV
alue
)
{
{
element
.
AssertShow
(
v
alue
.
ToString
());
element
.
AssertShow
(
expectedV
alue
.
ToString
());
}
}
public
static
void
AssertShowDecimal
(
this
XElement
element
,
int
v
alue
)
public
static
void
AssertShowDecimal
(
this
XElement
element
,
ushort
expectedV
alue
)
{
{
element
.
AssertShow
(
v
alue
.
ToString
());
element
.
AssertShow
(
expectedV
alue
.
ToString
());
}
}
public
static
void
AssertShowDecimal
(
this
XElement
element
,
uint
v
alue
)
public
static
void
AssertShowDecimal
(
this
XElement
element
,
int
expectedV
alue
)
{
{
element
.
AssertShow
(
v
alue
.
ToString
());
element
.
AssertShow
(
expectedV
alue
.
ToString
());
}
}
public
static
void
AssertShowDecimal
(
this
XElement
element
,
long
v
alue
)
public
static
void
AssertShowDecimal
(
this
XElement
element
,
uint
expectedV
alue
)
{
{
element
.
AssertShow
(
v
alue
.
ToString
());
element
.
AssertShow
(
expectedV
alue
.
ToString
());
}
}
public
static
void
AssertShowDecimal
(
this
XElement
element
,
ulong
v
alue
)
public
static
void
AssertShowDecimal
(
this
XElement
element
,
long
expectedV
alue
)
{
{
element
.
AssertShow
(
v
alue
.
ToString
());
element
.
AssertShow
(
expectedV
alue
.
ToString
());
}
}
public
static
void
AssertShow
Hex
(
this
XElement
element
,
byte
v
alue
)
public
static
void
AssertShow
Decimal
(
this
XElement
element
,
ulong
expectedV
alue
)
{
{
element
.
AssertShow
(
"0x"
+
value
.
ToString
(
"x"
+
2
*
sizeof
(
byte
)
));
element
.
AssertShow
(
expectedValue
.
ToString
(
));
}
}
public
static
void
AssertShowHex
(
this
XElement
element
,
short
v
alue
)
public
static
void
AssertShowHex
(
this
XElement
element
,
byte
expectedV
alue
)
{
{
element
.
AssertShow
(
"0x"
+
value
.
ToString
(
"x"
+
2
*
sizeof
(
short
)));
element
.
AssertShow
(
"0x"
+
expectedValue
.
ToString
(
"x"
+
2
*
sizeof
(
byte
)));
}
}
public
static
void
AssertShowHex
(
this
XElement
element
,
ushort
v
alue
)
public
static
void
AssertShowHex
(
this
XElement
element
,
short
expectedV
alue
)
{
{
element
.
AssertShow
(
"0x"
+
value
.
ToString
(
"x"
+
2
*
sizeof
(
u
short
)));
element
.
AssertShow
(
"0x"
+
expectedValue
.
ToString
(
"x"
+
2
*
sizeof
(
short
)));
}
}
public
static
void
AssertShowHex
(
this
XElement
element
,
int
v
alue
)
public
static
void
AssertShowHex
(
this
XElement
element
,
ushort
expectedV
alue
)
{
{
element
.
AssertShow
(
"0x"
+
value
.
ToString
(
"x"
+
2
*
sizeof
(
in
t
)));
element
.
AssertShow
(
"0x"
+
expectedValue
.
ToString
(
"x"
+
2
*
sizeof
(
ushor
t
)));
}
}
public
static
void
AssertShowHex
(
this
XElement
element
,
uint
v
alue
)
public
static
void
AssertShowHex
(
this
XElement
element
,
int
expectedV
alue
)
{
{
element
.
AssertShow
(
"0x"
+
value
.
ToString
(
"x"
+
2
*
sizeof
(
u
int
)));
element
.
AssertShow
(
"0x"
+
expectedValue
.
ToString
(
"x"
+
2
*
sizeof
(
int
)));
}
}
public
static
void
AssertShowHex
(
this
XElement
element
,
long
v
alue
)
public
static
void
AssertShowHex
(
this
XElement
element
,
uint
expectedV
alue
)
{
{
element
.
AssertShow
(
"0x"
+
value
.
ToString
(
"x"
+
2
*
sizeof
(
long
)));
element
.
AssertShow
(
"0x"
+
expectedValue
.
ToString
(
"x"
+
2
*
sizeof
(
uint
)));
}
}
public
static
void
AssertShowHex
(
this
XElement
element
,
ulong
v
alue
)
public
static
void
AssertShowHex
(
this
XElement
element
,
long
expectedV
alue
)
{
{
element
.
AssertShow
(
"0x"
+
value
.
ToString
(
"x"
+
2
*
sizeof
(
u
long
)));
element
.
AssertShow
(
"0x"
+
expectedValue
.
ToString
(
"x"
+
2
*
sizeof
(
long
)));
}
}
public
static
void
Assert
Value
(
this
XElement
element
,
string
v
alue
)
public
static
void
Assert
ShowHex
(
this
XElement
element
,
ulong
expectedV
alue
)
{
{
Assert
.
AreEqual
(
element
.
Value
(),
value
,
element
.
Name
(
));
element
.
AssertShow
(
"0x"
+
expectedValue
.
ToString
(
"x"
+
2
*
sizeof
(
ulong
)
));
}
}
public
static
void
AssertValue
(
this
XElement
element
,
IEnumerable
<
byte
>
bytes
)
public
static
void
AssertValue
(
this
XElement
element
,
string
expectedValue
)
{
{
element
.
AssertValue
(
bytes
.
BytesSequenceToHexadecimalString
());
Assert
.
AreEqual
(
element
.
Value
(),
expectedValue
,
element
.
Name
());
}
public
static
void
AssertValue
(
this
XElement
element
,
IEnumerable
<
byte
>
expectedValue
)
{
element
.
AssertValue
(
expectedValue
.
BytesSequenceToHexadecimalString
());
}
public
static
void
AssertValue
(
this
XElement
element
,
byte
expectedValue
)
{
element
.
AssertValue
(
expectedValue
.
ToString
(
"x2"
));
}
public
static
void
AssertValue
(
this
XElement
element
,
ushort
expectedValue
)
{
element
.
AssertValue
(
expectedValue
.
ToString
(
"x4"
));
}
public
static
void
AssertValue
(
this
XElement
element
,
uint
expectedValue
)
{
element
.
AssertValue
(
expectedValue
.
ToString
(
"x8"
));
}
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets.Test/GreTests.cs
View file @
caa669f1
...
@@ -135,7 +135,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -135,7 +135,7 @@ namespace PcapDotNet.Packets.Test
default
:
default
:
GreSourceRouteEntryUnknown
unknownEntry
=
(
GreSourceRouteEntryUnknown
)
entry
;
GreSourceRouteEntryUnknown
unknownEntry
=
(
GreSourceRouteEntryUnknown
)
entry
;
MoreAssert
.
IsInRange
(
0
,
unknownEntry
.
Data
.
Length
,
unknownEntry
.
Offset
);
MoreAssert
.
IsInRange
(
0
,
unknownEntry
.
Data
.
Length
,
unknownEntry
.
Payload
Offset
);
break
;
break
;
}
}
...
@@ -191,7 +191,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -191,7 +191,7 @@ namespace PcapDotNet.Packets.Test
packet
=
packetBuilder
.
Build
(
DateTime
.
Now
);
packet
=
packetBuilder
.
Build
(
DateTime
.
Now
);
Assert
.
IsFalse
(
packet
.
IsValid
);
Assert
.
IsFalse
(
packet
.
IsValid
);
//
Sre
Offset is too big
//
Payload
Offset is too big
buffer
=
gre
.
ToArray
();
buffer
=
gre
.
ToArray
();
buffer
[
gre
.
Length
-
10
]
=
100
;
buffer
[
gre
.
Length
-
10
]
=
100
;
newIpPayload
=
new
Datagram
(
buffer
);
newIpPayload
=
new
Datagram
(
buffer
);
...
@@ -199,7 +199,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -199,7 +199,7 @@ namespace PcapDotNet.Packets.Test
packet
=
packetBuilder
.
Build
(
DateTime
.
Now
);
packet
=
packetBuilder
.
Build
(
DateTime
.
Now
);
Assert
.
IsFalse
(
packet
.
IsValid
);
Assert
.
IsFalse
(
packet
.
IsValid
);
//
Sre
Offset isn't aligned to ip
//
Payload
Offset isn't aligned to ip
buffer
=
gre
.
ToArray
();
buffer
=
gre
.
ToArray
();
buffer
[
gre
.
Length
-
10
]
=
3
;
buffer
[
gre
.
Length
-
10
]
=
3
;
newIpPayload
=
new
Datagram
(
buffer
);
newIpPayload
=
new
Datagram
(
buffer
);
...
@@ -207,7 +207,7 @@ namespace PcapDotNet.Packets.Test
...
@@ -207,7 +207,7 @@ namespace PcapDotNet.Packets.Test
packet
=
packetBuilder
.
Build
(
DateTime
.
Now
);
packet
=
packetBuilder
.
Build
(
DateTime
.
Now
);
Assert
.
IsFalse
(
packet
.
IsValid
);
Assert
.
IsFalse
(
packet
.
IsValid
);
//
Sre
Offset isn't aligned to as
//
Payload
Offset isn't aligned to as
buffer
=
gre
.
ToArray
();
buffer
=
gre
.
ToArray
();
buffer
[
gre
.
Length
-
16
]
=
1
;
buffer
[
gre
.
Length
-
16
]
=
1
;
newIpPayload
=
new
Datagram
(
buffer
);
newIpPayload
=
new
Datagram
(
buffer
);
...
...
PcapDotNet/src/PcapDotNet.Packets/Gre/GreDatagram.cs
View file @
caa669f1
...
@@ -36,6 +36,7 @@ namespace PcapDotNet.Packets.Gre
...
@@ -36,6 +36,7 @@ namespace PcapDotNet.Packets.Gre
public
const
int
SequenceNumberPresent
=
0
;
public
const
int
SequenceNumberPresent
=
0
;
public
const
int
StrictSourceRoute
=
0
;
public
const
int
StrictSourceRoute
=
0
;
public
const
int
RecursionControl
=
0
;
public
const
int
RecursionControl
=
0
;
public
const
int
Flags
=
1
;
public
const
int
Version
=
1
;
public
const
int
Version
=
1
;
public
const
int
ProtocolType
=
2
;
public
const
int
ProtocolType
=
2
;
public
const
int
Checksum
=
4
;
public
const
int
Checksum
=
4
;
...
@@ -50,9 +51,15 @@ namespace PcapDotNet.Packets.Gre
...
@@ -50,9 +51,15 @@ namespace PcapDotNet.Packets.Gre
public
const
byte
SequenceNumberPresent
=
0x10
;
public
const
byte
SequenceNumberPresent
=
0x10
;
public
const
byte
StrictSourceRoute
=
0x08
;
public
const
byte
StrictSourceRoute
=
0x08
;
public
const
byte
RecursionControl
=
0x07
;
public
const
byte
RecursionControl
=
0x07
;
public
const
byte
Flags
=
0xF8
;
public
const
byte
Version
=
0x07
;
public
const
byte
Version
=
0x07
;
}
}
private
static
class
Shift
{
public
const
int
Flags
=
3
;
}
public
const
int
HeaderMinimumLength
=
4
;
public
const
int
HeaderMinimumLength
=
4
;
public
int
HeaderLength
public
int
HeaderLength
...
@@ -108,14 +115,19 @@ namespace PcapDotNet.Packets.Gre
...
@@ -108,14 +115,19 @@ namespace PcapDotNet.Packets.Gre
get
{
return
(
this
[
Offset
.
StrictSourceRoute
]
&
Mask
.
StrictSourceRoute
)
==
Mask
.
StrictSourceRoute
;
}
get
{
return
(
this
[
Offset
.
StrictSourceRoute
]
&
Mask
.
StrictSourceRoute
)
==
Mask
.
StrictSourceRoute
;
}
}
}
/// <summary>
/// <summary>
/// Recursion control contains a three bit unsigned integer which contains the number of additional encapsulations which are permissible.
/// Recursion control contains a three bit unsigned integer which contains the number of additional encapsulations which are permissible.
/// This SHOULD default to zero.
/// This SHOULD default to zero.
/// </summary>
/// </summary>
public
byte
RecursionControl
public
byte
RecursionControl
{
{
get
{
return
(
byte
)(
this
[
Offset
.
RecursionControl
]
&
Mask
.
RecursionControl
);
}
get
{
return
(
byte
)(
this
[
Offset
.
RecursionControl
]
&
Mask
.
RecursionControl
);
}
}
}
public
byte
Flags
{
get
{
return
(
byte
)((
this
[
Offset
.
Flags
]
&
Mask
.
Flags
)
>>
Shift
.
Flags
);
}
}
/// <summary>
/// <summary>
/// The Version Number field MUST contain the value zero.
/// The Version Number field MUST contain the value zero.
...
@@ -428,14 +440,15 @@ namespace PcapDotNet.Packets.Gre
...
@@ -428,14 +440,15 @@ namespace PcapDotNet.Packets.Gre
get
{
return
HeaderLength
+
PayloadLength
;
}
get
{
return
HeaderLength
+
PayloadLength
;
}
}
}
public
abstract
int
PayloadLength
{
get
;
}
public
abstract
byte
PayloadOffset
{
get
;
}
public
abstract
byte
PayloadLength
{
get
;
}
public
bool
Equals
(
GreSourceRouteEntry
other
)
public
bool
Equals
(
GreSourceRouteEntry
other
)
{
{
return
other
!=
null
&&
return
other
!=
null
&&
AddressFamily
==
other
.
AddressFamily
&&
AddressFamily
==
other
.
AddressFamily
&&
Length
==
other
.
Length
&&
Length
==
other
.
Length
&&
OffsetInPayload
==
other
.
OffsetInPayload
&&
PayloadOffset
==
other
.
PayloadOffset
&&
EqualsPayloads
(
other
);
EqualsPayloads
(
other
);
}
}
...
@@ -444,7 +457,6 @@ namespace PcapDotNet.Packets.Gre
...
@@ -444,7 +457,6 @@ namespace PcapDotNet.Packets.Gre
return
Equals
(
obj
as
GreSourceRouteEntry
);
return
Equals
(
obj
as
GreSourceRouteEntry
);
}
}
protected
abstract
byte
OffsetInPayload
{
get
;
}
protected
abstract
bool
EqualsPayloads
(
GreSourceRouteEntry
other
);
protected
abstract
bool
EqualsPayloads
(
GreSourceRouteEntry
other
);
protected
abstract
void
WritePayload
(
byte
[]
buffer
,
int
offset
);
protected
abstract
void
WritePayload
(
byte
[]
buffer
,
int
offset
);
...
@@ -482,7 +494,7 @@ namespace PcapDotNet.Packets.Gre
...
@@ -482,7 +494,7 @@ namespace PcapDotNet.Packets.Gre
internal
void
Write
(
byte
[]
buffer
,
ref
int
offset
)
internal
void
Write
(
byte
[]
buffer
,
ref
int
offset
)
{
{
buffer
.
Write
(
offset
+
Offset
.
AddressFamily
,
(
ushort
)
AddressFamily
,
Endianity
.
Big
);
buffer
.
Write
(
offset
+
Offset
.
AddressFamily
,
(
ushort
)
AddressFamily
,
Endianity
.
Big
);
buffer
.
Write
(
offset
+
Offset
.
SreOffset
,
OffsetInPayload
);
buffer
.
Write
(
offset
+
Offset
.
SreOffset
,
PayloadOffset
);
buffer
.
Write
(
offset
+
Offset
.
SreLength
,
(
byte
)
PayloadLength
);
buffer
.
Write
(
offset
+
Offset
.
SreLength
,
(
byte
)
PayloadLength
);
WritePayload
(
buffer
,
offset
+
HeaderLength
);
WritePayload
(
buffer
,
offset
+
HeaderLength
);
offset
+=
Length
;
offset
+=
Length
;
...
@@ -533,15 +545,19 @@ namespace PcapDotNet.Packets.Gre
...
@@ -533,15 +545,19 @@ namespace PcapDotNet.Packets.Gre
_nextAddressIndex
=
nextAddressIndex
;
_nextAddressIndex
=
nextAddressIndex
;
}
}
public
override
GreSourceRouteEntryAddressFamily
AddressFamily
public
override
GreSourceRouteEntryAddressFamily
AddressFamily
{
{
get
{
return
GreSourceRouteEntryAddressFamily
.
IpSourceRoute
;
}
get
{
return
GreSourceRouteEntryAddressFamily
.
IpSourceRoute
;
}
}
}
public
override
int
PayloadLength
public
override
byte
PayloadLength
{
get
{
return
(
byte
)(
Addresses
.
Count
*
IpV4Address
.
SizeOf
);
}
}
public
override
byte
PayloadOffset
{
{
get
{
return
Addresses
.
Count
*
IpV4Address
.
SizeOf
;
}
get
{
return
(
byte
)(
NextAddressIndex
*
IpV4Address
.
SizeOf
)
;
}
}
}
protected
override
bool
EqualsPayloads
(
GreSourceRouteEntry
other
)
protected
override
bool
EqualsPayloads
(
GreSourceRouteEntry
other
)
...
@@ -570,11 +586,6 @@ namespace PcapDotNet.Packets.Gre
...
@@ -570,11 +586,6 @@ namespace PcapDotNet.Packets.Gre
get
{
return
Addresses
[
NextAddressIndex
];
}
get
{
return
Addresses
[
NextAddressIndex
];
}
}
}
protected
override
byte
OffsetInPayload
{
get
{
return
(
byte
)(
NextAddressIndex
*
IpV4Address
.
SizeOf
);
}
}
internal
GreSourceRouteEntryIp
(
IpV4Address
[]
addresses
,
int
nextAddressIndex
)
internal
GreSourceRouteEntryIp
(
IpV4Address
[]
addresses
,
int
nextAddressIndex
)
:
this
(
addresses
.
AsReadOnly
(),
nextAddressIndex
)
:
this
(
addresses
.
AsReadOnly
(),
nextAddressIndex
)
{
{
...
@@ -597,9 +608,14 @@ namespace PcapDotNet.Packets.Gre
...
@@ -597,9 +608,14 @@ namespace PcapDotNet.Packets.Gre
get
{
return
GreSourceRouteEntryAddressFamily
.
AsSourceRoute
;
}
get
{
return
GreSourceRouteEntryAddressFamily
.
AsSourceRoute
;
}
}
}
public
override
int
PayloadLength
public
override
byte
PayloadLength
{
{
get
{
return
AsNumbers
.
Count
*
sizeof
(
ushort
);
}
get
{
return
(
byte
)(
AsNumbers
.
Count
*
sizeof
(
ushort
));
}
}
public
override
byte
PayloadOffset
{
get
{
return
(
byte
)(
NextAsNumberIndex
*
sizeof
(
ushort
));
}
}
}
protected
override
bool
EqualsPayloads
(
GreSourceRouteEntry
other
)
protected
override
bool
EqualsPayloads
(
GreSourceRouteEntry
other
)
...
@@ -622,11 +638,6 @@ namespace PcapDotNet.Packets.Gre
...
@@ -622,11 +638,6 @@ namespace PcapDotNet.Packets.Gre
get
{
return
AsNumbers
[
NextAsNumberIndex
];
}
get
{
return
AsNumbers
[
NextAsNumberIndex
];
}
}
}
protected
override
byte
OffsetInPayload
{
get
{
return
(
byte
)(
NextAsNumberIndex
*
sizeof
(
ushort
));
}
}
protected
override
void
WritePayload
(
byte
[]
buffer
,
int
offset
)
protected
override
void
WritePayload
(
byte
[]
buffer
,
int
offset
)
{
{
foreach
(
ushort
asNumber
in
AsNumbers
)
foreach
(
ushort
asNumber
in
AsNumbers
)
...
@@ -656,24 +667,19 @@ namespace PcapDotNet.Packets.Gre
...
@@ -656,24 +667,19 @@ namespace PcapDotNet.Packets.Gre
get
{
return
_addressFamily
;
}
get
{
return
_addressFamily
;
}
}
}
public
override
int
PayloadLength
public
override
byte
PayloadLength
{
get
{
return
Data
.
Length
;
}
}
public
Datagram
Data
{
{
get
{
return
_data
;
}
get
{
return
(
byte
)
Data
.
Length
;
}
}
}
public
int
Offset
public
override
byte
Payload
Offset
{
{
get
{
return
_offset
;
}
get
{
return
(
byte
)
_offset
;
}
}
}
p
rotected
override
byte
OffsetInPayload
p
ublic
Datagram
Data
{
{
get
{
return
(
byte
)
Offset
;
}
get
{
return
_data
;
}
}
}
protected
override
bool
EqualsPayloads
(
GreSourceRouteEntry
other
)
protected
override
bool
EqualsPayloads
(
GreSourceRouteEntry
other
)
...
...
PcapDotNet/src/PcapDotNet.TestUtils/BoolExtensions.cs
0 → 100644
View file @
caa669f1
namespace
PcapDotNet.TestUtils
{
public
static
class
BoolExtensions
{
public
static
int
ToInt
(
this
bool
b
)
{
return
b
?
1
:
0
;
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.TestUtils/ByteExtensions.cs
0 → 100644
View file @
caa669f1
namespace
PcapDotNet.TestUtils
{
public
static
class
ByteExtensions
{
public
static
bool
[]
ToBits
(
this
byte
b
)
{
bool
[]
bits
=
new
bool
[
8
];
for
(
int
i
=
0
;
i
!=
8
;
++
i
)
{
bits
[
7
-
i
]
=
(
b
%
2
==
1
);
b
/=
2
;
}
return
bits
;
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.TestUtils/PcapDotNet.TestUtils.csproj
View file @
caa669f1
...
@@ -50,8 +50,10 @@
...
@@ -50,8 +50,10 @@
<Reference
Include=
"System.Xml"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
<Compile
Include=
"ByteExtensions.cs"
/>
<Compile
Include=
"MoreAssert.cs"
/>
<Compile
Include=
"MoreAssert.cs"
/>
<Compile
Include=
"MoreRandom.cs"
/>
<Compile
Include=
"BoolExtensions.cs"
/>
<Compile
Include=
"RandomExtensions.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
</ItemGroup>
<ItemGroup>
<ItemGroup>
...
...
PcapDotNet/src/PcapDotNet.TestUtils/
MoreRandom
.cs
→
PcapDotNet/src/PcapDotNet.TestUtils/
RandomExtensions
.cs
View file @
caa669f1
...
@@ -6,7 +6,7 @@ using PcapDotNet.Base;
...
@@ -6,7 +6,7 @@ using PcapDotNet.Base;
namespace
PcapDotNet.TestUtils
namespace
PcapDotNet.TestUtils
{
{
public
static
class
MoreRandom
public
static
class
RandomExtensions
{
{
public
static
bool
NextBool
(
this
Random
random
)
public
static
bool
NextBool
(
this
Random
random
)
{
{
...
...
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