Commit 10552b97 authored by Brickner_cp's avatar Brickner_cp

Wireshark 1.12.1.

Add Padding property to EthernetDatagram (in addition to Trailer and FrameCheckSequence).
Rename TrailerWithFrameCheckSequence to ExtraData.
More complete documentation of HttpDatagram format.
parent b9a4771a
...@@ -26,19 +26,23 @@ namespace PcapDotNet.Core.Test ...@@ -26,19 +26,23 @@ namespace PcapDotNet.Core.Test
break; break;
case "eth.type": case "eth.type":
field.AssertNoFields();
field.AssertShowDecimal((ushort)ethernetDatagram.EtherType); field.AssertShowDecimal((ushort)ethernetDatagram.EtherType);
break; break;
case "eth.trailer": case "eth.trailer":
if (ethernetDatagram.Trailer != null)
field.AssertValue(ethernetDatagram.Trailer); field.AssertValue(ethernetDatagram.Trailer);
break; break;
case "": case "eth.fcs":
if (ethernetDatagram.Trailer != null)
field.AssertValue(ethernetDatagram.FrameCheckSequence); field.AssertValue(ethernetDatagram.FrameCheckSequence);
break; break;
case "eth.padding":
field.AssertNoFields();
field.AssertValue(ethernetDatagram.Padding);
break;
default: default:
throw new InvalidOperationException("Invalid etherent field " + field.Name()); throw new InvalidOperationException("Invalid etherent field " + field.Name());
} }
......
...@@ -184,7 +184,8 @@ namespace PcapDotNet.Core.Test ...@@ -184,7 +184,8 @@ namespace PcapDotNet.Core.Test
break; break;
case "http.request.full_uri": case "http.request.full_uri":
Assert.AreEqual(fieldShow, ("http://" + httpDatagram.Header["Host"].ValueString + ((HttpRequestDatagram)httpDatagram).Uri).ToWiresharkLiteral()); // TODO: Uncomment when https://bugs.wireshark.org/bugzilla/show_bug.cgi?id=10681 is fixed.
// Assert.AreEqual(fieldShow, ("http://" + httpDatagram.Header["Host"].ValueString + ((HttpRequestDatagram)httpDatagram).Uri).ToWiresharkLiteral());
break; break;
default: default:
......
...@@ -432,7 +432,7 @@ namespace PcapDotNet.Core.Test ...@@ -432,7 +432,7 @@ namespace PcapDotNet.Core.Test
case IpV4OptionType.RouterAlert: case IpV4OptionType.RouterAlert:
var routerAlert = (IpV4OptionRouterAlert)option; var routerAlert = (IpV4OptionRouterAlert)option;
field.AssertShow("Router Alert (" + option.Length + " bytes): " + field.AssertShow("Router Alert (" + option.Length + " bytes): " +
((routerAlert.Value != 0) ? "Reserved (" + routerAlert.Value + ")" : "Every router examines packet")); ((routerAlert.Value != 0) ? "Reserved (" + routerAlert.Value + ")" : "Router shall examine packet (0)"));
foreach (var subfield in field.Fields()) foreach (var subfield in field.Fields())
{ {
if (HandleCommonOptionSubfield(subfield, option)) if (HandleCommonOptionSubfield(subfield, option))
...@@ -606,6 +606,14 @@ namespace PcapDotNet.Core.Test ...@@ -606,6 +606,14 @@ namespace PcapDotNet.Core.Test
field.AssertShow("MTU Probe (with option length = " + option.Length + " bytes; should be 4)"); field.AssertShow("MTU Probe (with option length = " + option.Length + " bytes; should be 4)");
break; break;
case (IpV4OptionType)12:
// TODO: Support 12.
if (option.Length != 4)
field.AssertShow("MTU Reply (with option length = " + option.Length + " bytes; should be 4)");
else
Assert.IsTrue(field.Show().StartsWith("MTU Reply (4 bytes): "));
break;
case (IpV4OptionType)133: case (IpV4OptionType)133:
// TODO: Support 133. // TODO: Support 133.
field.AssertShow("Extended Security (" + option.Length + " bytes)"); field.AssertShow("Extended Security (" + option.Length + " bytes)");
......
...@@ -1870,7 +1870,8 @@ namespace PcapDotNet.Core.Test ...@@ -1870,7 +1870,8 @@ namespace PcapDotNet.Core.Test
break; break;
case IpV6MobilityOptionType.Experimental: case IpV6MobilityOptionType.Experimental:
optionField.AssertShow("Experimental"); optionField.AssertShow("Experimental" +
(option.Length == 2 ? " (with option length = 0 bytes; should be >= 1)" : ""));
var experimental = (IpV6MobilityOptionExperimental)option; var experimental = (IpV6MobilityOptionExperimental)option;
foreach (XElement optionSubfield in optionField.Fields()) foreach (XElement optionSubfield in optionField.Fields())
{ {
......
...@@ -196,14 +196,21 @@ namespace PcapDotNet.Core.Test ...@@ -196,14 +196,21 @@ namespace PcapDotNet.Core.Test
switch (checksumField.Name()) switch (checksumField.Name())
{ {
case "tcp.checksum_good": case "tcp.checksum_good":
checksumField.AssertNoFields();
checksumField.AssertShowDecimal(tcpDatagram.Checksum != 0 && ipDatagram.IsTransportChecksumCorrect); checksumField.AssertShowDecimal(tcpDatagram.Checksum != 0 && ipDatagram.IsTransportChecksumCorrect);
break; break;
case "tcp.checksum_bad": case "tcp.checksum_bad":
checksumField.AssertShowDecimal(tcpDatagram.Checksum != 0 && !ipDatagram.IsTransportChecksumCorrect); checksumField.AssertShowDecimal(!ipDatagram.IsTransportChecksumCorrect);
if (checksumField.Fields().Any())
{
checksumField.AssertNumFields(1);
checksumField.Fields().First().AssertName("_ws.expert");
}
break; break;
case "tcp.checksum_calculated": case "tcp.checksum_calculated":
checksumField.AssertNoFields();
if (ipDatagram.IsTransportChecksumCorrect) if (ipDatagram.IsTransportChecksumCorrect)
checksumField.AssertShowDecimal(tcpDatagram.Checksum); checksumField.AssertShowDecimal(tcpDatagram.Checksum);
break; break;
...@@ -211,7 +218,6 @@ namespace PcapDotNet.Core.Test ...@@ -211,7 +218,6 @@ namespace PcapDotNet.Core.Test
default: default:
throw new InvalidOperationException("Invalid checksum field name " + checksumField.Name()); throw new InvalidOperationException("Invalid checksum field name " + checksumField.Name());
} }
checksumField.AssertNoFields();
} }
} }
break; break;
...@@ -259,6 +265,7 @@ namespace PcapDotNet.Core.Test ...@@ -259,6 +265,7 @@ namespace PcapDotNet.Core.Test
{ {
Assert.IsFalse(options.IsValid, "Options IsValid"); Assert.IsFalse(options.IsValid, "Options IsValid");
Assert.IsTrue( Assert.IsTrue(
field.Show().StartsWith("Unknown (0x09) ") || // 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 (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("Echo reply (with option length = ") || field.Show().StartsWith("Echo reply (with option length = ") ||
...@@ -483,6 +490,11 @@ namespace PcapDotNet.Core.Test ...@@ -483,6 +490,11 @@ namespace PcapDotNet.Core.Test
} }
break; break;
case (TcpOptionType)22:
field.AssertShow("SCPS record boundary (with option length = " + option.Length + " bytes; should be 2)");
// TODO: Support 22.
break;
case (TcpOptionType)23: case (TcpOptionType)23:
field.AssertShow("SCPS corruption experienced (with option length = " + option.Length + " bytes; should be 2)"); field.AssertShow("SCPS corruption experienced (with option length = " + option.Length + " bytes; should be 2)");
// TODO: Support 23. // TODO: Support 23.
......
...@@ -51,7 +51,12 @@ namespace PcapDotNet.Core.Test ...@@ -51,7 +51,12 @@ namespace PcapDotNet.Core.Test
(EthernetType)1, (EthernetType)5, (EthernetType)17, (EthernetType)29, (EthernetType)30, (EthernetType)43, (EthernetType)50, EthernetType.ReverseArp, (EthernetType)1, (EthernetType)5, (EthernetType)17, (EthernetType)29, (EthernetType)30, (EthernetType)43, (EthernetType)50, EthernetType.ReverseArp,
}.Contains( }.Contains(
vLanTaggedFrameDatagram.EtherType)) vLanTaggedFrameDatagram.EtherType))
field.AssertValue(vLanTaggedFrameDatagram.TrailerWithFrameCheckSequence); field.AssertValue(vLanTaggedFrameDatagram.ExtraData);
break;
case "eth.padding":
field.AssertNoFields();
field.AssertValue(vLanTaggedFrameDatagram.Trailer);
break; break;
default: default:
......
...@@ -109,9 +109,10 @@ namespace PcapDotNet.Packets.Test ...@@ -109,9 +109,10 @@ namespace PcapDotNet.Packets.Test
Data = new Datagram(new byte[100]) Data = new Datagram(new byte[100])
}); });
Assert.IsTrue(packet.IsValid); Assert.IsTrue(packet.IsValid);
Assert.IsNull(packet.Ethernet.TrailerWithFrameCheckSequence); Assert.IsNull(packet.Ethernet.Padding);
Assert.IsNull(packet.Ethernet.Trailer); Assert.IsNull(packet.Ethernet.Trailer);
Assert.IsNull(packet.Ethernet.FrameCheckSequence); Assert.IsNull(packet.Ethernet.FrameCheckSequence);
Assert.IsNull(packet.Ethernet.ExtraData);
} }
} }
} }
\ No newline at end of file
...@@ -481,7 +481,7 @@ namespace PcapDotNet.Packets.Test ...@@ -481,7 +481,7 @@ namespace PcapDotNet.Packets.Test
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)] [ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
public void IpV4OptionQuickStartBadNonceTest() public void IpV4OptionQuickStartBadNonceTest()
{ {
IpV4OptionQuickStart option = new IpV4OptionQuickStart(IpV4OptionQuickStartFunction.RateRequest, 1, 1, 2); IpV4OptionQuickStart option = new IpV4OptionQuickStart(IpV4OptionQuickStartFunction.RateRequest, 1, 1, 0x40000000);
Assert.IsNotNull(option); Assert.IsNotNull(option);
Assert.Fail(); Assert.Fail();
} }
......
...@@ -139,7 +139,7 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -139,7 +139,7 @@ namespace PcapDotNet.Packets.TestUtils
int uriLength = random.Next(100); int uriLength = random.Next(100);
StringBuilder stringBuilder = new StringBuilder(); StringBuilder stringBuilder = new StringBuilder();
for (int i = 0; i != uriLength; ++i) for (int i = 0; i != uriLength; ++i)
stringBuilder.Append(random.NextChar((char)33, (char)255)); stringBuilder.Append(random.NextChar((char)33, (char)127));
return stringBuilder.ToString(); return stringBuilder.ToString();
} }
......
...@@ -30,47 +30,53 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -30,47 +30,53 @@ namespace PcapDotNet.Packets.Ethernet
} }
/// <summary> /// <summary>
/// The bytes padding the Ethernet packet beyond the actual Ethernet payload. /// The bytes padding the Ethernet packet beyond the actual Ethernet payload until it is a 60 bytes packet.
/// This assumes we know how to calculate the actual payload length (For example, by using the Total Length of the IPv4 payload). /// This assumes we know how to calculate the actual payload length (For example, by using the Total Length of the IPv4 payload).
/// If we don't know how to calculate the actual payload length <see langword="null"/> will be returned. /// If we don't know how to calculate the actual payload length <see langword="null"/> will be returned.
/// The trailer doesn't include the <see cref="FrameCheckSequence"/> if it exists. /// The Padding doesn't include the <see cref="Trailer"/> and the <see cref="FrameCheckSequence"/> if any exist.
/// </summary> /// </summary>
public DataSegment Trailer public DataSegment Padding
{ {
get get
{ {
DataSegment trailerWithFrameCheckSequence = TrailerWithFrameCheckSequence; if (Length < 60)
if (trailerWithFrameCheckSequence == null) return DataSegment.Empty;
DataSegment payloadByEtherType = PayloadByEtherType;
if (payloadByEtherType == null)
return null; return null;
DataSegment frameCheckSequence = FrameCheckSequence; int payloadLength = PayloadByEtherType.Length;
if (frameCheckSequence == null)
return trailerWithFrameCheckSequence; return new DataSegment(Buffer, StartOffset + HeaderLength + payloadLength, 60 - HeaderLength - payloadLength);
return trailerWithFrameCheckSequence.Subsegment(0, trailerWithFrameCheckSequence.Length - frameCheckSequence.Length);
} }
} }
/// <summary> /// <summary>
/// A sequence of bytes that includes the trailer bytes and the framce check sequence bytes. /// The bytes padding the Ethernet packet beyond the actual Ethernet payload and beyond the first 60 bytes of the packet.
/// This assumes we know how to calculate the actual payload length (For example, by using the Total Length of the IPv4 payload).
/// If we don't know how to calculate the actual payload length <see langword="null"/> will be returned.
/// The trailer doesn't include the <see cref="Padding"/> and the <see cref="FrameCheckSequence"/> if any exist.
/// </summary> /// </summary>
public DataSegment TrailerWithFrameCheckSequence public DataSegment Trailer
{ {
get get
{ {
DataSegment payloadByEtherType = PayloadByEtherType; DataSegment extraBytes = ExtraData;
if (payloadByEtherType == null) if (extraBytes == null)
return null; return null;
int payloadLength = PayloadByEtherType.Length; DataSegment frameCheckSequence = FrameCheckSequence;
return new DataSegment(Buffer, StartOffset + HeaderLength + payloadLength, Length - HeaderLength - payloadLength); if (frameCheckSequence == null)
return extraBytes;
return extraBytes.Subsegment(Padding.Length, extraBytes.Length - frameCheckSequence.Length - Padding.Length);
} }
} }
/// <summary> /// <summary>
/// The 4 bytes of the Frame Check Sequence (FCS). /// The 4 bytes of the Frame Check Sequence (FCS).
/// Usually, these bytes won't be available because the device remvoed them after checking their validity. /// Usually, these bytes won't be available because the device remvoed them after checking their validity.
/// We assume they exist when we see that the Ethernet padding pads to 68 bytes or more. /// We assume they exist when we see that the Ethernet extra bytes pads to 68 bytes or more.
/// If the padding isn't that long or we don't know how to calculate the real payload length, <see langword="null"/> will be returned. /// If the packet isn't that long or we don't know how to calculate the real payload length, <see langword="null"/> will be returned.
/// </summary> /// </summary>
public DataSegment FrameCheckSequence public DataSegment FrameCheckSequence
{ {
...@@ -79,16 +85,32 @@ namespace PcapDotNet.Packets.Ethernet ...@@ -79,16 +85,32 @@ namespace PcapDotNet.Packets.Ethernet
if (Length < 68) if (Length < 68)
return null; return null;
DataSegment trailerWithFrameCheckSequence = TrailerWithFrameCheckSequence; DataSegment extraBytes = ExtraData;
if (trailerWithFrameCheckSequence == null) if (extraBytes == null)
return null; return null;
if (trailerWithFrameCheckSequence.Length >= 4) if (extraBytes.Length >= 4)
return trailerWithFrameCheckSequence.Subsegment(trailerWithFrameCheckSequence.Length - 4, 4); return extraBytes.Subsegment(extraBytes.Length - 4, 4);
return null; return null;
} }
} }
/// <summary>
/// A sequence of bytes that includes the padding bytes, trailer bytes and the frame check sequence bytes.
/// </summary>
public DataSegment ExtraData
{
get
{
DataSegment payloadByEtherType = PayloadByEtherType;
if (payloadByEtherType == null)
return null;
int payloadLength = PayloadByEtherType.Length;
return new DataSegment(Buffer, StartOffset + HeaderLength + payloadLength, Length - HeaderLength - payloadLength);
}
}
/// <summary> /// <summary>
/// The Ethernet payload as a VLAN Tagged Frame datagram. /// The Ethernet payload as a VLAN Tagged Frame datagram.
/// </summary> /// </summary>
......
...@@ -90,6 +90,13 @@ namespace PcapDotNet.Packets.Http ...@@ -90,6 +90,13 @@ namespace PcapDotNet.Packets.Http
/// IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*digit /// IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*digit
/// domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum /// domainlabel = alphanum | alphanum *( alphanum | "-" ) alphanum
/// toplabel = alpha | alpha *( alphanum | "-" ) alphanum /// toplabel = alpha | alpha *( alphanum | "-" ) alphanum
/// alphanum = alpha | digit
/// alpha = lowalpha | upalpha
/// lowalpha = "a" | "b" | "c" | "d" | "e" | "f" | "g" | "h" | "i" | "j" | "k" | "l" | "m" | "n" | "o" | "p" | "q" | "r" | "s" | "t" | "u" | "v" |
/// "w" | "x" | "y" | "z"
/// upalpha = "A" | "B" | "C" | "D" | "E" | "F" | "G" | "H" | "I" | "J" | "K" | "L" | "M" | "N" | "O" | "P" | "Q" | "R" | "S" | "T" | "U" | "V" |
/// "W" | "X" | "Y" | "Z"
/// digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9"
/// ///
/// request-header = Accept /// request-header = Accept
/// | Accept-Charset /// | Accept-Charset
......
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