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
bcd8ec16
Commit
bcd8ec16
authored
Nov 26, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
New PacketBuilder design
parent
8122647a
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
558 additions
and
27 deletions
+558
-27
ArpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/ArpTests.cs
+19
-5
EthernetTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/EthernetTests.cs
+12
-4
IpV4Tests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
+27
-5
TcpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/TcpTests.cs
+38
-7
UdpTests.cs
PcapDotNet/src/PcapDotNet.Packets.Test/UdpTests.cs
+32
-6
MacAddress.cs
PcapDotNet/src/PcapDotNet.Packets/Ethernet/MacAddress.cs
+6
-0
PacketBuilder2.cs
PcapDotNet/src/PcapDotNet.Packets/PacketBuilder2.cs
+423
-0
PcapDotNet.Packets.csproj
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
+1
-0
No files found.
PcapDotNet/src/PcapDotNet.Packets.Test/ArpTests.cs
View file @
bcd8ec16
...
...
@@ -66,11 +66,25 @@ namespace PcapDotNet.Packets.Test
byte
[]
arpTargetHardwareAddress
=
random
.
NextBytes
(
hardwareAddressLength
);
byte
[]
arpTargetProtocolAddress
=
random
.
NextBytes
(
protocolAddressLength
);
Packet
packet
=
PacketBuilder
.
EthernetArp
(
DateTime
.
Now
,
ethernetSource
,
ethernetType
,
arpOperation
,
arpSenderHardwareAddress
,
arpSenderProtocolAddress
,
arpTargetHardwareAddress
,
arpTargetProtocolAddress
);
Packet
packet
=
new
PacketBuilder2
(
new
EthernetLayer
{
Source
=
ethernetSource
,
},
new
ArpLayer
{
ProtocolType
=
ethernetType
,
Operation
=
arpOperation
,
SenderHardwareAddress
=
arpSenderHardwareAddress
,
SenderProtocolAddress
=
arpSenderProtocolAddress
,
TargetHardwareAddress
=
arpTargetHardwareAddress
,
TargetProtocolAddress
=
arpTargetProtocolAddress
})
.
Build
(
DateTime
.
Now
);
// Packet packet = PacketBuilder.EthernetArp(DateTime.Now,
// ethernetSource,
// ethernetType, arpOperation,
// arpSenderHardwareAddress, arpSenderProtocolAddress,
// arpTargetHardwareAddress, arpTargetProtocolAddress);
Assert
.
IsTrue
(
packet
.
IsValid
,
"IsValid"
);
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/EthernetTests.cs
View file @
bcd8ec16
...
...
@@ -72,10 +72,18 @@ namespace PcapDotNet.Packets.Test
int
ethernetPayloadLength
=
random
.
Next
(
1500
);
Datagram
ethernetPayload
=
random
.
NextDatagram
(
ethernetPayloadLength
);
Packet
packet
=
PacketBuilder
.
Ethernet
(
DateTime
.
Now
,
ethernetSource
,
ethernetDestination
,
ethernetType
,
ethernetPayload
);
Packet
packet
=
new
PacketBuilder2
(
new
EthernetLayer
{
Source
=
ethernetSource
,
Destination
=
ethernetDestination
,
EtherType
=
ethernetType
},
new
PayloadLayer
{
Data
=
ethernetPayload
})
.
Build
(
DateTime
.
Now
);
// Ethernet
Assert
.
AreEqual
(
packet
.
Length
-
EthernetDatagram
.
HeaderLength
,
packet
.
Ethernet
.
PayloadLength
,
"PayloadLength"
);
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/IpV4Tests.cs
View file @
bcd8ec16
...
...
@@ -123,11 +123,33 @@ namespace PcapDotNet.Packets.Test
random
.
NextBytes
(
ipV4PayloadBuffer
);
Datagram
ipV4Payload
=
new
Datagram
(
ipV4PayloadBuffer
);
Packet
packet
=
PacketBuilder
.
EthernetIpV4
(
DateTime
.
Now
,
ethernetSource
,
ethernetDestination
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
ipV4Protocol
,
ipV4Source
,
ipV4Destination
,
ipV4Options
,
ipV4Payload
);
Packet
packet
=
new
PacketBuilder2
(
new
EthernetLayer
{
Source
=
ethernetSource
,
Destination
=
ethernetDestination
,
},
new
IpV4Layer
{
TypeOfService
=
ipV4TypeOfService
,
Identification
=
ipV4Identification
,
Fragmentation
=
ipV4Fragmentation
,
Ttl
=
ipV4Ttl
,
Protocol
=
ipV4Protocol
,
Source
=
ipV4Source
,
Destination
=
ipV4Destination
,
Options
=
ipV4Options
,
},
new
PayloadLayer
{
Data
=
ipV4Payload
}
).
Build
(
DateTime
.
Now
);
// Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now,
// ethernetSource, ethernetDestination,
// ipV4TypeOfService, ipV4Identification, ipV4Fragmentation, ipV4Ttl, ipV4Protocol,
// ipV4Source, ipV4Destination, ipV4Options,
// ipV4Payload);
Assert
.
IsTrue
(
ipV4Protocol
==
IpV4Protocol
.
Udp
||
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/TcpTests.cs
View file @
bcd8ec16
...
...
@@ -92,13 +92,44 @@ namespace PcapDotNet.Packets.Test
TcpOptions
tcpOptions
=
random
.
NextTcpOptions
();
Datagram
tcpPayload
=
random
.
NextDatagram
(
random
.
Next
(
60000
));
Packet
packet
=
PacketBuilder
.
EthernetIpV4Tcp
(
DateTime
.
Now
,
ethernetSource
,
ethernetDestination
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
ipV4Source
,
ipV4Destination
,
ipV4Options
,
tcpSourcePort
,
tcpDestinationPort
,
tcpSequenceNumber
,
tcpAcknowledgmentNumber
,
tcpControlBits
,
tcpWindow
,
tcpUrgentPointer
,
tcpOptions
,
tcpPayload
);
Packet
packet
=
new
PacketBuilder2
(
new
EthernetLayer
{
Source
=
ethernetSource
,
Destination
=
ethernetDestination
},
new
IpV4Layer
{
TypeOfService
=
ipV4TypeOfService
,
Identification
=
ipV4Identification
,
Fragmentation
=
ipV4Fragmentation
,
Ttl
=
ipV4Ttl
,
Source
=
ipV4Source
,
Destination
=
ipV4Destination
,
Options
=
ipV4Options
,
},
new
TcpLayer
{
SourcePort
=
tcpSourcePort
,
DestinationPort
=
tcpDestinationPort
,
SequenceNumber
=
tcpSequenceNumber
,
AcknowledgmentNumber
=
tcpAcknowledgmentNumber
,
ControlBits
=
tcpControlBits
,
Window
=
tcpWindow
,
UrgentPointer
=
tcpUrgentPointer
,
Options
=
tcpOptions
,
},
new
PayloadLayer
{
Data
=
tcpPayload
}
).
Build
(
DateTime
.
Now
);
// Packet packet = PacketBuilder.EthernetIpV4Tcp(DateTime.Now,
// ethernetSource, ethernetDestination,
// ipV4TypeOfService, ipV4Identification, ipV4Fragmentation, ipV4Ttl,
// ipV4Source, ipV4Destination, ipV4Options,
// tcpSourcePort, tcpDestinationPort, tcpSequenceNumber, tcpAcknowledgmentNumber, tcpControlBits, tcpWindow, tcpUrgentPointer,
// tcpOptions,
// tcpPayload);
Assert
.
IsTrue
(
packet
.
IsValid
);
...
...
PcapDotNet/src/PcapDotNet.Packets.Test/UdpTests.cs
View file @
bcd8ec16
...
...
@@ -86,12 +86,38 @@ namespace PcapDotNet.Packets.Test
bool
udpCalculateChecksum
=
random
.
NextBool
();
Datagram
udpPayload
=
random
.
NextDatagram
(
random
.
Next
(
60000
));
Packet
packet
=
PacketBuilder
.
EthernetIpV4Udp
(
DateTime
.
Now
,
ethernetSource
,
ethernetDestination
,
ipV4TypeOfService
,
ipV4Identification
,
ipV4Fragmentation
,
ipV4Ttl
,
ipV4Source
,
ipV4Destination
,
ipV4Options
,
udpSourcePort
,
udpDestinationPort
,
udpCalculateChecksum
,
udpPayload
);
Packet
packet
=
new
PacketBuilder2
(
new
EthernetLayer
{
Source
=
ethernetSource
,
Destination
=
ethernetDestination
,
},
new
IpV4Layer
{
TypeOfService
=
ipV4TypeOfService
,
Identification
=
ipV4Identification
,
Fragmentation
=
ipV4Fragmentation
,
Ttl
=
ipV4Ttl
,
Source
=
ipV4Source
,
Destination
=
ipV4Destination
,
Options
=
ipV4Options
,
},
new
UdpLayer
{
SourcePort
=
udpSourcePort
,
DestinationPort
=
udpDestinationPort
,
CalculateChecksum
=
udpCalculateChecksum
,
},
new
PayloadLayer
{
Data
=
udpPayload
})
.
Build
(
DateTime
.
Now
);
// Packet packet = PacketBuilder.EthernetIpV4Udp(DateTime.Now,
// ethernetSource, ethernetDestination,
// ipV4TypeOfService, ipV4Identification, ipV4Fragmentation, ipV4Ttl,
// ipV4Source, ipV4Destination, ipV4Options,
// udpSourcePort, udpDestinationPort, udpCalculateChecksum,
// udpPayload);
Assert
.
IsTrue
(
packet
.
IsValid
);
...
...
PcapDotNet/src/PcapDotNet.Packets/Ethernet/MacAddress.cs
View file @
bcd8ec16
...
...
@@ -14,6 +14,11 @@ namespace PcapDotNet.Packets.Ethernet
/// </summary>
public
const
int
SizeOf
=
UInt48
.
SizeOf
;
public
static
MacAddress
Zero
{
get
{
return
_zero
;
}
}
/// <summary>
/// Constructs the address from a 48 bit integer.
/// </summary>
...
...
@@ -105,6 +110,7 @@ namespace PcapDotNet.Packets.Ethernet
(
byte
)(
_value
));
}
private
static
readonly
MacAddress
_zero
;
private
readonly
UInt48
_value
;
}
}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Packets/PacketBuilder2.cs
0 → 100644
View file @
bcd8ec16
This diff is collapsed.
Click to expand it.
PcapDotNet/src/PcapDotNet.Packets/PcapDotNet.Packets.csproj
View file @
bcd8ec16
...
...
@@ -134,6 +134,7 @@
<Compile
Include=
"OptionTypeRegistrationAttribute.cs"
/>
<Compile
Include=
"Packet.cs"
/>
<Compile
Include=
"PacketBuilder.cs"
/>
<Compile
Include=
"PacketBuilder2.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
<Compile
Include=
"Transport\TcpDatagram.cs"
/>
<Compile
Include=
"Transport\TcpControlBits.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