Commit b2293f3d authored by Brickner_cp's avatar Brickner_cp

ICMP

parent 1e1408a0
...@@ -224,13 +224,7 @@ namespace PcapDotNet.Core.Test ...@@ -224,13 +224,7 @@ namespace PcapDotNet.Core.Test
random.NextBytes(hardwareAddressLength), random.NextBytes(protocolAddressLength)); random.NextBytes(hardwareAddressLength), random.NextBytes(protocolAddressLength));
case PacketType.IpV4: case PacketType.IpV4:
return PacketBuilder.EthernetIpV4(packetTimestamp, return PacketBuilder2.Build(packetTimestamp, random.NextEthernetLayer(EthernetType.None), random.NextIpV4Layer(), random.NextPayloadLayer(random.Next(100)));
random.NextMacAddress(), random.NextMacAddress(),
random.NextByte(), random.NextUShort(), random.NextIpV4Fragmentation(),
random.NextByte(),
random.NextEnum<IpV4Protocol>(),
random.NextIpV4Address(), random.NextIpV4Address(), random.NextIpV4Options(),
random.NextDatagram(random.Next(100)));
case PacketType.Igmp: case PacketType.Igmp:
return CreateRandomIgmpPacket(packetTimestamp, random); return CreateRandomIgmpPacket(packetTimestamp, random);
......
...@@ -165,7 +165,7 @@ namespace PcapDotNet.Packets.Test ...@@ -165,7 +165,7 @@ namespace PcapDotNet.Packets.Test
else else
Assert.IsNull(packet.Ethernet.IpV4.Transport); Assert.IsNull(packet.Ethernet.IpV4.Transport);
Assert.AreEqual(payloadLayer, packet.Ethernet.IpV4.Payload.ExtractLayer(), "IP Payload"); Assert.AreEqual(payloadLayer.Data, packet.Ethernet.IpV4.Payload, "IP Payload");
} }
} }
...@@ -192,11 +192,27 @@ namespace PcapDotNet.Packets.Test ...@@ -192,11 +192,27 @@ namespace PcapDotNet.Packets.Test
[TestMethod] [TestMethod]
public void IpV4OptionTimestampFactoryCreateInstanceErrorTest() public void IpV4OptionTimestampFactoryCreateInstanceErrorTest()
{ {
Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now, Packet packet = PacketBuilder2.Build(DateTime.Now,
new MacAddress(), new MacAddress(), new EthernetLayer(),
0, 0, new IpV4Fragmentation(), 0, 0, new IpV4Address(), new IpV4Address(), new IpV4Layer
new IpV4Options(new IpV4OptionTimestampOnly(0, 0)), {
Datagram.Empty); Protocol = IpV4Protocol.Argus,
Options = new IpV4Options(new IpV4OptionTimestampOnly(0, 0)),
});
// public static Packet EthernetIpV4(DateTime timestamp,
// MacAddress ethernetSource, MacAddress ethernetDestination,
// byte ipV4TypeOfService, ushort ipV4Identification, IpV4Fragmentation ipV4Fragmentation,
// byte ipV4Ttl, IpV4Protocol ipV4Protocol,
// IpV4Address ipV4SourceAddress, IpV4Address ipV4DestinationAddress,
// IpV4Options ipV4Options,
// Datagram ipV4Payload)
// 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); Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
...@@ -246,11 +262,18 @@ namespace PcapDotNet.Packets.Test ...@@ -246,11 +262,18 @@ namespace PcapDotNet.Packets.Test
public void IpV4OptionRouteTryReadErrorTest() public void IpV4OptionRouteTryReadErrorTest()
{ {
// Small Length // Small Length
Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now, Packet packet = PacketBuilder2.Build(DateTime.Now,
new MacAddress(), new MacAddress(), new EthernetLayer(),
0, 0, new IpV4Fragmentation(), 0, 0, new IpV4Address(), new IpV4Address(), new IpV4Layer
new IpV4Options(new IpV4OptionLooseSourceRouting()), {
Datagram.Empty); Protocol = 0,
Options = new IpV4Options(new IpV4OptionLooseSourceRouting())
});
// 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); Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
byte[] buffer = packet.Buffer; byte[] buffer = packet.Buffer;
...@@ -371,11 +394,19 @@ namespace PcapDotNet.Packets.Test ...@@ -371,11 +394,19 @@ namespace PcapDotNet.Packets.Test
public void IpV4OptionBasicSecurityCreateInstanceErrorTest() public void IpV4OptionBasicSecurityCreateInstanceErrorTest()
{ {
// Invalid Length // Invalid Length
Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now, Packet packet = PacketBuilder2.Build(DateTime.Now,
new MacAddress(), new MacAddress(), new EthernetLayer(),
0, 0, new IpV4Fragmentation(), 0, 0, new IpV4Address(), new IpV4Address(), new IpV4Layer
new IpV4Options(new IpV4OptionBasicSecurity()), {
Datagram.Empty); Protocol = 0,
Options = new IpV4Options(new IpV4OptionBasicSecurity()),
});
// 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); Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
byte[] buffer = packet.Buffer; byte[] buffer = packet.Buffer;
...@@ -384,11 +415,19 @@ namespace PcapDotNet.Packets.Test ...@@ -384,11 +415,19 @@ namespace PcapDotNet.Packets.Test
Assert.IsFalse(packet.Ethernet.IpV4.Options.IsValid); Assert.IsFalse(packet.Ethernet.IpV4.Options.IsValid);
// Invalid classification level // Invalid classification level
packet = PacketBuilder.EthernetIpV4(DateTime.Now, packet = PacketBuilder2.Build(DateTime.Now,
new MacAddress(), new MacAddress(), new EthernetLayer(),
0, 0, new IpV4Fragmentation(), 0, 0, new IpV4Address(), new IpV4Address(), new IpV4Layer
new IpV4Options(new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Secret)), {
Datagram.Empty); Protocol = 0,
Options = new IpV4Options(new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Secret)),
});
// 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); Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
buffer = packet.Buffer; buffer = packet.Buffer;
...@@ -397,11 +436,18 @@ namespace PcapDotNet.Packets.Test ...@@ -397,11 +436,18 @@ namespace PcapDotNet.Packets.Test
Assert.IsFalse(packet.Ethernet.IpV4.Options.IsValid); Assert.IsFalse(packet.Ethernet.IpV4.Options.IsValid);
// Invalid protection authorities bytes // Invalid protection authorities bytes
packet = PacketBuilder.EthernetIpV4(DateTime.Now, packet = PacketBuilder2.Build(DateTime.Now,
new MacAddress(), new MacAddress(), new EthernetLayer(),
0, 0, new IpV4Fragmentation(), 0, 0, new IpV4Address(), new IpV4Address(), new IpV4Layer
new IpV4Options(new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Confidential, IpV4OptionSecurityProtectionAuthorities.Nsa, 5)), {
Datagram.Empty); Protocol = 0,
Options = new IpV4Options(new IpV4OptionBasicSecurity(IpV4OptionSecurityClassificationLevel.Confidential, IpV4OptionSecurityProtectionAuthorities.Nsa, 5)),
});
// 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); Assert.IsTrue(packet.Ethernet.IpV4.Options.IsValid);
buffer = packet.Buffer; buffer = packet.Buffer;
...@@ -457,11 +503,27 @@ namespace PcapDotNet.Packets.Test ...@@ -457,11 +503,27 @@ namespace PcapDotNet.Packets.Test
[TestMethod] [TestMethod]
public void IpV4DatagramInvalidShortTest() public void IpV4DatagramInvalidShortTest()
{ {
Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now, Packet packet = PacketBuilder2.Build(DateTime.Now,
new MacAddress(1), new MacAddress(2), new EthernetLayer
0, 1, new IpV4Fragmentation(IpV4FragmentationOptions.MoreFragments, 8), 1, {
IpV4Protocol.WidebandExpak, new IpV4Address(1), new IpV4Address(2), new IpV4Options(), Source = new MacAddress(1),
Datagram.Empty); Destination = new MacAddress(2),
},
new IpV4Layer
{
Identification = 1,
Fragmentation = new IpV4Fragmentation(IpV4FragmentationOptions.MoreFragments, 8),
Ttl = 1,
Protocol = IpV4Protocol.WidebandExpak,
Source = new IpV4Address(1),
Destination = new IpV4Address(2),
});
// Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now,
// new MacAddress(1), new MacAddress(2),
// 0, 1, new IpV4Fragmentation(IpV4FragmentationOptions.MoreFragments, 8), 1,
// IpV4Protocol.WidebandExpak, new IpV4Address(1), new IpV4Address(2), new IpV4Options(),
// Datagram.Empty);
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
byte[] badPacketBuffer = new byte[packet.Length - 5]; byte[] badPacketBuffer = new byte[packet.Length - 5];
...@@ -473,10 +535,14 @@ namespace PcapDotNet.Packets.Test ...@@ -473,10 +535,14 @@ namespace PcapDotNet.Packets.Test
[TestMethod] [TestMethod]
public void IpV4DatagramInvalidHeaderChecksumTest() public void IpV4DatagramInvalidHeaderChecksumTest()
{ {
Packet packet = PacketBuilder.EthernetIpV4(DateTime.Now, Packet packet = PacketBuilder2.Build(DateTime.Now, new EthernetLayer(), new IpV4Layer
new MacAddress(), new MacAddress(), {
0, 0, new IpV4Fragmentation(), 0, 0, IpV4Address.Zero, IpV4Address.Zero, IpV4Options.None, Protocol = 0,
Datagram.Empty); });
// 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); Assert.IsTrue(packet.IsValid);
......
...@@ -45,16 +45,21 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -45,16 +45,21 @@ namespace PcapDotNet.Packets.TestUtils
// Ethernet // Ethernet
public static EthernetLayer NextEthernetLayer(this Random random) public static EthernetLayer NextEthernetLayer(this Random random, EthernetType etherType)
{ {
return new EthernetLayer return new EthernetLayer
{ {
Source = random.NextMacAddress(), Source = random.NextMacAddress(),
Destination = random.NextMacAddress(), Destination = random.NextMacAddress(),
EtherType = random.NextEnum(EthernetType.None) EtherType = etherType
}; };
} }
public static EthernetLayer NextEthernetLayer(this Random random)
{
return random.NextEthernetLayer(random.NextEnum(EthernetType.None));
}
public static MacAddress NextMacAddress(this Random random) public static MacAddress NextMacAddress(this Random random)
{ {
return new MacAddress(random.NextUInt48()); return new MacAddress(random.NextUInt48());
......
...@@ -215,6 +215,7 @@ namespace PcapDotNet.Packets.IpV4 ...@@ -215,6 +215,7 @@ namespace PcapDotNet.Packets.IpV4
Fragmentation = Fragmentation, Fragmentation = Fragmentation,
Ttl = Ttl, Ttl = Ttl,
Protocol = Protocol, Protocol = Protocol,
HeaderChecksum = HeaderChecksum,
Source = Source, Source = Source,
Destination = Destination, Destination = Destination,
Options = Options, Options = Options,
...@@ -312,7 +313,7 @@ namespace PcapDotNet.Packets.IpV4 ...@@ -312,7 +313,7 @@ namespace PcapDotNet.Packets.IpV4
internal static void WriteHeader(byte[] buffer, int offset, internal static void WriteHeader(byte[] buffer, int offset,
byte typeOfService, ushort identification, byte typeOfService, ushort identification,
IpV4Fragmentation fragmentation, IpV4Fragmentation fragmentation,
byte ttl, IpV4Protocol protocol, byte ttl, IpV4Protocol protocol, ushort? checksum,
IpV4Address source, IpV4Address destination, IpV4Address source, IpV4Address destination,
IpV4Options options, int payloadLength) IpV4Options options, int payloadLength)
{ {
...@@ -330,7 +331,9 @@ namespace PcapDotNet.Packets.IpV4 ...@@ -330,7 +331,9 @@ namespace PcapDotNet.Packets.IpV4
buffer.Write(offset + Offset.Destination, destination, Endianity.Big); buffer.Write(offset + Offset.Destination, destination, Endianity.Big);
options.Write(buffer, offset + Offset.Options); options.Write(buffer, offset + Offset.Options);
buffer.Write(offset + Offset.HeaderChecksum, Sum16BitsToChecksum(Sum16Bits(buffer, offset, headerLength)), Endianity.Big); if (checksum == null)
checksum = Sum16BitsToChecksum(Sum16Bits(buffer, offset, headerLength));
buffer.Write(offset + Offset.HeaderChecksum, checksum.Value, Endianity.Big);
} }
internal static void WriteTransportChecksum(byte[] buffer, int offset, int headerLength, ushort transportLength, int transportChecksumOffset, bool isChecksumOptional) internal static void WriteTransportChecksum(byte[] buffer, int offset, int headerLength, ushort transportLength, int transportChecksumOffset, bool isChecksumOptional)
......
...@@ -90,25 +90,25 @@ namespace PcapDotNet.Packets ...@@ -90,25 +90,25 @@ namespace PcapDotNet.Packets
/// <param name="ipV4Options">The IPv4 options.</param> /// <param name="ipV4Options">The IPv4 options.</param>
/// <param name="ipV4Payload">The IPv4 payload.</param> /// <param name="ipV4Payload">The IPv4 payload.</param>
/// <returns>A packet with an IPv4 over Ethernet datagram.</returns> /// <returns>A packet with an IPv4 over Ethernet datagram.</returns>
public static Packet EthernetIpV4(DateTime timestamp, // public static Packet EthernetIpV4(DateTime timestamp,
MacAddress ethernetSource, MacAddress ethernetDestination, // MacAddress ethernetSource, MacAddress ethernetDestination,
byte ipV4TypeOfService, ushort ipV4Identification, IpV4Fragmentation ipV4Fragmentation, // byte ipV4TypeOfService, ushort ipV4Identification, IpV4Fragmentation ipV4Fragmentation,
byte ipV4Ttl, IpV4Protocol ipV4Protocol, // byte ipV4Ttl, IpV4Protocol ipV4Protocol,
IpV4Address ipV4SourceAddress, IpV4Address ipV4DestinationAddress, // IpV4Address ipV4SourceAddress, IpV4Address ipV4DestinationAddress,
IpV4Options ipV4Options, // IpV4Options ipV4Options,
Datagram ipV4Payload) // Datagram ipV4Payload)
{ // {
int ipHeaderLength = IpV4Datagram.HeaderMinimumLength + ipV4Options.BytesLength; // int ipHeaderLength = IpV4Datagram.HeaderMinimumLength + ipV4Options.BytesLength;
byte[] buffer = new byte[EthernetDatagram.HeaderLength + ipHeaderLength + ipV4Payload.Length]; // byte[] buffer = new byte[EthernetDatagram.HeaderLength + ipHeaderLength + ipV4Payload.Length];
EthernetDatagram.WriteHeader(buffer, 0, ethernetSource, ethernetDestination, EthernetType.IpV4); // EthernetDatagram.WriteHeader(buffer, 0, ethernetSource, ethernetDestination, EthernetType.IpV4);
IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength, // IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength,
ipV4TypeOfService, ipV4Identification, ipV4Fragmentation, // ipV4TypeOfService, ipV4Identification, ipV4Fragmentation,
ipV4Ttl, ipV4Protocol, // ipV4Ttl, ipV4Protocol,
ipV4SourceAddress, ipV4DestinationAddress, // ipV4SourceAddress, ipV4DestinationAddress,
ipV4Options, ipV4Payload.Length); // ipV4Options, ipV4Payload.Length);
ipV4Payload.Write(buffer, EthernetDatagram.HeaderLength + ipHeaderLength); // ipV4Payload.Write(buffer, EthernetDatagram.HeaderLength + ipHeaderLength);
return new Packet(buffer, timestamp, DataLinkKind.Ethernet); // return new Packet(buffer, timestamp, DataLinkKind.Ethernet);
} // }
/// <summary> /// <summary>
/// Builds an ICMP over IPv4 over Ethernet packet. /// Builds an ICMP over IPv4 over Ethernet packet.
...@@ -244,14 +244,14 @@ namespace PcapDotNet.Packets ...@@ -244,14 +244,14 @@ namespace PcapDotNet.Packets
EthernetDatagram.WriteHeader(buffer, 0, ethernetSource, ethernetDestination, EthernetType.IpV4); EthernetDatagram.WriteHeader(buffer, 0, ethernetSource, ethernetDestination, EthernetType.IpV4);
IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength, IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength,
ipV4TypeOfService, ipV4Identification, ipV4Fragmentation, ipV4TypeOfService, ipV4Identification, ipV4Fragmentation,
ipV4Ttl, IpV4Protocol.InternetControlMessageProtocol, ipV4Ttl, IpV4Protocol.InternetControlMessageProtocol, null,
ipV4SourceAddress, ipV4DestinationAddress, ipV4SourceAddress, ipV4DestinationAddress,
ipV4Options, ipPayloadLength); ipV4Options, ipPayloadLength);
IcmpDatagram.WriteHeader(buffer, icmpOffset, IcmpMessageType.DestinationUnreachable, icmpCode, icmpValueAccordingToType); IcmpDatagram.WriteHeader(buffer, icmpOffset, IcmpMessageType.DestinationUnreachable, icmpCode, icmpValueAccordingToType);
IpV4Datagram.WriteHeader(buffer, icmpOffset + IcmpDatagram.HeaderLength, IpV4Datagram.WriteHeader(buffer, icmpOffset + IcmpDatagram.HeaderLength,
icmpIpV4TypeOfService, icmpIpV4Identification, icmpIpV4TypeOfService, icmpIpV4Identification,
icmpIpV4Fragmentation, icmpIpV4Fragmentation,
icmpIpV4Ttl, icmpIpV4Protocol, icmpIpV4Ttl, icmpIpV4Protocol, null,
icmpIpV4SourceAddress, icmpIpV4DestinationAddress, icmpIpV4SourceAddress, icmpIpV4DestinationAddress,
icmpIpV4Options, icmpIpV4Payload.Length); icmpIpV4Options, icmpIpV4Payload.Length);
icmpIpV4Payload.Write(buffer, icmpOffset + IcmpDatagram.HeaderLength + icmpIpHeaderLength); icmpIpV4Payload.Write(buffer, icmpOffset + IcmpDatagram.HeaderLength + icmpIpHeaderLength);
...@@ -498,7 +498,7 @@ namespace PcapDotNet.Packets ...@@ -498,7 +498,7 @@ namespace PcapDotNet.Packets
EthernetDatagram.WriteHeader(buffer, 0, ethernetSource, ethernetDestination, EthernetType.IpV4); EthernetDatagram.WriteHeader(buffer, 0, ethernetSource, ethernetDestination, EthernetType.IpV4);
IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength, IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength,
ipV4TypeOfService, ipV4Identification, ipV4Fragmentation, ipV4TypeOfService, ipV4Identification, ipV4Fragmentation,
ipV4Ttl, IpV4Protocol.InternetGroupManagementProtocol, ipV4Ttl, IpV4Protocol.InternetGroupManagementProtocol, null,
ipV4SourceAddress, ipV4DestinationAddress, ipV4SourceAddress, ipV4DestinationAddress,
ipV4Options, igmpLength); ipV4Options, igmpLength);
IgmpDatagram.WriteQueryVersion3(buffer, EthernetDatagram.HeaderLength + ipHeaderLength, IgmpDatagram.WriteQueryVersion3(buffer, EthernetDatagram.HeaderLength + ipHeaderLength,
...@@ -536,7 +536,7 @@ namespace PcapDotNet.Packets ...@@ -536,7 +536,7 @@ namespace PcapDotNet.Packets
EthernetDatagram.WriteHeader(buffer, 0, ethernetSource, ethernetDestination, EthernetType.IpV4); EthernetDatagram.WriteHeader(buffer, 0, ethernetSource, ethernetDestination, EthernetType.IpV4);
IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength, IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength,
ipV4TypeOfService, ipV4Identification, ipV4Fragmentation, ipV4TypeOfService, ipV4Identification, ipV4Fragmentation,
ipV4Ttl, IpV4Protocol.InternetGroupManagementProtocol, ipV4Ttl, IpV4Protocol.InternetGroupManagementProtocol, null,
ipV4SourceAddress, ipV4DestinationAddress, ipV4SourceAddress, ipV4DestinationAddress,
ipV4Options, igmpLength); ipV4Options, igmpLength);
IgmpDatagram.WriteReportVersion3(buffer, EthernetDatagram.HeaderLength + ipHeaderLength, IgmpDatagram.WriteReportVersion3(buffer, EthernetDatagram.HeaderLength + ipHeaderLength,
...@@ -557,7 +557,7 @@ namespace PcapDotNet.Packets ...@@ -557,7 +557,7 @@ namespace PcapDotNet.Packets
EthernetDatagram.WriteHeader(buffer, 0, ethernetSource, ethernetDestination, EthernetType.IpV4); EthernetDatagram.WriteHeader(buffer, 0, ethernetSource, ethernetDestination, EthernetType.IpV4);
IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength, IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength,
ipV4TypeOfService, ipV4Identification, ipV4Fragmentation, ipV4TypeOfService, ipV4Identification, ipV4Fragmentation,
ipV4Ttl, IpV4Protocol.InternetGroupManagementProtocol, ipV4Ttl, IpV4Protocol.InternetGroupManagementProtocol, null,
ipV4SourceAddress, ipV4DestinationAddress, ipV4SourceAddress, ipV4DestinationAddress,
ipV4Options, IgmpDatagram.HeaderLength); ipV4Options, IgmpDatagram.HeaderLength);
IgmpDatagram.WriteHeader(buffer, EthernetDatagram.HeaderLength + ipHeaderLength, IgmpDatagram.WriteHeader(buffer, EthernetDatagram.HeaderLength + ipHeaderLength,
...@@ -601,7 +601,7 @@ namespace PcapDotNet.Packets ...@@ -601,7 +601,7 @@ namespace PcapDotNet.Packets
IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength, IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength,
ipV4TypeOfService, ipV4Identification, ipV4Fragmentation, ipV4TypeOfService, ipV4Identification, ipV4Fragmentation,
ipV4Ttl, IpV4Protocol.Udp, ipV4Ttl, IpV4Protocol.Udp, null,
ipV4SourceAddress, ipV4DestinationAddress, ipV4SourceAddress, ipV4DestinationAddress,
ipV4Options, transportLength); ipV4Options, transportLength);
...@@ -661,7 +661,7 @@ namespace PcapDotNet.Packets ...@@ -661,7 +661,7 @@ namespace PcapDotNet.Packets
IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength, IpV4Datagram.WriteHeader(buffer, EthernetDatagram.HeaderLength,
ipV4TypeOfService, ipV4Identification, ipV4Fragmentation, ipV4TypeOfService, ipV4Identification, ipV4Fragmentation,
ipV4Ttl, IpV4Protocol.Tcp, ipV4Ttl, IpV4Protocol.Tcp, null,
ipV4SourceAddress, ipV4DestinationAddress, ipV4SourceAddress, ipV4DestinationAddress,
ipV4Options, transportLength); ipV4Options, transportLength);
......
...@@ -185,6 +185,7 @@ namespace PcapDotNet.Packets ...@@ -185,6 +185,7 @@ namespace PcapDotNet.Packets
Fragmentation = IpV4Fragmentation.None; Fragmentation = IpV4Fragmentation.None;
Ttl = 0; Ttl = 0;
Protocol = null; Protocol = null;
HeaderChecksum = null;
Source = IpV4Address.Zero; Source = IpV4Address.Zero;
Destination = IpV4Address.Zero; Destination = IpV4Address.Zero;
Options = IpV4Options.None; Options = IpV4Options.None;
...@@ -200,6 +201,8 @@ namespace PcapDotNet.Packets ...@@ -200,6 +201,8 @@ namespace PcapDotNet.Packets
public IpV4Protocol? Protocol { get; set; } public IpV4Protocol? Protocol { get; set; }
public ushort? HeaderChecksum { get; set; }
public IpV4Address Source { get; set; } public IpV4Address Source { get; set; }
public IpV4Address Destination { get; set; } public IpV4Address Destination { get; set; }
...@@ -238,7 +241,7 @@ namespace PcapDotNet.Packets ...@@ -238,7 +241,7 @@ namespace PcapDotNet.Packets
IpV4Datagram.WriteHeader(buffer, offset, IpV4Datagram.WriteHeader(buffer, offset,
TypeOfService, Identification, Fragmentation, TypeOfService, Identification, Fragmentation,
Ttl, protocol, Ttl, protocol, HeaderChecksum,
Source, Destination, Source, Destination,
Options, payloadLength); Options, payloadLength);
} }
...@@ -1080,6 +1083,11 @@ namespace PcapDotNet.Packets ...@@ -1080,6 +1083,11 @@ namespace PcapDotNet.Packets
public class PacketBuilder2 public class PacketBuilder2
{ {
public static Packet Build(DateTime timestamp, params ILayer[] layers)
{
return new PacketBuilder2(layers).Build(timestamp);
}
public PacketBuilder2(params ILayer[] layers) public PacketBuilder2(params ILayer[] layers)
{ {
if (layers.Length == 0) if (layers.Length == 0)
......
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