Commit 4863044c authored by Brickner_cp's avatar Brickner_cp

Add IGMP Version 0 Message Type values.

Add IGMP Version 0 Reply Code.
Add IGMP Version 0 Create Group Request Code.
IGMP Version 0 is not supported yet.
Code Coverage 97.02%
parent 87cc08fe
...@@ -57,6 +57,9 @@ namespace PcapDotNet.Base.Test ...@@ -57,6 +57,9 @@ namespace PcapDotNet.Base.Test
Assert.AreEqual(value, value); Assert.AreEqual(value, value);
Assert.IsTrue(value == value); Assert.IsTrue(value == value);
Assert.IsFalse(value != value); Assert.IsFalse(value != value);
Assert.AreNotEqual(value, "string");
Assert.AreNotEqual(value, (UInt24)(((value & 0x00FFFF) + 1)| value & 0xFF0000));
Assert.AreNotEqual(value, (UInt24)((value & 0x00FFFF)| ((value & 0xFF0000) + 0x010000)));
Assert.IsNotNull(value.GetHashCode()); Assert.IsNotNull(value.GetHashCode());
Assert.AreEqual(((int)value).ToString(), value.ToString()); Assert.AreEqual(((int)value).ToString(), value.ToString());
} }
......
...@@ -19,9 +19,9 @@ namespace PcapDotNet.Core.Test ...@@ -19,9 +19,9 @@ namespace PcapDotNet.Core.Test
} }
/// <summary> /// <summary>
///Gets or sets the test context which provides /// Gets or sets the test context which provides
///information about and functionality for the current test run. /// information about and functionality for the current test run.
///</summary> /// </summary>
public TestContext TestContext { get; set;} public TestContext TestContext { get; set;}
#region Additional test attributes #region Additional test attributes
......
...@@ -152,7 +152,7 @@ namespace PcapDotNet.Core.Test ...@@ -152,7 +152,7 @@ namespace PcapDotNet.Core.Test
TestReceivePacketsEnumerable(NumPacketsToSend, NumPacketsToSend / 2, int.MaxValue, 2, PacketSize, NumPacketsToSend / 2, 0, 0.027); TestReceivePacketsEnumerable(NumPacketsToSend, NumPacketsToSend / 2, int.MaxValue, 2, PacketSize, NumPacketsToSend / 2, 0, 0.027);
// Wait for more packets // Wait for more packets
TestReceivePacketsEnumerable(NumPacketsToSend, -1, int.MaxValue, 2, PacketSize, NumPacketsToSend, 2, 2.021); TestReceivePacketsEnumerable(NumPacketsToSend, -1, int.MaxValue, 2, PacketSize, NumPacketsToSend, 2, 2.024);
TestReceivePacketsEnumerable(NumPacketsToSend, NumPacketsToSend + 1, int.MaxValue, 2, PacketSize, NumPacketsToSend, 2, 2.13); TestReceivePacketsEnumerable(NumPacketsToSend, NumPacketsToSend + 1, int.MaxValue, 2, PacketSize, NumPacketsToSend, 2, 2.13);
// Break loop // Break loop
......
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace PcapDotNet.Core.Test
{
/// <summary>
/// Summary description for MarshalingServicesTests
/// </summary>
[TestClass]
public class MarshalingServicesTests
{
public MarshalingServicesTests()
{
//
// TODO: Add constructor logic here
//
}
/// <summary>
/// Gets or sets the test context which provides
/// information about and functionality for the current test run.
/// </summary>
public TestContext TestContext { get; set; }
#region Additional test attributes
//
// You can use the following additional attributes as you write your tests:
//
// Use ClassInitialize to run code before running the first test in the class
// [ClassInitialize()]
// public static void MyClassInitialize(TestContext testContext) { }
//
// Use ClassCleanup to run code after all tests in a class have run
// [ClassCleanup()]
// public static void MyClassCleanup() { }
//
// Use TestInitialize to run code before running each test
// [TestInitialize()]
// public void MyTestInitialize() { }
//
// Use TestCleanup to run code after each test has run
// [TestCleanup()]
// public void MyTestCleanup() { }
//
#endregion
// [TestMethod]
// public void ManagedToUnmanagedStringTest()
// {
// new PcapDataLink(null);
// }
}
}
\ No newline at end of file
...@@ -48,6 +48,7 @@ ...@@ -48,6 +48,7 @@
<ItemGroup> <ItemGroup>
<Compile Include="BerkeleyPacketFilterTests.cs" /> <Compile Include="BerkeleyPacketFilterTests.cs" />
<Compile Include="LivePacketDeviceTests.cs" /> <Compile Include="LivePacketDeviceTests.cs" />
<Compile Include="MarshalingServicesTests.cs" />
<Compile Include="MoreIpV4Option.cs" /> <Compile Include="MoreIpV4Option.cs" />
<Compile Include="MoreTcpOption.cs" /> <Compile Include="MoreTcpOption.cs" />
<Compile Include="XElementExtensions.cs" /> <Compile Include="XElementExtensions.cs" />
......
...@@ -142,15 +142,6 @@ namespace PcapDotNet.Core.Test ...@@ -142,15 +142,6 @@ namespace PcapDotNet.Core.Test
ethernetLayer.EtherType = EthernetType.None; ethernetLayer.EtherType = EthernetType.None;
ipV4Layer.Protocol = null; ipV4Layer.Protocol = null;
GreLayer greLayer = random.NextGreLayer(); GreLayer greLayer = random.NextGreLayer();
// GreLayer greLayer = new GreLayer
// {
// AcknowledgmentSequenceNumber = 10,
// ProtocolType = EthernetType.AppleTalk,
// //EthernetType.PointToPointProtocol,
// Key = 0,
// Version = GreVersion.EnhancedGre,
// };
// IEnumerable<ILayer> grePayloadLayers = random.NextIcmpPayloadLayers(icmpLayer);
return PacketBuilder.Build(packetTimestamp, ethernetLayer, ipV4Layer, greLayer, payloadLayer); return PacketBuilder.Build(packetTimestamp, ethernetLayer, ipV4Layer, greLayer, payloadLayer);
case PacketType.Udp: case PacketType.Udp:
...@@ -190,7 +181,7 @@ namespace PcapDotNet.Core.Test ...@@ -190,7 +181,7 @@ namespace PcapDotNet.Core.Test
} }
else else
{ {
const byte retryNumber = 24; const byte retryNumber = 121;
pcapFilename = Path.GetTempPath() + "temp." + retryNumber + ".pcap"; pcapFilename = Path.GetTempPath() + "temp." + retryNumber + ".pcap";
List<Packet> packetsList = new List<Packet>(); List<Packet> packetsList = new List<Packet>();
new OfflinePacketDevice(pcapFilename).Open().ReceivePackets(1000, packetsList.Add); new OfflinePacketDevice(pcapFilename).Open().ReceivePackets(1000, packetsList.Add);
...@@ -621,7 +612,8 @@ namespace PcapDotNet.Core.Test ...@@ -621,7 +612,8 @@ namespace PcapDotNet.Core.Test
switch (field.Name()) switch (field.Name())
{ {
case "igmp.version": case "igmp.version":
field.AssertShowDecimal(igmpDatagram.Version); if (field.Show() != "0")
field.AssertShowDecimal(igmpDatagram.Version);
break; break;
case "igmp.type": case "igmp.type":
...@@ -690,6 +682,10 @@ namespace PcapDotNet.Core.Test ...@@ -690,6 +682,10 @@ namespace PcapDotNet.Core.Test
field.AssertShow(igmpDatagram.SourceAddresses[sourceAddressIndex++].ToString()); field.AssertShow(igmpDatagram.SourceAddresses[sourceAddressIndex++].ToString());
break; break;
case "igmp.identifier":
// todo support IGMP version 0 and IGMP identifier.
break;
default: default:
throw new InvalidOperationException("Invalid igmp field " + field.Name()); throw new InvalidOperationException("Invalid igmp field " + field.Name());
} }
......
...@@ -11,6 +11,7 @@ namespace PcapDotNet { namespace Core ...@@ -11,6 +11,7 @@ namespace PcapDotNet { namespace Core
static System::InvalidOperationException^ BuildInvalidOperation(System::String^ errorMessage, pcap_t* pcapDescriptor); static System::InvalidOperationException^ BuildInvalidOperation(System::String^ errorMessage, pcap_t* pcapDescriptor);
private: private:
[System::Diagnostics::DebuggerNonUserCode]
PcapError(){} PcapError(){}
}; };
}} }}
\ No newline at end of file
...@@ -236,6 +236,7 @@ namespace PcapDotNet.Packets.Test ...@@ -236,6 +236,7 @@ namespace PcapDotNet.Packets.Test
Datagram newIpPayload = new Datagram(gre.Take(gre.Length - 1).ToArray()); Datagram newIpPayload = new Datagram(gre.Take(gre.Length - 1).ToArray());
packetBuilder = new PacketBuilder(ethernetLayer, ipV4Layer, new PayloadLayer {Data = newIpPayload}); packetBuilder = new PacketBuilder(ethernetLayer, ipV4Layer, new PayloadLayer {Data = newIpPayload});
packet = packetBuilder.Build(DateTime.Now); packet = packetBuilder.Build(DateTime.Now);
Assert.IsNull(packet.Ethernet.IpV4.Gre.Payload);
Assert.IsFalse(packet.IsValid); Assert.IsFalse(packet.IsValid);
// SreLength is too big // SreLength is too big
......
...@@ -500,7 +500,11 @@ namespace PcapDotNet.Packets.TestUtils ...@@ -500,7 +500,11 @@ namespace PcapDotNet.Packets.TestUtils
public static IgmpLayer NextIgmpLayer(this Random random) public static IgmpLayer NextIgmpLayer(this Random random)
{ {
IgmpMessageType igmpMessageType = random.NextEnum(IgmpMessageType.None); IgmpMessageType igmpMessageType = random.NextEnum(IgmpMessageType.None, IgmpMessageType.CreateGroupRequestVersion0,
IgmpMessageType.CreateGroupReplyVersion0, IgmpMessageType.JoinGroupRequestVersion0,
IgmpMessageType.JoinGroupReplyVersion0, IgmpMessageType.LeaveGroupRequestVersion0,
IgmpMessageType.LeaveGroupReplyVersion0, IgmpMessageType.ConfirmGroupRequestVersion0,
IgmpMessageType.ConfirmGroupReplyVersion0);
IgmpQueryVersion igmpQueryVersion = IgmpQueryVersion.None; IgmpQueryVersion igmpQueryVersion = IgmpQueryVersion.None;
TimeSpan igmpMaxResponseTime = random.NextTimeSpan(TimeSpan.FromSeconds(0.1), TimeSpan.FromSeconds(256 * 0.1) - TimeSpan.FromTicks(1)); TimeSpan igmpMaxResponseTime = random.NextTimeSpan(TimeSpan.FromSeconds(0.1), TimeSpan.FromSeconds(256 * 0.1) - TimeSpan.FromTicks(1));
IpV4Address igmpGroupAddress = random.NextIpV4Address(); IpV4Address igmpGroupAddress = random.NextIpV4Address();
......
...@@ -225,6 +225,33 @@ namespace PcapDotNet.Packets ...@@ -225,6 +225,33 @@ namespace PcapDotNet.Packets
return result; return result;
} }
/// <!--summary>
/// Reads 8 bytes from a specific offset as an int with a given endianity.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns-->
// public static long ReadLong(this byte[] buffer, int offset, Endianity endianity)
// {
// long value = ReadLong(buffer, offset);
// if (IsWrongEndianity(endianity))
// value = IPAddress.HostToNetworkOrder(value);
// return value;
// }
/// <!--summary>
/// Reads 8 bytes from a specific offset as a ulong with a given endianity.
/// </summary>
/// <param name="buffer">The buffer to read the bytes from.</param>
/// <param name="offset">The offset in the buffer to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns-->
// public static ulong ReadULong(this byte[] buffer, int offset, Endianity endianity)
// {
// return (ulong)ReadLong(buffer, offset, endianity);
// }
/// <summary> /// <summary>
/// Reads 6 bytes from a specific offset as a MacAddress with a given endianity. /// Reads 6 bytes from a specific offset as a MacAddress with a given endianity.
/// </summary> /// </summary>
...@@ -664,6 +691,17 @@ namespace PcapDotNet.Packets ...@@ -664,6 +691,17 @@ namespace PcapDotNet.Packets
} }
} }
// private static long ReadLong(byte[] buffer, int offset)
// {
// unsafe
// {
// fixed (byte* ptr = &buffer[offset])
// {
// return *((long*)ptr);
// }
// }
// }
private static void Write(byte[] buffer, int offset, short value) private static void Write(byte[] buffer, int offset, short value)
{ {
unsafe unsafe
......
...@@ -221,6 +221,17 @@ namespace PcapDotNet.Packets ...@@ -221,6 +221,17 @@ namespace PcapDotNet.Packets
return Buffer.ReadUInt(StartOffset + offset, endianity); return Buffer.ReadUInt(StartOffset + offset, endianity);
} }
/// <!--summary>
/// Reads 8 bytes from a specific offset in the datagram as a ulong with a given endianity.
/// </summary>
/// <param name="offset">The offset in the datagram to start reading.</param>
/// <param name="endianity">The endianity to use to translate the bytes to the value.</param>
/// <returns>The value converted from the read bytes according to the endianity.</returns-->
// protected ulong ReadULong(int offset, Endianity endianity)
// {
// return Buffer.ReadULong(StartOffset + offset, endianity);
// }
/// <summary> /// <summary>
/// Reads 6 bytes from a specific offset in the datagram as a MacAddress with a given endianity. /// Reads 6 bytes from a specific offset in the datagram as a MacAddress with a given endianity.
/// </summary> /// </summary>
......
namespace PcapDotNet.Packets.Igmp
{
/// <summary>
/// The code of the IGMP message for Create Group Request (RFC988).
/// </summary>
public enum IgmpCreateGroupRequestVersion0Code : byte
{
/// <summary>
/// Public.
/// </summary>
Public = 0x00,
/// <summary>
/// Private.
/// </summary>
Private = 0x01
}
}
\ No newline at end of file
...@@ -10,6 +10,46 @@ namespace PcapDotNet.Packets.Igmp ...@@ -10,6 +10,46 @@ namespace PcapDotNet.Packets.Igmp
/// </summary> /// </summary>
None = 0x00, None = 0x00,
/// <summary>
/// Create Group Request (RFC988).
/// </summary>
CreateGroupRequestVersion0 = 0x01,
/// <summary>
/// Create Group Reply (RFC988).
/// </summary>
CreateGroupReplyVersion0 = 0x02,
/// <summary>
/// Join Group Request (RFC988).
/// </summary>
JoinGroupRequestVersion0 = 0x03,
/// <summary>
/// Join Group Reply (RFC988).
/// </summary>
JoinGroupReplyVersion0 = 0x04,
/// <summary>
/// Leave Group Request (RFC988).
/// </summary>
LeaveGroupRequestVersion0 = 0x05,
/// <summary>
/// Leave Group Reply (RFC988).
/// </summary>
LeaveGroupReplyVersion0 = 0x06,
/// <summary>
/// Confirm Group Request (RFC988).
/// </summary>
ConfirmGroupRequestVersion0 = 0x07,
/// <summary>
/// Confirm Group Reply (RFC988).
/// </summary>
ConfirmGroupReplyVersion0 = 0x08,
/// <summary> /// <summary>
/// Membership Query (RFC3376). /// Membership Query (RFC3376).
/// </summary> /// </summary>
......
...@@ -3,7 +3,7 @@ ...@@ -3,7 +3,7 @@
<PropertyGroup> <PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration> <Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform> <Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.30729</ProductVersion> <ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion> <SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8A184AF5-E46C-482C-81A3-76D8CE290104}</ProjectGuid> <ProjectGuid>{8A184AF5-E46C-482C-81A3-76D8CE290104}</ProjectGuid>
<OutputType>Library</OutputType> <OutputType>Library</OutputType>
...@@ -139,11 +139,13 @@ ...@@ -139,11 +139,13 @@
<Compile Include="Icmp\IcmpUnknownLayer.cs" /> <Compile Include="Icmp\IcmpUnknownLayer.cs" />
<Compile Include="IDataLink.cs" /> <Compile Include="IDataLink.cs" />
<Compile Include="Ethernet\IEthernetNextLayer.cs" /> <Compile Include="Ethernet\IEthernetNextLayer.cs" />
<Compile Include="Igmp\IgmpCreateGroupRequestVersion0Code.cs" />
<Compile Include="Igmp\IgmpLayer.cs" /> <Compile Include="Igmp\IgmpLayer.cs" />
<Compile Include="Igmp\IgmpLeaveGroupVersion2Layer.cs" /> <Compile Include="Igmp\IgmpLeaveGroupVersion2Layer.cs" />
<Compile Include="Igmp\IgmpQueryVersion1Layer.cs" /> <Compile Include="Igmp\IgmpQueryVersion1Layer.cs" />
<Compile Include="Igmp\IgmpQueryVersion2Layer.cs" /> <Compile Include="Igmp\IgmpQueryVersion2Layer.cs" />
<Compile Include="Igmp\IgmpQueryVersion3Layer.cs" /> <Compile Include="Igmp\IgmpQueryVersion3Layer.cs" />
<Compile Include="Igmp\IgmpReplyVersion0Code.cs" />
<Compile Include="Igmp\IgmpReportVersion1Layer.cs" /> <Compile Include="Igmp\IgmpReportVersion1Layer.cs" />
<Compile Include="Igmp\IgmpReportVersion2Layer.cs" /> <Compile Include="Igmp\IgmpReportVersion2Layer.cs" />
<Compile Include="Igmp\IgmpReportVersion3Layer.cs" /> <Compile Include="Igmp\IgmpReportVersion3Layer.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