Commit bcd8ec16 authored by Brickner_cp's avatar Brickner_cp

New PacketBuilder design

parent 8122647a
......@@ -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");
......
......@@ -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");
......
......@@ -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 ||
......
......@@ -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);
......
......@@ -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);
......
......@@ -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
This diff is collapsed.
......@@ -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" />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment