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
13e7b291
Commit
13e7b291
authored
Jul 30, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
IpV4
parent
990042d6
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
607 additions
and
198 deletions
+607
-198
IpV4Tests.cs
PcapDotNet/src/Packets.Test/IpV4Tests.cs
+63
-92
Packets.Test.csproj
PcapDotNet/src/Packets.Test/Packets.Test.csproj
+1
-1
EthernetDatagram.cs
PcapDotNet/src/Packets/Ethernet/EthernetDatagram.cs
+1
-0
IpV4Address.cs
PcapDotNet/src/Packets/IpV4/IpV4Address.cs
+6
-0
IpV4Datagram.cs
PcapDotNet/src/Packets/IpV4/IpV4Datagram.cs
+332
-105
IpV4Fragmentation.cs
PcapDotNet/src/Packets/IpV4/IpV4Fragmentation.cs
+51
-0
IpV4FragmentationFlags.cs
PcapDotNet/src/Packets/IpV4/IpV4FragmentationFlags.cs
+13
-0
IpV4Protocol.cs
PcapDotNet/src/Packets/IpV4/IpV4Protocol.cs
+7
-0
MoreByteArray.cs
PcapDotNet/src/Packets/MoreByteArray.cs
+30
-0
Packets.csproj
PcapDotNet/src/Packets/Packets.csproj
+3
-0
DumpPacketsTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/DumpPacketsTests.cs
+99
-0
PcapDotNet.Core.Test.csproj
...tNet/src/PcapDotNet.Core.Test/PcapDotNet.Core.Test.csproj
+1
-0
No files found.
PcapDotNet/src/Packets.Test/IpV4
Datagram
Tests.cs
→
PcapDotNet/src/Packets.Test/IpV4Tests.cs
View file @
13e7b291
This diff is collapsed.
Click to expand it.
PcapDotNet/src/Packets.Test/Packets.Test.csproj
View file @
13e7b291
...
...
@@ -43,7 +43,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="EthernetDatagramTests.cs" />
<Compile Include="IpV4
Datagram
Tests.cs" />
<Compile Include="IpV4Tests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="IpV4AddressTests.cs" />
</ItemGroup>
...
...
PcapDotNet/src/Packets/Ethernet/EthernetDatagram.cs
View file @
13e7b291
...
...
@@ -81,6 +81,7 @@ namespace Packets
}
}
internal
EthernetDatagram
(
byte
[]
buffer
,
int
offset
,
int
length
)
:
base
(
buffer
,
offset
,
length
)
{
...
...
PcapDotNet/src/Packets/IpV4/IpV4Address.cs
View file @
13e7b291
...
...
@@ -18,6 +18,11 @@ namespace Packets
(
byte
.
Parse
(
values
[
3
])));
}
public
static
IpV4Address
Zero
{
get
{
return
_zero
;
}
}
public
uint
ToValue
()
{
return
_value
;
...
...
@@ -74,5 +79,6 @@ namespace Packets
}
private
readonly
uint
_value
;
private
static
readonly
IpV4Address
_zero
=
new
IpV4Address
(
0
);
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4Datagram.cs
View file @
13e7b291
This diff is collapsed.
Click to expand it.
PcapDotNet/src/Packets/IpV4/IpV4Fragmentation.cs
0 → 100644
View file @
13e7b291
using
System
;
namespace
Packets
{
public
struct
IpV4Fragmentation
:
IEquatable
<
IpV4Fragmentation
>
{
public
static
IpV4Fragmentation
None
{
get
{
return
_none
;
}
}
public
IpV4Fragmentation
(
IpV4FragmentationFlags
flags
,
ushort
offset
)
:
this
((
ushort
)((
ushort
)
flags
|
(
offset
/
8
)))
{
}
public
IpV4FragmentationFlags
Flags
{
get
{
return
(
IpV4FragmentationFlags
)(
_value
&
0xE000
);
}
}
public
ushort
Offset
{
get
{
return
(
ushort
)((
_value
&
0x1FFF
)
*
8
);
}
}
public
bool
Equals
(
IpV4Fragmentation
other
)
{
return
_value
==
other
.
_value
;
}
public
override
bool
Equals
(
object
obj
)
{
return
(
obj
is
IpV4Fragmentation
&&
Equals
((
IpV4Fragmentation
)
obj
));
}
internal
IpV4Fragmentation
(
ushort
value
)
{
_value
=
value
;
}
internal
void
Write
(
byte
[]
buffer
,
int
offset
)
{
buffer
.
Write
(
offset
,
_value
,
Endianity
.
Big
);
}
private
static
readonly
IpV4Fragmentation
_none
=
new
IpV4Fragmentation
(
IpV4FragmentationFlags
.
None
,
0
);
private
readonly
ushort
_value
;
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4FragmentationFlags.cs
0 → 100644
View file @
13e7b291
using
System
;
namespace
Packets
{
[
Flags
]
public
enum
IpV4FragmentationFlags
:
ushort
{
None
=
0x0
<<
13
,
Reserved
=
0x4
<<
13
,
DontFragment
=
0x2
<<
13
,
MoreFragments
=
0x1
<<
13
}
}
\ No newline at end of file
PcapDotNet/src/Packets/IpV4/IpV4Protocol.cs
0 → 100644
View file @
13e7b291
namespace
Packets
{
public
enum
IpV4Protocol
:
byte
{
Tcp
=
0x06
}
}
\ No newline at end of file
PcapDotNet/src/Packets/MoreByteArray.cs
View file @
13e7b291
...
...
@@ -39,6 +39,13 @@ namespace Packets
return
(
uint
)
ReadInt
(
buffer
,
offset
,
endianity
);
}
public
static
uint
ReadUInt
(
this
byte
[]
buffer
,
ref
int
offset
,
Endianity
endianity
)
{
uint
result
=
ReadUInt
(
buffer
,
offset
,
endianity
);
offset
+=
4
;
return
result
;
}
[
System
.
Diagnostics
.
CodeAnalysis
.
SuppressMessage
(
"Microsoft.Naming"
,
"CA1720:IdentifiersShouldNotContainTypeNames"
,
MessageId
=
"int"
)]
public
static
int
ReadInt
(
this
byte
[]
buffer
,
int
offset
,
Endianity
endianity
)
{
...
...
@@ -60,6 +67,18 @@ namespace Packets
Write
(
buffer
,
offset
,
(
short
)
value
,
endianity
);
}
public
static
void
Write
(
this
byte
[]
buffer
,
int
offset
,
int
value
,
Endianity
endianity
)
{
if
(
IsWrongEndianity
(
endianity
))
value
=
IPAddress
.
HostToNetworkOrder
(
value
);
Write
(
buffer
,
offset
,
value
);
}
public
static
void
Write
(
this
byte
[]
buffer
,
int
offset
,
uint
value
,
Endianity
endianity
)
{
Write
(
buffer
,
offset
,
(
int
)
value
,
endianity
);
}
private
static
bool
IsWrongEndianity
(
Endianity
endianity
)
{
return
(
BitConverter
.
IsLittleEndian
==
(
endianity
==
Endianity
.
Big
));
...
...
@@ -97,5 +116,16 @@ namespace Packets
}
}
}
private
static
void
Write
(
byte
[]
buffer
,
int
offset
,
int
value
)
{
unsafe
{
fixed
(
byte
*
ptr
=
&
buffer
[
offset
])
{
*((
int
*)
ptr
)
=
value
;
}
}
}
}
}
\ No newline at end of file
PcapDotNet/src/Packets/Packets.csproj
View file @
13e7b291
...
...
@@ -67,6 +67,9 @@
<Compile
Include=
"IDataLink.cs"
/>
<Compile
Include=
"IpV4\IpV4Address.cs"
/>
<Compile
Include=
"IpV4\IpV4Datagram.cs"
/>
<Compile
Include=
"IpV4\IpV4Fragmentation.cs"
/>
<Compile
Include=
"IpV4\IpV4FragmentationFlags.cs"
/>
<Compile
Include=
"IpV4\IpV4Protocol.cs"
/>
<Compile
Include=
"MoreByteArray.cs"
/>
<Compile
Include=
"Packet.cs"
/>
<Compile
Include=
"PacketBuilder.cs"
/>
...
...
PcapDotNet/src/PcapDotNet.Core.Test/DumpPacketsTests.cs
0 → 100644
View file @
13e7b291
using
System
;
using
Microsoft.VisualStudio.TestTools.UnitTesting
;
using
Packets
;
namespace
PcapDotNet.Core.Test
{
/// <summary>
/// Summary description for DumpPacketsTests
/// </summary>
[
TestClass
]
public
class
DumpPacketsTests
{
public
DumpPacketsTests
()
{
//
// TODO: Add constructor logic here
//
}
private
TestContext
testContextInstance
;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public
TestContext
TestContext
{
get
{
return
testContextInstance
;
}
set
{
testContextInstance
=
value
;
}
}
#
region
Additional
test
attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#
endregion
[
TestMethod
]
public
void
DumpIpV4PacketTest
()
{
MacAddress
ethernetSource
=
new
MacAddress
(
"00:01:02:03:04:05"
);
MacAddress
ethernetDestination
=
new
MacAddress
(
"A0:A1:A2:A3:A4:A5"
);
const
EthernetType
ethernetType
=
EthernetType
.
IpV4
;
Random
random
=
new
Random
();
byte
ipV4TypeOfService
=
(
byte
)
random
.
Next
(
256
);
ushort
ipV4Identification
=
(
ushort
)
random
.
Next
(
65536
);
byte
ipV4Ttl
=
(
byte
)
random
.
Next
(
256
);
IpV4FragmentationFlags
ipV4FragmentationFlags
=
(
IpV4FragmentationFlags
)(
random
.
Next
(
4
)
<<
13
);
ushort
ipV4FragmentationOffset
=
(
ushort
)
random
.
Next
(
65536
);
IpV4Fragmentation
ipV4Fragmentation
=
new
IpV4Fragmentation
(
ipV4FragmentationFlags
,
ipV4FragmentationOffset
);
const
IpV4Protocol
ipV4Protocol
=
IpV4Protocol
.
Tcp
;
IpV4Address
ipV4Source
=
new
IpV4Address
((
uint
)
random
.
Next
());
IpV4Address
ipV4Destination
=
new
IpV4Address
((
uint
)
random
.
Next
());
IpV4Options
ipV4Options
=
IpV4Options
.
None
;
byte
[]
ipV4PayloadBuffer
=
new
byte
[
random
.
Next
(
0
,
50
*
1024
)];
random
.
NextBytes
(
ipV4PayloadBuffer
);
Datagram
ipV4Payload
=
new
Datagram
(
ipV4PayloadBuffer
);
Packet
packet
=
PacketBuilder
.
IpV4
(
DateTime
.
Now
,
ethernetSource
,
ethernetDestination
,
ethernetType
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
ipV4Protocol
,
ipV4Source
,
ipV4Destination
,
ipV4Options
,
ipV4Payload
);
using
(
PacketCommunicator
communicator
=
LivePacketDeviceTests
.
OpenLiveDevice
())
{
// using (PacketDumpFile dumpFile = communicator.OpenDump(@"c:\wow.pcap"))
// {
// dumpFile.Dump(packet);
// }
}
}
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core.Test/PcapDotNet.Core.Test.csproj
View file @
13e7b291
...
...
@@ -43,6 +43,7 @@
</ItemGroup>
<ItemGroup>
<Compile Include="BerkeleyPacketFilterTests.cs" />
<Compile Include="DumpPacketsTests.cs" />
<Compile Include="MoreAssert.cs" />
<Compile Include="LivePacketDeviceTests.cs" />
<Compile Include="MoreRandom.cs" />
...
...
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