Commit 31b0f4b1 authored by Boaz Brickner's avatar Boaz Brickner

Merge pull request #73 from bricknerb/master

Wireshark 1.12.8, IPv4 Large Segment Offload
parents 75d40918 12856808
...@@ -82,13 +82,35 @@ namespace PcapDotNet.Core.Test ...@@ -82,13 +82,35 @@ namespace PcapDotNet.Core.Test
Console.WriteLine("Seed: " + seed); Console.WriteLine("Seed: " + seed);
Random random = new Random(seed); Random random = new Random(seed);
for (int i = 0; i != 10; ++i) try
{ {
// Create packets for (int i = 0; i != 10; ++i)
List<Packet> packets = new List<Packet>(CreateRandomPackets(random, 200)); {
List<Packet> packets;
// Compare packets to wireshark try
ComparePacketsToWireshark(packets); {
// Create packets
packets = new List<Packet>(CreateRandomPackets(random, 200));
}
catch (Exception exception)
{
throw new AssertFailedException("Failed creating packets. " + exception, exception);
}
try
{
// Compare packets to wireshark
ComparePacketsToWireshark(packets);
}
catch (Exception exception)
{
throw new AssertFailedException("Failed comparing packets. " + exception, exception);
}
}
}
catch (Exception exception)
{
throw new AssertFailedException("Failed test with seed " + seed + ". " + exception, exception);
} }
} }
...@@ -102,7 +124,7 @@ namespace PcapDotNet.Core.Test ...@@ -102,7 +124,7 @@ namespace PcapDotNet.Core.Test
Packet packet = new Packet(new byte[14], timestamp, DataLinkKind.Ethernet); Packet packet = new Packet(new byte[14], timestamp, DataLinkKind.Ethernet);
// Compare packet to wireshark // Compare packet to wireshark
ComparePacketsToWireshark(new[] { packet }); ComparePacketsToWireshark(packet);
// BUG: Limited timestamp due to Windows bug: https://connect.microsoft.com/VisualStudio/feedback/details/559198/net-4-datetime-tolocaltime-is-sometimes-wrong // BUG: Limited timestamp due to Windows bug: https://connect.microsoft.com/VisualStudio/feedback/details/559198/net-4-datetime-tolocaltime-is-sometimes-wrong
// Now check different dates. // Now check different dates.
...@@ -495,9 +517,9 @@ namespace PcapDotNet.Core.Test ...@@ -495,9 +517,9 @@ namespace PcapDotNet.Core.Test
{ {
Compare(XDocument.Load(fixedDocumentFilename, LoadOptions.None), packets); Compare(XDocument.Load(fixedDocumentFilename, LoadOptions.None), packets);
} }
catch (AssertFailedException exception) catch (Exception exception)
{ {
throw new AssertFailedException("Failed comparing packets in file " + pcapFilename + ". Message: " + exception.Message, exception); throw new AssertFailedException("Failed comparing packets in file " + pcapFilename + ". " + exception, exception);
} }
} }
......
...@@ -4,6 +4,8 @@ using System.Reflection; ...@@ -4,6 +4,8 @@ using System.Reflection;
using System.Xml.Linq; using System.Xml.Linq;
using PcapDotNet.Base; using PcapDotNet.Base;
using PcapDotNet.Packets; using PcapDotNet.Packets;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.IpV6;
namespace PcapDotNet.Core.Test namespace PcapDotNet.Core.Test
{ {
...@@ -48,6 +50,10 @@ namespace PcapDotNet.Core.Test ...@@ -48,6 +50,10 @@ namespace PcapDotNet.Core.Test
bool success = true; bool success = true;
foreach (var element in layer.Fields()) foreach (var element in layer.Fields())
{ {
// TODO: Remove this hack when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=11802 is fixed.
IpV6Datagram ipV6ParentDatagram = parentDatagram as IpV6Datagram;
if (ipV6ParentDatagram != null && (ipV6ParentDatagram.NextHeader == IpV4Protocol.IsoIp || ipV6ParentDatagram.ExtensionHeaders.NextHeader == IpV4Protocol.IsoIp))
return false;
if (!CompareField(element, parentDatagram, datagram)) if (!CompareField(element, parentDatagram, datagram))
{ {
success = false; success = false;
......
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization;
using System.Linq; using System.Linq;
using System.Text;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Base; using PcapDotNet.Base;
using PcapDotNet.Packets; using PcapDotNet.Packets;
using PcapDotNet.Packets.Dns; using PcapDotNet.Packets.Dns;
using PcapDotNet.Packets.IpV6; using PcapDotNet.Packets.IpV6;
using PcapDotNet.TestUtils;
namespace PcapDotNet.Core.Test namespace PcapDotNet.Core.Test
{ {
...@@ -269,8 +265,7 @@ namespace PcapDotNet.Core.Test ...@@ -269,8 +265,7 @@ namespace PcapDotNet.Core.Test
{ {
_hipRendezvousServersIndex = 0; _hipRendezvousServersIndex = 0;
_wksBitmapIndex = 0; _wksBitmapIndex = 0;
// TODO: Uncomment this when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10615 is fixed. _nxtTypeIndex = 0;
// _nxtTypeIndex = 0;
_spfTypeIndex = 0; _spfTypeIndex = 0;
_txtTypeIndex = 0; _txtTypeIndex = 0;
_nSecTypeIndex = 0; _nSecTypeIndex = 0;
...@@ -893,12 +888,11 @@ namespace PcapDotNet.Core.Test ...@@ -893,12 +888,11 @@ namespace PcapDotNet.Core.Test
break; break;
case "": case "":
// TODO: Uncomment this when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10615 is fixed. DnsType actualType = nxtData.TypesExist.Skip(_nxtTypeIndex++).First();
// DnsType actualType = nxtData.TypesExist.Skip(_nxtTypeIndex++).First(); DnsType expectedType;
// DnsType expectedType; if (!TryGetDnsType(dataFieldShow, out expectedType))
// if (!TryGetDnsType(dataFieldShow, out expectedType)) throw new InvalidOperationException(string.Format("Can't parse DNS field {0} : {1}", dataFieldShow, actualType));
// throw new InvalidOperationException(string.Format("Can't parse DNS field {0} : {1}", dataFieldShow, actualType)); Assert.AreEqual(expectedType, actualType);
// Assert.AreEqual(expectedType, actualType);
return false; return false;
default: default:
...@@ -1864,8 +1858,7 @@ namespace PcapDotNet.Core.Test ...@@ -1864,8 +1858,7 @@ namespace PcapDotNet.Core.Test
private int _hipRendezvousServersIndex; private int _hipRendezvousServersIndex;
private int _wksBitmapIndex; private int _wksBitmapIndex;
// TODO: Uncomment this when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10615 is fixed. private int _nxtTypeIndex;
// private int _nxtTypeIndex;
private int _spfTypeIndex; private int _spfTypeIndex;
private int _txtTypeIndex; private int _txtTypeIndex;
private int _nSecTypeIndex; private int _nSecTypeIndex;
......
...@@ -36,7 +36,8 @@ namespace PcapDotNet.Core.Test ...@@ -36,7 +36,8 @@ namespace PcapDotNet.Core.Test
field.AssertNoShow(); field.AssertNoShow();
MoreAssert.AreSequenceEqual(httpDatagram.Subsegment(0, _data.Length / 2), HexEncoding.Instance.GetBytes(_data.ToString())); MoreAssert.AreSequenceEqual(httpDatagram.Subsegment(0, _data.Length / 2), HexEncoding.Instance.GetBytes(_data.ToString()));
// TODO: Uncomment once https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10707 is fixed. Assert.AreEqual(httpDatagram.Subsegment(_data.Length / 2 + 2, httpDatagram.Length - _data.Length / 2 - 2).ToHexadecimalString(), field.Value().Substring(0, 2 * (httpDatagram.Length - _data.Length / 2 - 2)));
// TODO: Uncomment instead of the above line once https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=11801 is fixed.
// field.AssertValue(httpDatagram.Subsegment(_data.Length / 2 + 2, httpDatagram.Length - _data.Length / 2 - 2)); // field.AssertValue(httpDatagram.Subsegment(_data.Length / 2 + 2, httpDatagram.Length - _data.Length / 2 - 2));
return false; return false;
} }
......
...@@ -7,6 +7,7 @@ using PcapDotNet.Packets; ...@@ -7,6 +7,7 @@ using PcapDotNet.Packets;
using PcapDotNet.Packets.Icmp; using PcapDotNet.Packets.Icmp;
using PcapDotNet.Packets.IpV4; using PcapDotNet.Packets.IpV4;
using System.Linq; using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace PcapDotNet.Core.Test namespace PcapDotNet.Core.Test
{ {
...@@ -47,24 +48,37 @@ namespace PcapDotNet.Core.Test ...@@ -47,24 +48,37 @@ namespace PcapDotNet.Core.Test
var icmpIpV4PayloadDatagram = icmpDatagram as IcmpIpV4PayloadDatagram; var icmpIpV4PayloadDatagram = icmpDatagram as IcmpIpV4PayloadDatagram;
if (icmpIpV4PayloadDatagram != null) if (icmpIpV4PayloadDatagram != null)
{ {
if (!new[] IpV4Datagram ipV4 = icmpIpV4PayloadDatagram.IpV4;
{ switch (ipV4.Protocol)
IpV4Protocol.IpComp, // TODO: Support IpComp.
IpV4Protocol.Ax25, // TODO: Support Ax25.
IpV4Protocol.FibreChannel, // TODO: Support FibreChannel.
}.Contains(icmpIpV4PayloadDatagram.IpV4.Protocol))
{ {
if (icmpIpV4PayloadDatagram.IpV4.Protocol == IpV4Protocol.Udp) case IpV4Protocol.Ip:
{ if (ipV4.Payload.Length < IpV4Datagram.HeaderMinimumLength)
field.AssertDataField(ipV4.Payload);
else
field.AssertDataField(ipV4.IpV4.Payload);
break;
case IpV4Protocol.Udp:
// Uncomment this when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10990 is fixed. // Uncomment this when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10990 is fixed.
// field.AssertDataField(casted1.IpV4.Udp.Payload); // field.AssertDataField(casted1.IpV4.Udp.Payload);
} break;
else
{ case IpV4Protocol.IpComp: // TODO: Support IpComp.
// TODO: Remove this condition when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10991 and https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10992 are fixed. case IpV4Protocol.Ax25: // TODO: Support Ax25.
if (!(icmpIpV4PayloadDatagram is IcmpParameterProblemDatagram || icmpIpV4PayloadDatagram is IcmpRedirectDatagram)) case IpV4Protocol.FibreChannel: // TODO: Support FibreChannel.
field.AssertDataField(icmpIpV4PayloadDatagram.IpV4.Payload); case IpV4Protocol.MultiprotocolLabelSwitchingInIp: // TODO: Support MPLS.
} case IpV4Protocol.EtherIp: // TODO: Support EtherIP.
case IpV4Protocol.LayerTwoTunnelingProtocol: // TODO: Support LayerTwoTunnelingProtocol.
case IpV4Protocol.AuthenticationHeader: // TODO: Support Authentication Header over IPv4.
break;
default:
if (icmpIpV4PayloadDatagram is IcmpIpV4HeaderPlus64BitsPayloadDatagram && field.Value().Length > 2 * 8)
Assert.AreEqual(ipV4.Payload.BytesSequenceToHexadecimalString(), field.Value().Substring(0, 2 * 8));
else
field.AssertDataField(ipV4.Payload);
break;
} }
} }
else else
...@@ -175,8 +189,9 @@ namespace PcapDotNet.Core.Test ...@@ -175,8 +189,9 @@ namespace PcapDotNet.Core.Test
case "icmp.resptime": case "icmp.resptime":
break; break;
// TODO: Remove this case when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10939 is fixed.
case "icmp.length": case "icmp.length":
// TODO: Uncomment this case when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10939 is fixed.
// field.AssertShowDecimal(((IcmpParameterProblemDatagram)icmpDatagram).OriginalDatagramLength);
break; break;
default: default:
......
...@@ -35,6 +35,11 @@ namespace PcapDotNet.Core.Test ...@@ -35,6 +35,11 @@ namespace PcapDotNet.Core.Test
break; break;
case "igmp.maddr": case "igmp.maddr":
if (igmpDatagram.MessageType == IgmpMessageType.MulticastTraceRoute)
{
// TODO: Support IGMP Traceroute request.
break;
}
field.AssertShow(igmpDatagram.GroupAddress.ToString()); field.AssertShow(igmpDatagram.GroupAddress.ToString());
break; break;
...@@ -72,8 +77,7 @@ namespace PcapDotNet.Core.Test ...@@ -72,8 +77,7 @@ namespace PcapDotNet.Core.Test
case "Data": case "Data":
if (field.Value().Length > 0) if (field.Value().Length > 0)
{ {
// TODO: Change following https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=11582 field.AssertValue(igmpDatagram.Skip(1));
field.AssertValue(field.Value().Length / 2 == igmpDatagram.Length - 21 ? igmpDatagram.Skip(21) : igmpDatagram.Skip(1));
} }
break; break;
...@@ -120,7 +124,8 @@ namespace PcapDotNet.Core.Test ...@@ -120,7 +124,8 @@ namespace PcapDotNet.Core.Test
break; break;
case "igmp.reply.pending": case "igmp.reply.pending":
field.AssertShowDecimal(igmpDatagram.RetryInThisManySeconds); if (!new[] {IgmpMessageType.None, (IgmpMessageType)12}.Contains(igmpDatagram.MessageType))
field.AssertShowDecimal(igmpDatagram.RetryInThisManySeconds);
break; break;
case "igmp.group_type": case "igmp.group_type":
......
...@@ -40,7 +40,7 @@ namespace PcapDotNet.Core.Test ...@@ -40,7 +40,7 @@ namespace PcapDotNet.Core.Test
break; break;
case "ip.len": case "ip.len":
field.AssertShowDecimal(ipV4Datagram.TotalLength); field.AssertShowDecimal(ipV4Datagram.TotalLength == 0 ? ipV4Datagram.Length : ipV4Datagram.TotalLength);
field.AssertNoFields(); field.AssertNoFields();
break; break;
...@@ -188,6 +188,7 @@ namespace PcapDotNet.Core.Test ...@@ -188,6 +188,7 @@ namespace PcapDotNet.Core.Test
Assert.IsFalse(options.IsValid); Assert.IsFalse(options.IsValid);
Assert.IsTrue(field.Show() == "Commercial IP security option" || Assert.IsTrue(field.Show() == "Commercial IP security option" ||
field.Show() == "Loose source route (length byte past end of options)" || field.Show() == "Loose source route (length byte past end of options)" ||
field.Show() == "Loose Source Route (5 bytes)" ||
field.Show() == "Time stamp:" || field.Show() == "Time stamp:" ||
field.Show().StartsWith("Unknown") || field.Show().StartsWith("Unknown") ||
field.Show().StartsWith("Security") || field.Show().StartsWith("Security") ||
......
using System; using System;
using System.Collections.Generic;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Globalization; using System.Globalization;
using System.Linq; using System.Linq;
using System.Xml.Linq; using System.Xml.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Base;
using PcapDotNet.Packets; using PcapDotNet.Packets;
using PcapDotNet.Packets.IpV4; using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.IpV6; using PcapDotNet.Packets.IpV6;
...@@ -32,9 +32,6 @@ namespace PcapDotNet.Core.Test ...@@ -32,9 +32,6 @@ namespace PcapDotNet.Core.Test
switch (field.Name()) switch (field.Name())
{ {
case "ipv6.version": case "ipv6.version":
// TODO: Remove this when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10706 is fixed.
if (field.Show() != ipV6Datagram.Version.ToString())
return false;
field.AssertShowDecimal(ipV6Datagram.Version); field.AssertShowDecimal(ipV6Datagram.Version);
foreach (XElement subfield in field.Fields()) foreach (XElement subfield in field.Fields())
{ {
...@@ -190,18 +187,64 @@ namespace PcapDotNet.Core.Test ...@@ -190,18 +187,64 @@ namespace PcapDotNet.Core.Test
headerField.AssertNumFields(1); headerField.AssertNumFields(1);
headerField.Fields().First().AssertName("_ws.expert"); headerField.Fields().First().AssertName("_ws.expert");
} }
// TODO: Uncomment when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10560 is fixed. // TODO: Remove this condition when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=11803 is fixed.
// headerField.AssertShowDecimal(routingProtocolLowPowerAndLossyNetworks.Addresses.Count); if (routingProtocolLowPowerAndLossyNetworks.Addresses.Count > 0)
{
headerField.AssertShowDecimal(routingProtocolLowPowerAndLossyNetworks.Addresses.Count);
}
break; break;
case "ipv6.routing_hdr.rpl.address": case "ipv6.routing_hdr.rpl.address":
headerField.AssertNoFields(); headerField.AssertNoFields();
// TODO: Implement when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10560 is fixed. // TODO: Remove this condition when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=11803 is fixed.
if (routingProtocolLowPowerAndLossyNetworks.Addresses.Count > 0)
{
IpV6Address actualAddress =
new IpV6Address(UInt128.Parse(headerField.Value(), NumberStyles.HexNumber, CultureInfo.InvariantCulture));
Assert.AreEqual(routingProtocolLowPowerAndLossyNetworks.Addresses[routingProtocolLowPowerAndLossyNetworksAddressIndex],
actualAddress);
}
break; break;
case "ipv6.routing_hdr.rpl.full_address": case "ipv6.routing_hdr.rpl.full_address":
headerField.AssertNoFields(); headerField.AssertNoFields();
// TODO: Implement when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10673 is fixed. // TODO: Uncomment the following code when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10673 is fixed.
// // TODO: Remove this condition when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=11803 is fixed.
// if (routingProtocolLowPowerAndLossyNetworks.Addresses.Count > 0)
// {
// IpV6Address actualFullAddress = new IpV6Address(headerField.Show());
//
// IpV6Address destinationAddress = ipV6Datagram.CurrentDestination;
// for (int i = 0; i < _currentExtensionHeaderIndex; ++i)
// {
// IpV6ExtensionHeaderRoutingHomeAddress ipV6ExtensionHeaderRoutingHomeAddress =
// ipV6Datagram.ExtensionHeaders[i] as IpV6ExtensionHeaderRoutingHomeAddress;
// if (ipV6ExtensionHeaderRoutingHomeAddress != null)
// destinationAddress = ipV6ExtensionHeaderRoutingHomeAddress.HomeAddress;
//
// IpV6ExtensionHeaderRoutingSourceRoute ipV6ExtensionHeaderRoutingSourceRoute =
// ipV6Datagram.ExtensionHeaders[i] as IpV6ExtensionHeaderRoutingSourceRoute;
// if (ipV6ExtensionHeaderRoutingSourceRoute != null && ipV6ExtensionHeaderRoutingSourceRoute.Addresses.Any())
// destinationAddress = ipV6ExtensionHeaderRoutingSourceRoute.Addresses.Last();
// }
//
// int commonPrefixLength =
// routingProtocolLowPowerAndLossyNetworksAddressIndex == routingProtocolLowPowerAndLossyNetworks.Addresses.Count - 1
// ? routingProtocolLowPowerAndLossyNetworks.CommonPrefixLengthForLastAddress
// : routingProtocolLowPowerAndLossyNetworks.CommonPrefixLengthForNonLastAddresses;
//
// byte[] destinationAddressBytes = new byte[IpV6Address.SizeOf];
// destinationAddressBytes.Write(0, destinationAddress, Endianity.Big);
//
// byte[] routingAddressBytes = new byte[IpV6Address.SizeOf];
// routingAddressBytes.Write(0, routingProtocolLowPowerAndLossyNetworks.Addresses[routingProtocolLowPowerAndLossyNetworksAddressIndex], Endianity.Big);
//
// byte[] fullAddressBytes = destinationAddressBytes.Subsegment(0, commonPrefixLength).Concat(routingAddressBytes.Subsegment(commonPrefixLength, IpV6Address.SizeOf - commonPrefixLength)).ToArray();
// IpV6Address expectedFullAddress = fullAddressBytes.ReadIpV6Address(0, Endianity.Big);
//
// Assert.AreEqual(expectedFullAddress, actualFullAddress);
// }
++routingProtocolLowPowerAndLossyNetworksAddressIndex; ++routingProtocolLowPowerAndLossyNetworksAddressIndex;
break; break;
......
...@@ -653,7 +653,7 @@ namespace PcapDotNet.Core.Test ...@@ -653,7 +653,7 @@ namespace PcapDotNet.Core.Test
"Invalid IPv6 Link Layer Address option field {0}", optionSubfield.Name())); "Invalid IPv6 Link Layer Address option field {0}", optionSubfield.Name()));
} }
} }
// TODO: Change to break when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10043 or https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10627 is fixed. // TODO: Change to break when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10627 is fixed.
return false; return false;
case IpV6MobilityOptionType.IpV4DefaultRouterAddress: case IpV6MobilityOptionType.IpV4DefaultRouterAddress:
...@@ -1492,8 +1492,7 @@ namespace PcapDotNet.Core.Test ...@@ -1492,8 +1492,7 @@ namespace PcapDotNet.Core.Test
break; break;
case "mip6.auth.auth_data": case "mip6.auth.auth_data":
// TODO: Uncomment when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10626 is fixed. optionSubfield.AssertValue(authentication.AuthenticationData);
// optionSubfield.AssertValue(authentication.AuthenticationData);
break; break;
default: default:
...@@ -1601,13 +1600,11 @@ namespace PcapDotNet.Core.Test ...@@ -1601,13 +1600,11 @@ namespace PcapDotNet.Core.Test
break; break;
case "mip6.lmaa.ipv6": case "mip6.lmaa.ipv6":
// TODO: Uncomment when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10961 is fixed. optionSubfield.AssertValue(localMobilityAnchorAddress.LocalMobilityAnchorAddressIpV6.Value.ToValue());
// optionSubfield.AssertValue(localMobilityAnchorAddress.LocalMobilityAnchorAddressIpV6.Value.ToValue());
break; break;
case "mip6.lmaa.ipv4": case "mip6.lmaa.ipv4":
// TODO: Uncomment when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10961 is fixed. optionSubfield.AssertShow(localMobilityAnchorAddress.LocalMobilityAnchorAddressIpV4.Value.ToString());
// optionSubfield.AssertShow(localMobilityAnchorAddress.LocalMobilityAnchorAddressIpV4.Value.ToString());
break; break;
default: default:
......
...@@ -194,7 +194,9 @@ namespace PcapDotNet.Core.Test ...@@ -194,7 +194,9 @@ namespace PcapDotNet.Core.Test
{ {
case "tcp.checksum_good": case "tcp.checksum_good":
checksumField.AssertNoFields(); checksumField.AssertNoFields();
checksumField.AssertShowDecimal(tcpDatagram.Checksum != 0 && ipDatagram.IsTransportChecksumCorrect); // TODO: Remove this condition when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=11857 is fixed.
if (!field.Showname().EndsWith(" [unchecked, not all data available]"))
checksumField.AssertShowDecimal(tcpDatagram.Checksum != 0 && ipDatagram.IsTransportChecksumCorrect);
break; break;
case "tcp.checksum_bad": case "tcp.checksum_bad":
...@@ -268,6 +270,7 @@ namespace PcapDotNet.Core.Test ...@@ -268,6 +270,7 @@ namespace PcapDotNet.Core.Test
field.Show().StartsWith("Unknown (0x0a) ") || // Unknown in Wireshark but known (and invalid) in Pcap.Net. field.Show().StartsWith("Unknown (0x0a) ") || // Unknown in Wireshark but known (and invalid) in Pcap.Net.
field.Show().StartsWith("Unknown (0x19) ") || // Unknown in Wireshark but known (and invalid) in Pcap.Net. field.Show().StartsWith("Unknown (0x19) ") || // Unknown in Wireshark but known (and invalid) in Pcap.Net.
field.Show().StartsWith("Unknown (0x2d) ") || // Unknown in Wireshark and unknown and invalid in Pcap.Net. field.Show().StartsWith("Unknown (0x2d) ") || // Unknown in Wireshark and unknown and invalid in Pcap.Net.
field.Show().StartsWith("Unknown (0x84) ") || // Unknown in Wireshark and unknown and invalid in Pcap.Net.
field.Show().StartsWith("Unknown (0xa9) ") || // Unknown in Wireshark and unknown and invalid in Pcap.Net. field.Show().StartsWith("Unknown (0xa9) ") || // Unknown in Wireshark and unknown and invalid in Pcap.Net.
field.Show().StartsWith("Echo reply (with option length = ") || field.Show().StartsWith("Echo reply (with option length = ") ||
field.Show().Contains("bytes says option goes past end of options") || field.Show().Contains("bytes says option goes past end of options") ||
......
...@@ -55,6 +55,7 @@ namespace PcapDotNet.Core.Test ...@@ -55,6 +55,7 @@ namespace PcapDotNet.Core.Test
{ {
(EthernetType)1, (EthernetType)1,
(EthernetType)5, (EthernetType)5,
(EthernetType)12,
(EthernetType)17, (EthernetType)17,
(EthernetType)29, (EthernetType)29,
(EthernetType)30, (EthernetType)30,
......
using System; using System;
using System.Collections.ObjectModel;
using System.Diagnostics.CodeAnalysis; using System.Diagnostics.CodeAnalysis;
using System.Linq; using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting; using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Base;
using PcapDotNet.Packets.Arp;
using PcapDotNet.Packets.Ethernet; using PcapDotNet.Packets.Ethernet;
using PcapDotNet.Packets.IpV4; using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.IpV6; using PcapDotNet.Packets.IpV6;
...@@ -132,5 +135,23 @@ namespace PcapDotNet.Packets.Test ...@@ -132,5 +135,23 @@ namespace PcapDotNet.Packets.Test
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
Assert.AreEqual(DataSegment.Empty, packet.Ethernet.Padding); Assert.AreEqual(DataSegment.Empty, packet.Ethernet.Padding);
} }
[TestMethod]
public void PayloadTooBigForPadding()
{
Packet packet = PacketBuilder.Build(DateTime.Now,
new EthernetLayer(),
new ArpLayer
{
ProtocolType = EthernetType.IpV4,
Operation = ArpOperation.DynamicReverseError,
SenderHardwareAddress = new byte[12].AsReadOnly(),
SenderProtocolAddress = new byte[22].AsReadOnly(),
TargetHardwareAddress = new byte[12].AsReadOnly(),
TargetProtocolAddress = new byte[22].AsReadOnly(),
});
Assert.IsTrue(packet.IsValid);
Assert.AreEqual(DataSegment.Empty, packet.Ethernet.Padding);
}
} }
} }
\ No newline at end of file
...@@ -143,7 +143,7 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -143,7 +143,7 @@ namespace PcapDotNet.Packets.TestUtils
random.NextUInt(), random.NextUInt(), random.NextUInt(), random.NextUInt(), random.NextUInt()); random.NextUInt(), random.NextUInt(), random.NextUInt(), random.NextUInt(), random.NextUInt());
case DnsType.Null: case DnsType.Null:
return new DnsResourceDataAnything(random.NextDataSegment(random.Next(65536))); return new DnsResourceDataAnything(random.NextDataSegment(random.Next(1000)));
case DnsType.WellKnownService: case DnsType.WellKnownService:
return new DnsResourceDataWellKnownService(random.NextIpV4Address(), random.NextEnum<IpV4Protocol>(), return new DnsResourceDataWellKnownService(random.NextIpV4Address(), random.NextEnum<IpV4Protocol>(),
......
...@@ -45,9 +45,11 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -45,9 +45,11 @@ namespace PcapDotNet.Packets.Ethernet
if (payloadByEtherType == null) if (payloadByEtherType == null)
return null; return null;
int payloadLength = PayloadByEtherType.Length; int payloadLength = payloadByEtherType.Length;
int dataLength = HeaderLength + payloadLength;
return new DataSegment(Buffer, StartOffset + HeaderLength + payloadLength, 60 - HeaderLength - payloadLength); if (dataLength >= 60)
return DataSegment.Empty;
return new DataSegment(Buffer, StartOffset + dataLength, 60 - dataLength);
} }
} }
...@@ -106,7 +108,7 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -106,7 +108,7 @@ namespace PcapDotNet.Packets.Ethernet
if (payloadByEtherType == null) if (payloadByEtherType == null)
return null; return null;
int payloadLength = PayloadByEtherType.Length; int payloadLength = payloadByEtherType.Length;
return new DataSegment(Buffer, StartOffset + HeaderLength + payloadLength, Length - HeaderLength - payloadLength); return new DataSegment(Buffer, StartOffset + HeaderLength + payloadLength, Length - HeaderLength - payloadLength);
} }
} }
......
...@@ -309,10 +309,7 @@ namespace PcapDotNet.Packets.Http ...@@ -309,10 +309,7 @@ namespace PcapDotNet.Packets.Http
if (chunkSizeValue == 0) if (chunkSizeValue == 0)
{ {
int? endOffset; int? endOffset;
// HttpHeader trailerHeader = new HttpHeader( GetHeaderFields(out endOffset, buffer, parser.Offset, offset + length - parser.Offset);
GetHeaderFields(out endOffset, buffer, parser.Offset, offset + length - parser.Offset)
// )
;
if (endOffset != null) if (endOffset != null)
parser.Skip(endOffset.Value - parser.Offset); parser.Skip(endOffset.Value - parser.Offset);
break; break;
...@@ -332,7 +329,6 @@ namespace PcapDotNet.Packets.Http ...@@ -332,7 +329,6 @@ namespace PcapDotNet.Packets.Http
datagram.Write(contentBuffer, contentBufferOffset); datagram.Write(contentBuffer, contentBufferOffset);
contentBufferOffset += datagram.Length; contentBufferOffset += datagram.Length;
} }
// Datagram content = new Datagram(contentBuffer);
return new Datagram(buffer, offset, parser.Offset - offset); return new Datagram(buffer, offset, parser.Offset - offset);
} }
......
...@@ -245,8 +245,11 @@ namespace PcapDotNet.Packets.IpV4 ...@@ -245,8 +245,11 @@ namespace PcapDotNet.Packets.IpV4
return ipV4Datagram.Length; return ipV4Datagram.Length;
ushort totalLength = ReadTotalLength(ipV4Datagram); ushort totalLength = ReadTotalLength(ipV4Datagram);
if (ipV4Datagram.Length < totalLength) if (ipV4Datagram.Length < totalLength ||
totalLength == 0) // Large segment offload.
{
return ipV4Datagram.Length; return ipV4Datagram.Length;
}
return totalLength; return totalLength;
} }
......
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