Commit 430c24ac authored by Brickner_cp's avatar Brickner_cp

Add support for quick start IPv4 option.

Fixed IPv4 Header checksum bug.
parent b4143c20
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Text;
using PcapDotNet.Packets.IpV4; using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Core.Test namespace PcapDotNet.Core.Test
...@@ -40,6 +41,32 @@ namespace PcapDotNet.Core.Test ...@@ -40,6 +41,32 @@ namespace PcapDotNet.Core.Test
case IpV4OptionType.RouterAlert: case IpV4OptionType.RouterAlert:
return "Router Alert: Unknown (" + ((IpV4OptionRouterAlert)option).Value + ")"; return "Router Alert: Unknown (" + ((IpV4OptionRouterAlert)option).Value + ")";
case IpV4OptionType.QuickStart:
IpV4OptionQuickStart quickStart = (IpV4OptionQuickStart)option;
StringBuilder quickStartWireshark = new StringBuilder("Quick-Start: ");
if (quickStart.Function == IpV4OptionQuickStartFunction.RateRequest)
quickStartWireshark.Append("Rate request");
else
quickStartWireshark.Append("Rate report");
quickStartWireshark.Append(", ");
if (quickStart.RateKbps == 0)
quickStartWireshark.Append("0 bit/s");
else if (quickStart.RateKbps < 1024)
quickStartWireshark.Append(quickStart.RateKbps + " kbit/s");
else if (quickStart.RateKbps < 1024 * 1024)
quickStartWireshark.Append(((double)quickStart.RateKbps / 1000) + " Mbit/s");
else
quickStartWireshark.Append(((double)quickStart.RateKbps / 1000000) + " Gbit/s");
if (quickStart.Function == IpV4OptionQuickStartFunction.RateRequest)
quickStartWireshark.Append(", QS TTL " + quickStart.Ttl);
return quickStartWireshark.ToString();
default: default:
throw new InvalidOperationException("Illegal option type " + option.OptionType); throw new InvalidOperationException("Illegal option type " + option.OptionType);
} }
...@@ -53,6 +80,7 @@ namespace PcapDotNet.Core.Test ...@@ -53,6 +80,7 @@ namespace PcapDotNet.Core.Test
case IpV4OptionType.NoOperation: case IpV4OptionType.NoOperation:
case IpV4OptionType.StreamIdentifier: case IpV4OptionType.StreamIdentifier:
case IpV4OptionType.RouterAlert: case IpV4OptionType.RouterAlert:
case IpV4OptionType.QuickStart:
break; break;
case IpV4OptionType.LooseSourceRouting: case IpV4OptionType.LooseSourceRouting:
......
...@@ -349,7 +349,7 @@ namespace PcapDotNet.Core.Test ...@@ -349,7 +349,7 @@ namespace PcapDotNet.Core.Test
DateTime fieldTimestamp = fieldShow[4] == ' ' DateTime fieldTimestamp = fieldShow[4] == ' '
? DateTime.ParseExact(fieldShow, "MMM d, yyyy HH:mm:ss.fffffff", CultureInfo.InvariantCulture) ? DateTime.ParseExact(fieldShow, "MMM d, yyyy HH:mm:ss.fffffff", CultureInfo.InvariantCulture)
: DateTime.ParseExact(fieldShow, "MMM dd, yyyy HH:mm:ss.fffffff", CultureInfo.InvariantCulture); : DateTime.ParseExact(fieldShow, "MMM dd, yyyy HH:mm:ss.fffffff", CultureInfo.InvariantCulture);
MoreAssert.IsInRange(fieldTimestamp.AddSeconds(-1), fieldTimestamp.AddSeconds(1), packet.Timestamp); MoreAssert.IsInRange(fieldTimestamp.AddSeconds(-2), fieldTimestamp.AddSeconds(2), packet.Timestamp);
break; break;
case "frame.len": case "frame.len":
......
...@@ -106,6 +106,8 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -106,6 +106,8 @@ namespace PcapDotNet.Packets.TestUtils
impossibleOptionTypes.Add(IpV4OptionType.InternetTimestamp); impossibleOptionTypes.Add(IpV4OptionType.InternetTimestamp);
if (maximumOptionLength < IpV4OptionTraceRoute.OptionLength) if (maximumOptionLength < IpV4OptionTraceRoute.OptionLength)
impossibleOptionTypes.Add(IpV4OptionType.TraceRoute); impossibleOptionTypes.Add(IpV4OptionType.TraceRoute);
if (maximumOptionLength < IpV4OptionQuickStart.OptionLength)
impossibleOptionTypes.Add(IpV4OptionType.QuickStart);
IpV4OptionType optionType = random.NextEnum<IpV4OptionType>(impossibleOptionTypes); IpV4OptionType optionType = random.NextEnum<IpV4OptionType>(impossibleOptionTypes);
switch (optionType) switch (optionType)
...@@ -193,6 +195,12 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -193,6 +195,12 @@ namespace PcapDotNet.Packets.TestUtils
case IpV4OptionType.RouterAlert: case IpV4OptionType.RouterAlert:
return new IpV4OptionRouterAlert(random.NextUShort()); return new IpV4OptionRouterAlert(random.NextUShort());
case IpV4OptionType.QuickStart:
return new IpV4OptionQuickStart(random.NextEnum<IpV4OptionQuickStartFunction>(),
random.NextByte(IpV4OptionQuickStart.RateMaximumValue + 1),
random.NextByte(),
random.NextUInt() & 0xFFFFFFFC);
default: default:
throw new InvalidOperationException("optionType = " + optionType); throw new InvalidOperationException("optionType = " + optionType);
} }
......
...@@ -254,7 +254,7 @@ namespace PcapDotNet.Packets.IpV4 ...@@ -254,7 +254,7 @@ namespace PcapDotNet.Packets.IpV4
private ushort CalculateHeaderChecksum() private ushort CalculateHeaderChecksum()
{ {
uint sum = Sum16Bits(Buffer, StartOffset, Math.Min(Offset.HeaderChecksum, Length)) + uint sum = Sum16Bits(Buffer, StartOffset, Math.Min(Offset.HeaderChecksum, Length)) +
Sum16Bits(Buffer, StartOffset + Offset.HeaderChecksum + 2, Math.Min(HeaderLength, Length) - Offset.HeaderChecksum - 2); Sum16Bits(Buffer, StartOffset + Offset.HeaderChecksum + 2, RealHeaderLength - Offset.HeaderChecksum - 2);
return Sum16BitsToChecksum(sum); return Sum16BitsToChecksum(sum);
} }
...@@ -275,6 +275,8 @@ namespace PcapDotNet.Packets.IpV4 ...@@ -275,6 +275,8 @@ namespace PcapDotNet.Packets.IpV4
uint sum = 0; uint sum = 0;
while (offset < endOffset - 1) while (offset < endOffset - 1)
sum += buffer.ReadUShort(ref offset, Endianity.Big); sum += buffer.ReadUShort(ref offset, Endianity.Big);
if (offset < endOffset)
sum += buffer[offset];
return sum; return sum;
} }
......
This diff is collapsed.
...@@ -33,6 +33,11 @@ namespace PcapDotNet.Packets.IpV4 ...@@ -33,6 +33,11 @@ namespace PcapDotNet.Packets.IpV4
/// </summary> /// </summary>
NoOperation = 1, NoOperation = 1,
/// <summary>
/// Quick Start (QS). RFC 4782.
/// </summary>
QuickStart = 25,
/// <summary> /// <summary>
/// Traceroute Using an IP Option. /// Traceroute Using an IP Option.
/// RFC 1393. /// RFC 1393.
......
...@@ -75,6 +75,7 @@ ...@@ -75,6 +75,7 @@
<Compile Include="IpV4\IpV4Option.cs" /> <Compile Include="IpV4\IpV4Option.cs" />
<Compile Include="IpV4\IpV4OptionComplex.cs" /> <Compile Include="IpV4\IpV4OptionComplex.cs" />
<Compile Include="IpV4\IpV4OptionLooseSourceRouting.cs" /> <Compile Include="IpV4\IpV4OptionLooseSourceRouting.cs" />
<Compile Include="IpV4\IpV4OptionQuickStart.cs" />
<Compile Include="IpV4\IpV4OptionRouterAlert.cs" /> <Compile Include="IpV4\IpV4OptionRouterAlert.cs" />
<Compile Include="IpV4\IpV4OptionSecurityProtectionAuthority.cs" /> <Compile Include="IpV4\IpV4OptionSecurityProtectionAuthority.cs" />
<Compile Include="IpV4\IpV4OptionSimple.cs" /> <Compile Include="IpV4\IpV4OptionSimple.cs" />
......
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