Commit c6eb9f9c authored by Brickner_cp's avatar Brickner_cp

Code Coverage 96.30%

Fix DnsResourceDataNextDomain bug, which resulted in wrong results in IsTypePresentForOwner() and CreateTypeBitmap().
Add MtuProbe to the list of IPv4 option types, but no support for it yet.
Improve TCP tests.
parent 7a1d0333
...@@ -587,9 +587,9 @@ namespace PcapDotNet.Core.Test ...@@ -587,9 +587,9 @@ namespace PcapDotNet.Core.Test
} }
break; break;
case (IpV4OptionType)11: case IpV4OptionType.MtuProbe:
// TODO: Support 11. // TODO: Support MTU Proble.
field.AssertShow("MTU Probe (with option length = " + option.Length + " bytes; should be 4)"); Assert.IsTrue(field.Show().StartsWith("MTU Probe (" + option.Length + " bytes): "));
break; break;
case (IpV4OptionType)12: case (IpV4OptionType)12:
...@@ -610,8 +610,8 @@ namespace PcapDotNet.Core.Test ...@@ -610,8 +610,8 @@ namespace PcapDotNet.Core.Test
case (IpV4OptionType)134: case (IpV4OptionType)134:
// TODO: Support 134. // TODO: Support 134.
field.AssertShow("Commercial Security" + field.AssertShow("Commercial Security " +
(option.Length >= 10 ? string.Empty : " (with option length = " + option.Length + " bytes; should be >= 10)")); (option.Length >= 10 ? "(" + option.Length + " bytes)" : "(with option length = " + option.Length + " bytes; should be >= 10)"));
break; break;
case (IpV4OptionType)149: case (IpV4OptionType)149:
......
...@@ -260,6 +260,7 @@ namespace PcapDotNet.Packets.Test ...@@ -260,6 +260,7 @@ namespace PcapDotNet.Packets.Test
Assert.IsTrue(resourceData.IsTypePresentForOwner(DnsType.Aaaa)); Assert.IsTrue(resourceData.IsTypePresentForOwner(DnsType.Aaaa));
Assert.IsFalse(resourceData.IsTypePresentForOwner(DnsType.Ns)); Assert.IsFalse(resourceData.IsTypePresentForOwner(DnsType.Ns));
Assert.IsFalse(resourceData.IsTypePresentForOwner(DnsType.UInfo)); Assert.IsFalse(resourceData.IsTypePresentForOwner(DnsType.UInfo));
MoreAssert.AreSequenceEqual(new[] {DnsType.A, DnsType.Aaaa}, resourceData.TypesExist);
bitmap = DnsResourceDataNextDomain.CreateTypeBitmap(new DnsType[] { 0 }); bitmap = DnsResourceDataNextDomain.CreateTypeBitmap(new DnsType[] { 0 });
Assert.AreEqual(DataSegment.Empty, bitmap); Assert.AreEqual(DataSegment.Empty, bitmap);
......
...@@ -72,9 +72,6 @@ namespace PcapDotNet.Packets.Test ...@@ -72,9 +72,6 @@ namespace PcapDotNet.Packets.Test
PayloadLayer payloadLayer = random.NextPayloadLayer(random.Next(60000)); PayloadLayer payloadLayer = random.NextPayloadLayer(random.Next(60000));
if (i < 2)
continue;
Packet packet = PacketBuilder.Build(DateTime.Now, ethernetLayer, ipLayer, tcpLayer, payloadLayer); Packet packet = PacketBuilder.Build(DateTime.Now, ethernetLayer, ipLayer, tcpLayer, payloadLayer);
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
...@@ -104,7 +101,7 @@ namespace PcapDotNet.Packets.Test ...@@ -104,7 +101,7 @@ namespace PcapDotNet.Packets.Test
Assert.AreNotEqual(random.NextTcpLayer(), packet.Ethernet.Ip.Tcp.ExtractLayer(), "TCP Layer"); Assert.AreNotEqual(random.NextTcpLayer(), packet.Ethernet.Ip.Tcp.ExtractLayer(), "TCP Layer");
Assert.AreEqual(tcpLayer.GetHashCode(), packet.Ethernet.Ip.Tcp.ExtractLayer().GetHashCode(), "TCP Layer"); Assert.AreEqual(tcpLayer.GetHashCode(), packet.Ethernet.Ip.Tcp.ExtractLayer().GetHashCode(), "TCP Layer");
Assert.AreNotEqual(random.NextTcpLayer().GetHashCode(), packet.Ethernet.Ip.Tcp.ExtractLayer().GetHashCode(), "TCP Layer"); Assert.AreNotEqual(random.NextTcpLayer().GetHashCode(), packet.Ethernet.Ip.Tcp.ExtractLayer().GetHashCode(), "TCP Layer");
Assert.AreEqual(packet.Ethernet.Ip.Tcp.SequenceNumber + packet.Ethernet.Ip.Tcp.PayloadLength, packet.Ethernet.Ip.Tcp.NextSequenceNumber); Assert.AreEqual((uint)(packet.Ethernet.Ip.Tcp.SequenceNumber + packet.Ethernet.Ip.Tcp.PayloadLength), packet.Ethernet.Ip.Tcp.NextSequenceNumber);
foreach (TcpOption option in packet.Ethernet.Ip.Tcp.Options.OptionsCollection) foreach (TcpOption option in packet.Ethernet.Ip.Tcp.Options.OptionsCollection)
{ {
Assert.AreEqual(option, option); Assert.AreEqual(option, option);
......
...@@ -75,7 +75,8 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -75,7 +75,8 @@ namespace PcapDotNet.Packets.TestUtils
if (maximumOptionLength >= IpV4OptionUnknown.OptionMinimumLength && random.Next(100) > 90) if (maximumOptionLength >= IpV4OptionUnknown.OptionMinimumLength && random.Next(100) > 90)
return random.NextIpV4OptionUnknown(maximumOptionLength); return random.NextIpV4OptionUnknown(maximumOptionLength);
List<IpV4OptionType> impossibleOptionTypes = new List<IpV4OptionType>(); // TODO: Support MtuProbe.
List<IpV4OptionType> impossibleOptionTypes = new List<IpV4OptionType> {IpV4OptionType.MtuProbe};
if (maximumOptionLength < IpV4OptionBasicSecurity.OptionMinimumLength) if (maximumOptionLength < IpV4OptionBasicSecurity.OptionMinimumLength)
impossibleOptionTypes.Add(IpV4OptionType.BasicSecurity); impossibleOptionTypes.Add(IpV4OptionType.BasicSecurity);
if (maximumOptionLength < IpV4OptionRoute.OptionMinimumLength) if (maximumOptionLength < IpV4OptionRoute.OptionMinimumLength)
......
...@@ -213,7 +213,7 @@ namespace PcapDotNet.Packets.Dns ...@@ -213,7 +213,7 @@ namespace PcapDotNet.Packets.Dns
private static void DnsTypeToByteOffsetAndMask(out int byteOffset, out byte mask, DnsType dnsType) private static void DnsTypeToByteOffsetAndMask(out int byteOffset, out byte mask, DnsType dnsType)
{ {
byteOffset = (ushort)dnsType / 8; byteOffset = (ushort)dnsType / 8;
mask = (byte)(1 << ((ushort)dnsType % 8)); mask = (byte)(0x80 >> ((ushort)dnsType % 8));
} }
} }
} }
\ No newline at end of file
...@@ -56,11 +56,29 @@ namespace PcapDotNet.Packets.IpV4 ...@@ -56,11 +56,29 @@ namespace PcapDotNet.Packets.IpV4
/// </summary> /// </summary>
NoOperation = 1, NoOperation = 1,
/// <summary>
/// Record Route.
/// Used to trace the route an internet datagram takes.
/// </summary>
RecordRoute = 7,
/// <summary>
/// MTU Probe.
/// RFCs 1063, 1191.
/// Obsoleted.
/// </summary>
MtuProbe = 11,
/// <summary> /// <summary>
/// Quick Start (QS). RFC 4782. /// Quick Start (QS). RFC 4782.
/// </summary> /// </summary>
QuickStart = 25, QuickStart = 25,
/// <summary>
/// Internet Timestamp.
/// </summary>
InternetTimestamp = 68,
/// <summary> /// <summary>
/// Traceroute Using an IP Option. /// Traceroute Using an IP Option.
/// RFC 1393. /// RFC 1393.
...@@ -85,23 +103,12 @@ namespace PcapDotNet.Packets.IpV4 ...@@ -85,23 +103,12 @@ namespace PcapDotNet.Packets.IpV4
/// </summary> /// </summary>
StrictSourceRouting = 137, StrictSourceRouting = 137,
/// <summary>
/// Record Route.
/// Used to trace the route an internet datagram takes.
/// </summary>
RecordRoute = 7,
/// <summary> /// <summary>
/// Stream ID. /// Stream ID.
/// Used to carry the stream identifier. /// Used to carry the stream identifier.
/// </summary> /// </summary>
StreamIdentifier = 136, StreamIdentifier = 136,
/// <summary>
/// Internet Timestamp.
/// </summary>
InternetTimestamp = 68,
/// <summary> /// <summary>
/// Router Alert Option (RFC 2113). /// Router Alert Option (RFC 2113).
/// </summary> /// </summary>
......
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