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,17 +26,21 @@ namespace PcapDotNet.Core.Test
break;
case "eth.type":
field.AssertNoFields();
field.AssertShowDecimal((ushort)ethernetDatagram.EtherType);
break;
case "eth.trailer":
if (ethernetDatagram.Trailer != null)
field.AssertValue(ethernetDatagram.Trailer);
field.AssertValue(ethernetDatagram.Trailer);
break;
case "":
if (ethernetDatagram.Trailer != null)
field.AssertValue(ethernetDatagram.FrameCheckSequence);
case "eth.fcs":
field.AssertValue(ethernetDatagram.FrameCheckSequence);
break;
case "eth.padding":
field.AssertNoFields();
field.AssertValue(ethernetDatagram.Padding);
break;
default:
......
......@@ -184,7 +184,8 @@ namespace PcapDotNet.Core.Test
break;
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;
default:
......
......@@ -432,7 +432,7 @@ namespace PcapDotNet.Core.Test
case IpV4OptionType.RouterAlert:
var routerAlert = (IpV4OptionRouterAlert)option;
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())
{
if (HandleCommonOptionSubfield(subfield, option))
......@@ -606,6 +606,14 @@ namespace PcapDotNet.Core.Test
field.AssertShow("MTU Probe (with option length = " + option.Length + " bytes; should be 4)");
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:
// TODO: Support 133.
field.AssertShow("Extended Security (" + option.Length + " bytes)");
......
......@@ -1870,7 +1870,8 @@ namespace PcapDotNet.Core.Test
break;
case IpV6MobilityOptionType.Experimental:
optionField.AssertShow("Experimental");
optionField.AssertShow("Experimental" +
(option.Length == 2 ? " (with option length = 0 bytes; should be >= 1)" : ""));
var experimental = (IpV6MobilityOptionExperimental)option;
foreach (XElement optionSubfield in optionField.Fields())
{
......
......@@ -196,14 +196,21 @@ namespace PcapDotNet.Core.Test
switch (checksumField.Name())
{
case "tcp.checksum_good":
checksumField.AssertNoFields();
checksumField.AssertShowDecimal(tcpDatagram.Checksum != 0 && ipDatagram.IsTransportChecksumCorrect);
break;
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;
case "tcp.checksum_calculated":
checksumField.AssertNoFields();
if (ipDatagram.IsTransportChecksumCorrect)
checksumField.AssertShowDecimal(tcpDatagram.Checksum);
break;
......@@ -211,7 +218,6 @@ namespace PcapDotNet.Core.Test
default:
throw new InvalidOperationException("Invalid checksum field name " + checksumField.Name());
}
checksumField.AssertNoFields();
}
}
break;
......@@ -259,6 +265,7 @@ namespace PcapDotNet.Core.Test
{
Assert.IsFalse(options.IsValid, "Options IsValid");
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 (0x19) ") || // Unknown in Wireshark but known (and invalid) in Pcap.Net.
field.Show().StartsWith("Echo reply (with option length = ") ||
......@@ -483,6 +490,11 @@ namespace PcapDotNet.Core.Test
}
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:
field.AssertShow("SCPS corruption experienced (with option length = " + option.Length + " bytes; should be 2)");
// TODO: Support 23.
......
......@@ -51,7 +51,12 @@ namespace PcapDotNet.Core.Test
(EthernetType)1, (EthernetType)5, (EthernetType)17, (EthernetType)29, (EthernetType)30, (EthernetType)43, (EthernetType)50, EthernetType.ReverseArp,
}.Contains(
vLanTaggedFrameDatagram.EtherType))
field.AssertValue(vLanTaggedFrameDatagram.TrailerWithFrameCheckSequence);
field.AssertValue(vLanTaggedFrameDatagram.ExtraData);
break;
case "eth.padding":
field.AssertNoFields();
field.AssertValue(vLanTaggedFrameDatagram.Trailer);
break;
default:
......
......@@ -109,9 +109,10 @@ namespace PcapDotNet.Packets.Test
Data = new Datagram(new byte[100])
});
Assert.IsTrue(packet.IsValid);
Assert.IsNull(packet.Ethernet.TrailerWithFrameCheckSequence);
Assert.IsNull(packet.Ethernet.Padding);
Assert.IsNull(packet.Ethernet.Trailer);
Assert.IsNull(packet.Ethernet.FrameCheckSequence);
Assert.IsNull(packet.Ethernet.ExtraData);
}
}
}
\ No newline at end of file
......@@ -481,7 +481,7 @@ namespace PcapDotNet.Packets.Test
[ExpectedException(typeof(ArgumentException), AllowDerivedTypes = false)]
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.Fail();
}
......
......@@ -139,7 +139,7 @@ namespace PcapDotNet.Packets.TestUtils
int uriLength = random.Next(100);
StringBuilder stringBuilder = new StringBuilder();
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();
}
......
......@@ -30,47 +30,53 @@ namespace PcapDotNet.Packets.Ethernet
}
/// <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).
/// 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>
public DataSegment Trailer
public DataSegment Padding
{
get
{
DataSegment trailerWithFrameCheckSequence = TrailerWithFrameCheckSequence;
if (trailerWithFrameCheckSequence == null)
if (Length < 60)
return DataSegment.Empty;
DataSegment payloadByEtherType = PayloadByEtherType;
if (payloadByEtherType == null)
return null;
DataSegment frameCheckSequence = FrameCheckSequence;
if (frameCheckSequence == null)
return trailerWithFrameCheckSequence;
return trailerWithFrameCheckSequence.Subsegment(0, trailerWithFrameCheckSequence.Length - frameCheckSequence.Length);
int payloadLength = PayloadByEtherType.Length;
return new DataSegment(Buffer, StartOffset + HeaderLength + payloadLength, 60 - HeaderLength - payloadLength);
}
}
/// <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>
public DataSegment TrailerWithFrameCheckSequence
public DataSegment Trailer
{
get
{
DataSegment payloadByEtherType = PayloadByEtherType;
if (payloadByEtherType == null)
DataSegment extraBytes = ExtraData;
if (extraBytes == null)
return null;
int payloadLength = PayloadByEtherType.Length;
return new DataSegment(Buffer, StartOffset + HeaderLength + payloadLength, Length - HeaderLength - payloadLength);
DataSegment frameCheckSequence = FrameCheckSequence;
if (frameCheckSequence == null)
return extraBytes;
return extraBytes.Subsegment(Padding.Length, extraBytes.Length - frameCheckSequence.Length - Padding.Length);
}
}
/// <summary>
/// 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.
/// We assume they exist when we see that the Ethernet padding 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.
/// We assume they exist when we see that the Ethernet extra bytes pads to 68 bytes or more.
/// 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>
public DataSegment FrameCheckSequence
{
......@@ -79,16 +85,32 @@ namespace PcapDotNet.Packets.Ethernet
if (Length < 68)
return null;
DataSegment trailerWithFrameCheckSequence = TrailerWithFrameCheckSequence;
if (trailerWithFrameCheckSequence == null)
DataSegment extraBytes = ExtraData;
if (extraBytes == null)
return null;
if (trailerWithFrameCheckSequence.Length >= 4)
return trailerWithFrameCheckSequence.Subsegment(trailerWithFrameCheckSequence.Length - 4, 4);
if (extraBytes.Length >= 4)
return extraBytes.Subsegment(extraBytes.Length - 4, 4);
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>
/// The Ethernet payload as a VLAN Tagged Frame datagram.
/// </summary>
......
......@@ -90,6 +90,13 @@ namespace PcapDotNet.Packets.Http
/// IPv4address = 1*digit "." 1*digit "." 1*digit "." 1*digit
/// domainlabel = alphanum | alphanum *( 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
/// | 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