Commit 18b85375 authored by Brickner_cp's avatar Brickner_cp

Removed zip dependency.

Moved to WinPcap version 4.1.1 to Support Windows 7 (32 and 64 bits).
Also support for IPv6 devices.
Warning: Blue Screen Of Death crash was encountered several times when running tests on Windows 7 64 bits (even without IPv6 devices).
parent b2ce6613
<?xml version="1.0" encoding="UTF-8"?>
<TestRunConfiguration name="Local Test Run" id="be17286c-6d1c-43dd-b068-e83867abf9c5" xmlns="http://microsoft.com/schemas/VisualStudio/TeamTest/2006">
<Description>This is a default test run configuration for a local test run.</Description>
<CodeCoverage enabled="true" keyFile="PcapDotNet.snk">
<Regular>
<CodeCoverageItem binaryFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Base.dll" pdbFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Base.pdb" instrumentInPlace="true" />
<CodeCoverageItem binaryFile="c:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.dll" pdbFile="c:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.pdb" instrumentInPlace="true" />
<CodeCoverageItem binaryFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Packets.dll" pdbFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Packets.pdb" instrumentInPlace="true" />
<CodeCoverageItem binaryFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.Extensions.dll" pdbFile="C:\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.Extensions.pdb" instrumentInPlace="true" />
</Regular>
</CodeCoverage>
<CodeCoverage keyFile="PcapDotNet.snk" />
<TestTypeSpecific>
<WebTestRunConfiguration testTypeId="4e7599fa-5ecb-43e9-a887-cd63cf72d207">
<Browser name="Internet Explorer 7.0">
......
......@@ -2,7 +2,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{20BCB32F-6B86-41D4-8DF4-191F3D233087}</ProjectGuid>
<OutputType>Library</OutputType>
......@@ -47,6 +47,7 @@
<Compile Include="MoreIEnumerableTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="TupleTests.cs" />
<Compile Include="UInt128Tests.cs" />
<Compile Include="UInt24Tests.cs" />
<Compile Include="UInt48Tests.cs" />
</ItemGroup>
......
using System.Globalization;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace PcapDotNet.Base.Test
{
/// <summary>
/// Summary description for UInt128Tests
/// </summary>
[TestClass]
public class UInt128Tests
{
public UInt128Tests()
{
//
// 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 ParseTest()
{
// Random random = new Random();
// for (int i = 0; i != 100; ++i)
// {
// UInt48 expected = (UInt48)random.NextLong(UInt48.MaxValue + 1);
// UInt48 actual = UInt48.Parse(expected.ToString(), NumberStyles.Integer, CultureInfo.InvariantCulture);
//
// Assert.AreEqual(expected, actual);
// }
}
[TestMethod]
public void UInt128Test()
{
// Random random = new Random();
// for (int i = 0; i != 1000; ++i)
// {
// UInt48 value = random.NextUInt48();
//
// Assert.AreEqual(value, value);
// Assert.IsTrue(value == value);
// Assert.IsFalse(value != value);
// Assert.IsNotNull(value.GetHashCode());
//
// if (value < uint.MaxValue)
// Assert.AreEqual(value, uint.Parse(value.ToString()));
//
// Assert.AreEqual((byte)value, (byte)(value % 256));
// }
}
[TestMethod]
public void ShiftRightTest()
{
const string valueString = "0123456789ABCDEFFEDCBA9876543210";
UInt128 value = UInt128.Parse(valueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Assert.AreEqual(UInt128.Parse(valueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture), value);
for (int i = 0; i <= 124; i += 4)
{
string expectedValueString = new string('0', i / 4) + valueString.Substring(0, valueString.Length - i / 4);
UInt128 expectedValue = UInt128.Parse(expectedValueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Assert.AreEqual(expectedValue, value >> i, i.ToString());
Assert.AreEqual(expectedValue, value >> (i / 2) >> (i / 2), i.ToString());
Assert.AreEqual(expectedValue, value >> (i / 4) >> (i / 4) >> (i / 4) >> (i / 4), i.ToString());
}
}
[TestMethod]
public void BitwiseAndTest()
{
const string valueString = "0123456789ABCDEFFEDCBA9876543210";
UInt128 value = UInt128.Parse(valueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Assert.AreEqual(UInt128.Parse(valueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture), value);
for (int i = 0; i <= 32; ++i)
{
string andValueString = new string('0', i) + new string('F', valueString.Length - i);
UInt128 andValue = UInt128.Parse(andValueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
string expectedValueString = new string('0', i) + valueString.Substring(i, valueString.Length - i);
UInt128 expectedValue = UInt128.Parse(expectedValueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
UInt128 actualValue = value & andValue;
Assert.AreEqual(expectedValue, actualValue, i.ToString());
}
}
[TestMethod]
public void ToStringTest()
{
const string valueString = "0123456789ABCDEFFEDCBA9876543210";
UInt128 value = UInt128.Parse(valueString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
Assert.AreEqual(valueString, value.ToString("X32"));
}
}
}
\ No newline at end of file
......@@ -7,7 +7,7 @@ namespace PcapDotNet.Base
/// <summary>
/// Extension methods for Func of type T.
/// </summary>
public static class MoreFunc
public static class FuncExtensions
{
/// <summary>
/// Generates an array of a given size by generating elements using the given delegate.
......
......@@ -10,7 +10,7 @@ namespace PcapDotNet.Base
/// <summary>
/// Extension methods for IEnumerable of type T.
/// </summary>
public static class MoreIEnumerable
public static class IEnumerableExtensions
{
/// <summary>
/// True iff the sequence has no elements.
......@@ -133,5 +133,10 @@ namespace PcapDotNet.Base
int i = 0;
return sequence.Aggregate(0, (value, b) => value ^ (b << (8 * (i++ % 4))));
}
public static int Count<T>(this IEnumerable<T> sequence, T value)
{
return sequence.Count(element => element.Equals(value));
}
}
}
\ No newline at end of file
......@@ -6,7 +6,7 @@ namespace PcapDotNet.Base
/// <summary>
/// Extension methods for IList of type T.
/// </summary>
public static class MoreIList
public static class IListExtensions
{
/// <summary>
/// Wraps a list with a ReadOnlyCollection.
......
......@@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{83E805C9-4D29-4E34-A27E-5A78690FBD2B}</ProjectGuid>
<OutputType>Library</OutputType>
......@@ -30,6 +30,7 @@
<RunCodeAnalysis>true</RunCodeAnalysis>
<DocumentationFile>..\..\bin\Debug\PcapDotNet.Base.XML</DocumentationFile>
<CodeAnalysisRules>-Microsoft.Design#CA1004</CodeAnalysisRules>
<PlatformTarget>AnyCPU</PlatformTarget>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
......@@ -59,13 +60,14 @@
<Reference Include="System.Xml" />
</ItemGroup>
<ItemGroup>
<Compile Include="MoreFunc.cs" />
<Compile Include="MoreIEnumerable.cs" />
<Compile Include="MoreIList.cs" />
<Compile Include="MorePropertyInfo.cs" />
<Compile Include="MoreTimeSpan.cs" />
<Compile Include="MoreType.cs" />
<Compile Include="FuncExtensions.cs" />
<Compile Include="IEnumerableExtensions.cs" />
<Compile Include="IListExtensions.cs" />
<Compile Include="PropertyInfoExtensions.cs" />
<Compile Include="TimeSpanExtensions.cs" />
<Compile Include="TypeExtensions.cs" />
<Compile Include="Tuple.cs" />
<Compile Include="UInt128.cs" />
<Compile Include="UInt24.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="UInt48.cs" />
......@@ -86,7 +88,7 @@
-->
<PropertyGroup>
<PreBuildEvent>if not exist "$(SolutionDir)$(SolutionName).snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v6.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")</PreBuildEvent>
<PostBuildEvent>cd $(OutDir)
zip Pcap.Net.Binary.zip $(TargetFileName) $(ProjectName).pdb $(ProjectName).xml</PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -5,7 +5,7 @@ namespace PcapDotNet.Base
/// <summary>
/// Extension methods for PropertyInfo.
/// </summary>
public static class MorePropertyInfo
public static class PropertyInfoExtensions
{
/// <summary>
/// Returns the value of the given instance's non-indexed property.
......
......@@ -7,7 +7,7 @@ namespace PcapDotNet.Base
/// <summary>
/// Extension methods for TimeSpan.
/// </summary>
public static class MoreTimeSpan
public static class TimeSpanExtensions
{
/// <summary>
/// Divides the TimeSpan by a given value.
......
......@@ -6,7 +6,7 @@ namespace PcapDotNet.Base
/// <summary>
/// Extension methods for Type.
/// </summary>
public static class MoreType
public static class TypeExtensions
{
/// <summary>
/// Returns all the possible values for the given enum type.
......
using System;
using System.Globalization;
using System.Runtime.InteropServices;
namespace PcapDotNet.Base
{
/// <summary>
/// A 128 bit unsigned integer.
/// </summary>
[StructLayout(LayoutKind.Sequential, Pack = 1)]
public struct UInt128
{
/// <summary>
/// The number of bytes this type will take.
/// </summary>
public const int SizeOf = 16;
/// <summary>
/// The maximum value of this type.
/// </summary>
public static readonly UInt128 MaxValue = UInt128.Parse("FFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF", NumberStyles.HexNumber, CultureInfo.InvariantCulture);
public static readonly UInt128 Zero = UInt128.Parse("00000000000000000000000000000000", NumberStyles.HexNumber, CultureInfo.InvariantCulture);
public UInt128(ulong mostSignificant, ulong leastSignificant)
{
_mostSignificant = mostSignificant;
_leastSignificant = leastSignificant;
}
public UInt128(ushort[] values)
{
if (values.Length != 8)
throw new ArgumentException("UInt128 must be created by 8 ushorts and not " + values.Length + " ushorts");
_mostSignificant =
((ulong)values[0] << 48) +
((ulong)values[1] << 32) +
((ulong)values[2] << 16) +
values[3];
_leastSignificant =
((ulong)values[4] << 48) +
((ulong)values[5] << 32) +
((ulong)values[6] << 16) +
values[7];
}
/// <summary>
/// Converts the string representation of a number in a specified style to its 128-bit unsigned integer equivalent.
/// </summary>
/// <param name="value">A string representing the number to convert.</param>
/// <param name="style">
/// A bitwise combination of NumberStyles values that indicates the permitted format of value.
/// A typical value to specify is NumberStyles.Integer.
/// </param>
/// <param name="provider">An System.IFormatProvider that supplies culture-specific formatting information about value.</param>
/// <returns>A 128-bit unsigned integer equivalent to the number specified in s.</returns>
public static UInt128 Parse(string value, NumberStyles style, IFormatProvider provider)
{
if (style != NumberStyles.HexNumber)
throw new NotSupportedException("Only " + NumberStyles.HexNumber + " style is supported");
ulong mostSignficantLong = 0;
ulong leastSignficantLong = 0;
if (value.Length > 16)
{
leastSignficantLong = ulong.Parse(value.Substring(value.Length - 16, 16), style, provider);
value = value.Substring(0, value.Length - 16);
mostSignficantLong = ulong.Parse(value, style, provider);
}
else
leastSignficantLong = ulong.Parse(value, style, provider);
return new UInt128(mostSignficantLong, leastSignficantLong);
}
/// <summary>
/// Converts a 64 bit unsigned integer to a 128 bit unsigned integer by taking all the 64 bits.
/// </summary>
/// <param name="value">The 64 bit value to convert.</param>
/// <returns>The 128 bit value created by taking all the 64 bits of the 64 bit value.</returns>
public static implicit operator UInt128(ulong value)
{
return new UInt128(0, value);
}
/// <summary>
/// Converts the 128 bits unsigned integer to a 64 bits unsigned integer.
/// </summary>
/// <param name="value">The 128 bit value to convert.</param>
/// <returns>The 64 bit value converted from the 128 bit value.</returns>
public static explicit operator ulong(UInt128 value)
{
return value._mostSignificant;
}
/// <summary>
/// Returns true iff the two values represent the same value.
/// </summary>
/// <param name="other">The value to compare to.</param>
/// <returns>True iff the two values represent the same value.</returns>
public bool Equals(UInt128 other)
{
return _mostSignificant == other._mostSignificant &&
_leastSignificant == other._leastSignificant;
}
/// <summary>
/// Indicates whether this instance and a specified object are equal.
/// </summary>
/// <returns>
/// true if <paramref name="obj"/> and this instance are the same type and represent the same value; otherwise, false.
/// </returns>
/// <param name="obj">Another object to compare to. </param><filterpriority>2</filterpriority>
public override bool Equals(object obj)
{
return (obj is UInt128) &&
Equals((UInt128)obj);
}
/// <summary>
/// Returns true iff the two values represent the same value.
/// </summary>
/// <param name="value1">The first value to compare.</param>
/// <param name="value2">The second value to compare.</param>
/// <returns>True iff the two values represent the same value.</returns>
public static bool operator ==(UInt128 value1, UInt128 value2)
{
return value1.Equals(value2);
}
/// <summary>
/// Returns true iff the two values represent different values.
/// </summary>
/// <param name="value1">The first value to compare.</param>
/// <param name="value2">The second value to compare.</param>
/// <returns>True iff the two values represent different values.</returns>
public static bool operator !=(UInt128 value1, UInt128 value2)
{
return !(value1 == value2);
}
public static UInt128 operator >> (UInt128 value, int numBits)
{
numBits %= 128;
if (numBits >= 64)
return new UInt128(0, value._mostSignificant >> (numBits - 64));
if (numBits == 0)
return value;
return new UInt128(value._mostSignificant >> numBits, (value._leastSignificant >> numBits) + (value._mostSignificant << (64 - numBits)));
}
public static UInt128 operator &(UInt128 value1, UInt128 value2)
{
return new UInt128(value1._mostSignificant & value2._mostSignificant, value1._leastSignificant & value2._leastSignificant);
}
/// <summary>
/// Returns the hash code for this instance.
/// </summary>
/// <returns>
/// A 32-bit signed integer that is the hash code for this instance.
/// </returns>
/// <filterpriority>2</filterpriority>
public override int GetHashCode()
{
return ((ulong)this).GetHashCode();
}
/// <summary>
/// Returns the hexadecimal string representation of the 128 bits unsigned integer.
/// </summary>
public string ToString(string format)
{
if (format != "X32")
throw new NotSupportedException("Only X32 format is supported");
return _mostSignificant.ToString("X16") + _leastSignificant.ToString("X16");
}
public string ToString()
{
throw new NotSupportedException("Only X32 format is supported");
}
private readonly ulong _leastSignificant;
private readonly ulong _mostSignificant;
}
}
\ No newline at end of file
......@@ -25,7 +25,7 @@ namespace PcapDotNet.Base
/// </summary>
/// <param name="value">A string representing the number to convert.</param>
/// <param name="style">
/// A bitwise combination of NumberStyles values that indicates the permitted format of s.
/// A bitwise combination of NumberStyles values that indicates the permitted format of value.
/// A typical value to specify is NumberStyles.Integer.
/// </param>
/// <param name="provider">An System.IFormatProvider that supplies culture-specific formatting information about value.</param>
......@@ -187,6 +187,5 @@ namespace PcapDotNet.Base
private readonly uint _leastSignificant;
private readonly ushort _mostSignificant;
}
}
\ No newline at end of file
......@@ -84,7 +84,7 @@
-->
<PropertyGroup>
<PreBuildEvent>if not exist "$(SolutionDir)$(SolutionName).snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v6.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")</PreBuildEvent>
<PostBuildEvent>cd $(OutDir)
zip Pcap.Net.Binary.zip $(TargetFileName) $(ProjectName).pdb $(ProjectName).xml</PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>
\ No newline at end of file
......@@ -7,6 +7,7 @@ using System.Threading;
using PcapDotNet.Core.Extensions;
using PcapDotNet.Packets;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets.IpV6;
using PcapDotNet.Packets.TestUtils;
using PcapDotNet.TestUtils;
......@@ -110,7 +111,7 @@ namespace PcapDotNet.Core.Test
const int PacketSize = 100;
// Test normal mode
TestReceiveSomePackets(0, 0, int.MaxValue, PacketSize, false, PacketCommunicatorReceiveResult.Ok, 0, 1, 1.02);
TestReceiveSomePackets(0, 0, int.MaxValue, PacketSize, false, PacketCommunicatorReceiveResult.Ok, 0, 1, 1.03);
TestReceiveSomePackets(NumPacketsToSend, NumPacketsToSend, int.MaxValue, PacketSize, false, PacketCommunicatorReceiveResult.Ok, NumPacketsToSend, 0, 0.02);
TestReceiveSomePackets(NumPacketsToSend, 0, int.MaxValue, PacketSize, false, PacketCommunicatorReceiveResult.Ok, NumPacketsToSend, 0, 0.02);
TestReceiveSomePackets(NumPacketsToSend, -1, int.MaxValue, PacketSize, false, PacketCommunicatorReceiveResult.Ok, NumPacketsToSend, 0, 0.02);
......@@ -139,7 +140,7 @@ namespace PcapDotNet.Core.Test
TestReceivePackets(NumPacketsToSend, NumPacketsToSend / 2, int.MaxValue, 2, PacketSize, PacketCommunicatorReceiveResult.Ok, NumPacketsToSend / 2, 0, 0.02);
// Wait for more packets
TestReceivePackets(NumPacketsToSend, 0, int.MaxValue, 2, PacketSize, PacketCommunicatorReceiveResult.None, NumPacketsToSend, 2, 2.02);
TestReceivePackets(NumPacketsToSend, 0, int.MaxValue, 2, PacketSize, PacketCommunicatorReceiveResult.None, NumPacketsToSend, 2, 2.03);
TestReceivePackets(NumPacketsToSend, -1, int.MaxValue, 2, PacketSize, PacketCommunicatorReceiveResult.None, NumPacketsToSend, 2, 2.02);
TestReceivePackets(NumPacketsToSend, NumPacketsToSend + 1, int.MaxValue, 2, PacketSize, PacketCommunicatorReceiveResult.None, NumPacketsToSend, 2, 2.02);
......@@ -293,7 +294,7 @@ namespace PcapDotNet.Core.Test
// Normal
TestGetStatistics(SourceMac, DestinationMac, NumPacketsToSend, NumStatisticsToGather, int.MaxValue, 5, PacketSize,
PacketCommunicatorReceiveResult.Ok, NumStatisticsToGather, NumPacketsToSend, NumStatisticsToGather, NumStatisticsToGather + 0.04);
PacketCommunicatorReceiveResult.Ok, NumStatisticsToGather, NumPacketsToSend, NumStatisticsToGather, NumStatisticsToGather + 0.05);
// Wait for less statistics
TestGetStatistics(SourceMac, DestinationMac, NumPacketsToSend, NumStatisticsToGather / 2, int.MaxValue, 5, PacketSize,
......@@ -343,15 +344,16 @@ namespace PcapDotNet.Core.Test
}
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void SetBigKernelBufferSizeErrorTest()
{
using (PacketCommunicator communicator = OpenLiveDevice())
{
communicator.SetKernelBufferSize(1024 * 1024 * 1024);
}
}
// this test is removed for now since it doens't throw an exception for such big value
// [TestMethod]
// [ExpectedException(typeof(InvalidOperationException))]
// public void SetBigKernelBufferSizeErrorTest()
// {
// using (PacketCommunicator communicator = OpenLiveDevice())
// {
// communicator.SetKernelBufferSize(1024 * 1024 * 1024);
// }
// }
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
......@@ -794,14 +796,27 @@ namespace PcapDotNet.Core.Test
IList<LivePacketDevice> devices = LivePacketDevice.AllLocalMachine;
MoreAssert.IsBiggerOrEqual(1, devices.Count);
LivePacketDevice device = devices[0];
MoreAssert.IsMatch(@"Network adapter '.* \(Microsoft's Packet Scheduler\) ' on local host", device.Description);
MoreAssert.IsMatch(@"Network adapter '.*\(.*\) ?' on local host", device.Description);
Assert.AreEqual(DeviceAttributes.None, device.Attributes);
Assert.AreEqual(1, device.Addresses.Count);
DeviceAddress address = device.Addresses[0];
MoreAssert.IsMatch("Address: " + SocketAddressFamily.Internet + @" [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ " +
"Netmask: " + SocketAddressFamily.Internet + @" 255\.[0-9]+\.[0-9]+\.[0-9]+ " +
"Broadcast: " + SocketAddressFamily.Internet + @" 255.255.255.255",
address.ToString());
MoreAssert.IsInRange(1, 2, device.Addresses.Count);
foreach (DeviceAddress address in device.Addresses)
{
if (address.Address.Family == SocketAddressFamily.Internet)
{
MoreAssert.IsMatch("Address: " + SocketAddressFamily.Internet + @" [0-9]+\.[0-9]+\.[0-9]+\.[0-9]+ " +
"Netmask: " + SocketAddressFamily.Internet + @" 255\.[0-9]+\.[0-9]+\.[0-9]+ " +
"Broadcast: " + SocketAddressFamily.Internet + @" 255.255.255.255",
address.ToString());
}
else
{
Assert.AreEqual(SocketAddressFamily.Internet6, address.Address.Family);
MoreAssert.IsMatch("Address: " + SocketAddressFamily.Internet6 + @" (?:[0-9A-F]{4}:){7}[0-9A-F]{4} " +
"Netmask: " + SocketAddressFamily.Unspecified + @" " + IpV6Address.Zero + " " +
"Broadcast: " + SocketAddressFamily.Unspecified + @" " + IpV6Address.Zero,
address.ToString());
}
}
PacketCommunicator communicator = device.Open();
try
{
......
......@@ -64,7 +64,9 @@ namespace PcapDotNet.Core.Test
public void VersionTest()
{
const string VersionNumberRegex = @"[0-9]+\.[0-9]+\.[0-9]+(?:\.[0-9]+)?";
const string VersionRegex = "^WinPcap version " + VersionNumberRegex + @" \(packet\.dll version " + VersionNumberRegex + @"\), based on libpcap version " + VersionNumberRegex + "$";
const string LibpcapVersionRegex = @"(?:[0-9]+\.[0-9]+\.[0-9]+(?:\.[0-9]+)?)|(?:[0-9]\.[0-9] branch [0-9]_[0-9]_rel0b \([0-9]+\))";
// WinPcap version 4.1.1 (packet.dll version 4.1.0.1753), based on libpcap version 1.0 branch 1_0_rel0b (20091008)
const string VersionRegex = "^WinPcap version " + VersionNumberRegex + @" \(packet\.dll version " + VersionNumberRegex + @"\), based on libpcap version " + LibpcapVersionRegex + "$";
string version = PcapLibrary.Version;
MoreAssert.IsMatch(VersionRegex, version);
}
......
#include "DeviceAddress.h"
#include "IpV4SocketAddress.h"
#include "IpV6SocketAddress.h"
#include "Pcap.h"
using namespace System;
......@@ -57,6 +58,17 @@ DeviceAddress::DeviceAddress(pcap_addr_t* pcapAddress)
_destination = gcnew IpV4SocketAddress(pcapAddress->dstaddr);
break;
case SocketAddressFamily::Internet6:
if (pcapAddress->addr)
_address = gcnew IpV6SocketAddress(pcapAddress->addr);
if (pcapAddress->netmask)
_netmask = gcnew IpV6SocketAddress(pcapAddress->netmask);
if (pcapAddress->broadaddr)
_broadcast = gcnew IpV6SocketAddress(pcapAddress->broadaddr);
if (pcapAddress->dstaddr)
_destination = gcnew IpV6SocketAddress(pcapAddress->dstaddr);
break;
default:
throw gcnew NotImplementedException(gcnew String("Device of family ") + family.ToString() + gcnew String(" is unsupported"));
// case SocketAddressFamily::INET6:
......
#include "IpV6SocketAddress.h"
#include "Pcap.h"
using namespace System;
using namespace System::Text;
using namespace System::Net;
using namespace PcapDotNet::Core;
using namespace PcapDotNet::Packets::IpV6;
using namespace PcapDotNet::Base;
IpV6Address IpV6SocketAddress::Address::get()
{
return _address;
}
String^ IpV6SocketAddress::ToString()
{
StringBuilder^ result = gcnew StringBuilder();
result->Append(SocketAddress::ToString());
result->Append(" ");
result->Append(Address);
return result->ToString();
}
// Internal
IpV6SocketAddress::IpV6SocketAddress(sockaddr *address)
: SocketAddress(address->sa_family)
{
sockaddr_in6* ipV6Address = (struct sockaddr_in6 *)address;
unsigned long *value = reinterpret_cast<unsigned long*>(ipV6Address->sin6_addr.u.Byte);
_address = IpV6Address(UInt128(*value, *(value+1)));
}
#pragma once
#include "SocketAddress.h"
#include "PcapDeclarations.h"
namespace PcapDotNet { namespace Core
{
/// <summary>
/// An internet protocol version 6 address for a device.
/// </summary>
public ref class IpV6SocketAddress : SocketAddress
{
public:
/// <summary>
/// The ip version 6 address.
/// </summary>
property Packets::IpV6::IpV6Address Address
{
Packets::IpV6::IpV6Address get();
}
virtual System::String^ ToString() override;
internal:
IpV6SocketAddress(sockaddr *address);
private:
Packets::IpV6::IpV6Address _address;
};
}}
\ No newline at end of file
......@@ -23,7 +23,7 @@ ReadOnlyCollection<LivePacketDevice^>^ LivePacketDevice::AllLocalMachine::get()
&alldevs, errbuf) == -1)
{
String^ errorString = gcnew String(errbuf);
throw gcnew InvalidOperationException(String::Format(CultureInfo::InvariantCulture, "Failed getting devices. Error: %s", errorString));
throw gcnew InvalidOperationException(String::Format(CultureInfo::InvariantCulture, "Failed getting devices. Error: {0}", errorString));
}
try
......
#pragma once
#define HAVE_REMOTE
#include <stdio.h>
#include <pcap.h>
#include <remote-ext.h>
......
......@@ -16,6 +16,9 @@
<Platform
Name="Win32"
/>
<Platform
Name="x64"
/>
</Platforms>
<ToolFiles>
</ToolFiles>
......@@ -102,8 +105,93 @@
/>
<Tool
Name="VCPostBuildEventTool"
Description="Build Release Files"
CommandLine="cd $(OutDir)&#x0D;&#x0A;zip Pcap.Net.Binary.zip $(TargetFileName) $(ProjectName).pdb $(ProjectName).xml&#x0D;&#x0A;"
CommandLine=""
/>
</Configuration>
<Configuration
Name="Debug|x64"
OutputDirectory="$(SolutionDir)\..\bin\$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
ManagedExtensions="1"
>
<Tool
Name="VCPreBuildEventTool"
Description="Create Public/Private Key Pair"
CommandLine="if not exist &quot;$(SolutionDir)$(SolutionName).snk&quot; (&quot;%PROGRAMFILES%\Microsoft SDKs\Windows\v6.0A\bin\sn.exe&quot; -k &quot;$(SolutionDir)$(SolutionName).snk&quot;)"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
Optimization="0"
AdditionalIncludeDirectories="&quot;..\..\3rdParty\WpdPack\Include&quot;"
PreprocessorDefinitions="WIN32;_DEBUG;CODE_ANALYSIS"
RuntimeLibrary="3"
UsePrecompiledHeader="0"
GenerateXMLDocumentationFiles="true"
WarningLevel="4"
DebugInformationFormat="3"
ForcedIncludeFiles="CodeAnalysis\SourceAnnotations.h"
EnablePREfast="false"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="wpcap.lib $(NOINHERIT)"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\3rdParty\WpdPack\Lib\x64"
AddModuleNamesToAssembly=""
GenerateDebugInformation="true"
AssemblyDebug="1"
TargetMachine="17"
KeyFile="&quot;$(SolutionDir)$(SolutionName).snk&quot;"
Profile="true"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
Rules="-Microsoft.Design#CA1021;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027;-Microsoft.Reliability#CA2004"
EnableFxCop="true"
Dictionaries="CodeAnalysisDictionary.xml"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine=""
/>
</Configuration>
<Configuration
......@@ -185,8 +273,90 @@
/>
<Tool
Name="VCPostBuildEventTool"
Description="Build Release Files"
CommandLine="cd $(OutDir)&#x0D;&#x0A;zip Pcap.Net.Binary.zip $(TargetFileName) $(ProjectName).pdb $(ProjectName).xml&#x0D;&#x0A;"
CommandLine=""
/>
</Configuration>
<Configuration
Name="Release|x64"
OutputDirectory="$(SolutionDir)\..\bin\$(ConfigurationName)"
IntermediateDirectory="$(ConfigurationName)"
ConfigurationType="2"
CharacterSet="1"
ManagedExtensions="1"
WholeProgramOptimization="1"
>
<Tool
Name="VCPreBuildEventTool"
Description="Create Public/Private Key Pair"
CommandLine="if not exist &quot;$(SolutionDir)$(SolutionName).snk&quot; (&quot;%PROGRAMFILES%\Microsoft SDKs\Windows\v6.0A\bin\sn.exe&quot; -k &quot;$(SolutionDir)$(SolutionName).snk&quot;)"
/>
<Tool
Name="VCCustomBuildTool"
/>
<Tool
Name="VCXMLDataGeneratorTool"
/>
<Tool
Name="VCWebServiceProxyGeneratorTool"
/>
<Tool
Name="VCMIDLTool"
TargetEnvironment="3"
/>
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;..\..\3rdParty\WpdPack\Include&quot;"
PreprocessorDefinitions="WIN32;NDEBUG;CODE_ANALYSIS"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
GenerateXMLDocumentationFiles="true"
WarningLevel="4"
DebugInformationFormat="3"
ForcedIncludeFiles="CodeAnalysis\SourceAnnotations.h"
/>
<Tool
Name="VCManagedResourceCompilerTool"
/>
<Tool
Name="VCResourceCompilerTool"
/>
<Tool
Name="VCPreLinkEventTool"
/>
<Tool
Name="VCLinkerTool"
AdditionalDependencies="wpcap.lib $(NOINHERIT)"
LinkIncremental="1"
AdditionalLibraryDirectories="..\..\3rdParty\WpdPack\Lib\x64"
AddModuleNamesToAssembly=""
GenerateDebugInformation="true"
TargetMachine="17"
KeyFile="&quot;$(SolutionDir)$(SolutionName).snk&quot;"
/>
<Tool
Name="VCALinkTool"
/>
<Tool
Name="VCManifestTool"
/>
<Tool
Name="VCXDCMakeTool"
/>
<Tool
Name="VCBscMakeTool"
/>
<Tool
Name="VCFxCopTool"
Rules="-Microsoft.Design#CA1021;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027;-Microsoft.Reliability#CA2004"
EnableFxCop="true"
Dictionaries="CodeAnalysisDictionary.xml"
/>
<Tool
Name="VCAppVerifierTool"
/>
<Tool
Name="VCPostBuildEventTool"
CommandLine=""
/>
</Configuration>
</Configurations>
......@@ -247,6 +417,14 @@
RelativePath=".\IpV4SocketAddress.h"
>
</File>
<File
RelativePath=".\IpV6SocketAddress.cpp"
>
</File>
<File
RelativePath=".\IpV6SocketAddress.h"
>
</File>
<File
RelativePath=".\LivePacketDevice.cpp"
>
......
......@@ -21,22 +21,14 @@ namespace PcapDotNet.Packets.Test
//
}
private TestContext testContextInstance;
/// <summary>
///Gets or sets the test context which provides
///information about and functionality for the current test run.
///</summary>
public TestContext TestContext
{
get
{
return testContextInstance;
}
set
{
testContextInstance = value;
}
get;
set;
}
#region Additional test attributes
......
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using PcapDotNet.Packets.IpV4;
using PcapDotNet.Packets.IpV6;
using PcapDotNet.Packets.TestUtils;
namespace PcapDotNet.Packets.Test
{
/// <summary>
/// Summary description for IpV6AddressTests
/// </summary>
[TestClass]
public class IpV6AddressTests
{
public IpV6AddressTests()
{
//
// 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 IpV6AddressRandomTest()
{
Random random = new Random();
for (int i = 0; i != 1000; ++i)
{
// IpV4Address address = random.NextIpV6Address();
//
// Assert.AreEqual(address, new IpV4Address(address.ToString()));
// Assert.IsTrue(address == new IpV4Address(address.ToString()));
// Assert.IsFalse(address != new IpV4Address(address.ToString()));
// Assert.AreEqual(address.GetHashCode(), new IpV4Address(address.ToString()).GetHashCode());
// Assert.AreEqual(address, new IpV4Address(address.ToValue()));
//
// Assert.AreNotEqual(address, random.NextIpV4Address());
// Assert.IsFalse(address == random.NextIpV4Address());
// Assert.IsTrue(address != random.NextIpV4Address());
// Assert.AreNotEqual(address.GetHashCode(), random.NextIpV4Address().GetHashCode());
//
// Assert.AreNotEqual(2, address);
// Assert.IsFalse(address.Equals(null));
}
}
[TestMethod]
public void IpV6AddressOrderTest()
{
// Assert.AreEqual("0.0.0.0", new IpV4Address(0).ToString());
// Assert.AreEqual("0.0.0.0", IpV4Address.Zero.ToString());
// Assert.AreEqual("0.0.0.1", new IpV4Address(1).ToString());
// Assert.AreEqual("0.0.0.255", new IpV4Address(255).ToString());
// Assert.AreEqual("0.0.1.0", new IpV4Address(256).ToString());
// Assert.AreEqual("0.0.255.0", new IpV4Address(255 * 256).ToString());
// Assert.AreEqual("0.1.0.0", new IpV4Address(256 * 256).ToString());
// Assert.AreEqual("0.255.0.0", new IpV4Address(255 * 256 * 256).ToString());
// Assert.AreEqual("1.0.0.0", new IpV4Address(256 * 256 * 256).ToString());
// Assert.AreEqual("255.0.0.0", new IpV4Address((uint)255 * 256 * 256 * 256).ToString());
// Assert.AreEqual("255.254.253.252", new IpV4Address((uint)255 * 256 * 256 * 256 + 254 * 256 * 256 + 253 * 256 + 252).ToString());
}
[TestMethod]
public void IpV6AddressWithBufferTest()
{
// Random random = new Random();
// for (int i = 0; i != 1000; ++i)
// {
// IpV4Address address = random.NextIpV4Address();
// byte[] buffer = new byte[IpV4Address.SizeOf];
// buffer.Write(0, address, Endianity.Big);
// Assert.AreEqual(address, buffer.ReadIpV4Address(0, Endianity.Big));
// Assert.AreNotEqual(address, buffer.ReadIpV4Address(0, Endianity.Small));
// buffer.Write(0, address, Endianity.Small);
// Assert.AreEqual(address, buffer.ReadIpV4Address(0, Endianity.Small));
// Assert.AreNotEqual(address, buffer.ReadIpV4Address(0, Endianity.Big));
// }
}
[TestMethod]
public void IpV6AddressParsingTest()
{
Assert.AreEqual(IpV6Address.Zero, new IpV6Address("0000:0000:0000:0000:0000:0000:0000:0000"));
Assert.AreEqual(IpV6Address.Zero, new IpV6Address("0000:0000:0000:0000:0000:0000:0.0.0.0"));
Assert.AreEqual(IpV6Address.Zero, new IpV6Address("0000:0000:0000::0000:0000:0.0.0.0"));
Assert.AreEqual(IpV6Address.Zero, new IpV6Address("0000:0000:0000::0000:0.0.0.0"));
Assert.AreEqual(IpV6Address.Zero, new IpV6Address("0000:0000::0000:0.0.0.0"));
Assert.AreEqual(IpV6Address.Zero, new IpV6Address("0000:0000::0000"));
Assert.AreEqual(IpV6Address.Zero, new IpV6Address("0000:0000::"));
Assert.AreEqual(IpV6Address.Zero, new IpV6Address("0000::"));
Assert.AreEqual(IpV6Address.Zero, new IpV6Address("::"));
Assert.AreEqual(IpV6Address.Zero, new IpV6Address("::0.0.0.0"));
Assert.AreEqual(new IpV6Address("1:2:3:4:5:6:7:8"), new IpV6Address("0001:0002:0003:0004:0005:0006:0007:0008"));
Assert.AreEqual(new IpV6Address("1:2:3:4:5:6:7:8"), new IpV6Address("0001:0002:0003:0004:0005:0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("1:0:3:4:5:6:7:8"), new IpV6Address("0001:0000:0003:0004:0005:0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("1:0:3:4:5:6:7:8"), new IpV6Address("0001::0003:0004:0005:0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("0:0:3:4:5:6:7:8"), new IpV6Address("0:0:0003:0004:0005:0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("0:0:3:4:5:6:7:8"), new IpV6Address(":0:0003:0004:0005:0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("0:0:3:4:5:6:7:8"), new IpV6Address("::0003:0004:0005:0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("0:0:3:0:0:6:7:8"), new IpV6Address("0:0:0003:0000:0000:0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("0:0:3:0:0:6:7:8"), new IpV6Address("0:0:0003:0:0:0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("0:0:3:0:0:6:7:8"), new IpV6Address("0:0:0003::0:0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("0:0:3:0:0:6:7:8"), new IpV6Address("0:0:0003::0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("0:0:3:0:0:6:7:8"), new IpV6Address("0::0003:0:0:0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("0:0:3:0:0:6:7:8"), new IpV6Address("::0003:0:0:0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("0:0:3:0:0:6:7:8"), new IpV6Address(":0:0003::0006:0.7.0.8"));
Assert.AreEqual(new IpV6Address("0:0:3:0:0:6:7:8"), new IpV6Address(":0:0003:0:0:0006:7:8"));
Assert.AreEqual(new IpV6Address("0:0:3:0:0:6:7:0"), new IpV6Address(":0:0003:0:0:0006:7:"));
Assert.AreEqual(new IpV6Address("0:0:3:0:0:6:0:0"), new IpV6Address(":0:0003:0:0:0006::"));
Assert.AreEqual(new IpV6Address("0:0:3:0:0:6:0:0"), new IpV6Address(":0:0003:0:0:0006::0"));
Assert.AreEqual(new IpV6Address("0:0:3:0:0:6:0:0"), new IpV6Address(":0:0003:0:0:0006::0"));
}
[TestMethod]
public void IpV6AddressToStringTest()
{
Assert.AreEqual("0000:0000:0000:0000:0000:0000:0000:0000", IpV6Address.Zero.ToString());
}
}
}
\ No newline at end of file
......@@ -2,7 +2,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6C7326EB-F230-4934-B74B-F99F87204E44}</ProjectGuid>
<OutputType>Library</OutputType>
......@@ -52,6 +52,7 @@
<Compile Include="IcmpTests.cs" />
<Compile Include="IgmpTests.cs" />
<Compile Include="IpV4Tests.cs" />
<Compile Include="IpV6AddressTests.cs" />
<Compile Include="MacAddressTests.cs" />
<Compile Include="PacketTests.cs" />
<Compile Include="Properties\AssemblyInfo.cs" />
......
using System;
using System.Collections.Generic;
using System.Globalization;
using System.Linq;
using System.Text;
using PcapDotNet.Base;
using PcapDotNet.Packets.IpV4;
namespace PcapDotNet.Packets.IpV6
{
/// <summary>
/// Represents an IPv6 address.
/// </summary>
public struct IpV6Address
{
/// <summary>
/// The number of bytes the address take.
/// </summary>
public const int SizeOf = UInt128.SizeOf;
/// <summary>
/// The zero address (::).
/// </summary>
public static IpV6Address Zero
{
get { return _zero; }
}
/// <summary>
/// Create an address from a 128 bit integer.
/// 0 -> ::
/// 1 -> ::1
/// 256 -> ::100
/// </summary>
public IpV6Address(UInt128 value)
{
_value = value;
}
/// <summary>
/// Creates an address from an address string ("2001:0db8:0::22:1.2.3.4").
/// </summary>
public IpV6Address(string value)
{
string cannonizedValue = value;
// Handle ...:1.2.3.4
int lastColonIndex = cannonizedValue.LastIndexOf(':');
if (lastColonIndex == -1)
throw new ArgumentException("Invalid IPv6 address format " + value);
string lastPart = value.Substring(lastColonIndex + 1, cannonizedValue.Length - lastColonIndex - 1);
if (lastPart.IndexOf('.') != -1)
{
uint lastPartValue = new IpV4Address(lastPart).ToValue();
cannonizedValue = cannonizedValue.Substring(0, lastColonIndex + 1) +
(lastPartValue >> 16).ToString("x") + ":" + (lastPartValue & 0x0000FFFF).ToString("x");
}
// Handle ...::...
int doubleColonIndex = cannonizedValue.IndexOf("::");
if (doubleColonIndex != -1)
{
int numMissingColons = 7 - cannonizedValue.Count(':');
if (numMissingColons < 0)
throw new ArgumentException("Invalid IPv6 address format " + value);
cannonizedValue = cannonizedValue.Substring(0, doubleColonIndex + 2) +
new string(':', numMissingColons) +
cannonizedValue.Substring(doubleColonIndex + 2);
}
IEnumerable<ushort> values =
cannonizedValue.Split(':').Select(part => string.IsNullOrEmpty(part) ? (ushort)0 : ushort.Parse(part, NumberStyles.HexNumber, CultureInfo.InvariantCulture));
ulong mostSignificant = values.Take(4).Aggregate((ulong)0, (sum, element) => (sum << 16) + element);
ulong leastSignificant = values.Skip(4).Take(4).Aggregate((ulong)0, (sum, element) => (sum << 16) + element);
_value = new UInt128(mostSignificant, leastSignificant);
}
// /// <summary>
// /// Gets the address value as a 32 bit integer.
// /// </summary>
// public uint ToValue()
// {
// return _value;
// }
/// <summary>
/// Two addresses are equal if the have the exact same value.
/// </summary>
public bool Equals(IpV6Address other)
{
return _value == other._value;
}
/// <summary>
/// Two addresses are equal if the have the exact same value.
/// </summary>
public override bool Equals(object obj)
{
return (obj is IpV6Address &&
Equals((IpV6Address)obj));
}
/// <summary>
/// Two addresses are equal if the have the exact same value.
/// </summary>
public static bool operator ==(IpV6Address value1, IpV6Address value2)
{
return value1.Equals(value2);
}
/// <summary>
/// Two addresses are different if the have different values.
/// </summary>
public static bool operator !=(IpV6Address value1, IpV6Address value2)
{
return !(value1 == value2);
}
/// <summary>
/// The hash code of an address is the hash code of its 128 bit integer value.
/// </summary>
public override int GetHashCode()
{
return _value.GetHashCode();
}
/// <summary>
/// Translates the address to a string (0ABC:1234:5678:0443:0ABC:1234:5678:0443).
/// </summary>
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder(39);
for (int i = 0; i != 8; ++i)
{
if (i != 0)
stringBuilder.Append(':');
string andZerosBefore = new string('0', i * 4);
string andZerosAfter = new string('0', 28 - i * 4);
string andString = andZerosBefore + "FFFF" + andZerosAfter;
UInt128 andValue = UInt128.Parse(andString, NumberStyles.HexNumber, CultureInfo.InvariantCulture);
ushort value = (ushort)((_value & andValue) >> (112 - i * 16));
stringBuilder.Append(value.ToString("X4"));
}
return stringBuilder.ToString();
}
private readonly UInt128 _value;
private static readonly IpV6Address _zero = new IpV6Address(0);
}
}
\ No newline at end of file
......@@ -3,7 +3,7 @@
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<ProductVersion>9.0.30729</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{8A184AF5-E46C-482C-81A3-76D8CE290104}</ProjectGuid>
<OutputType>Library</OutputType>
......@@ -95,6 +95,7 @@
<Compile Include="Igmp\IgmpMessageType.cs" />
<Compile Include="IOptionUnknownFactory.cs" />
<Compile Include="IpV4\IpV4OptionUnknown.cs" />
<Compile Include="IpV6\IpV6Address.cs" />
<Compile Include="Option.cs" />
<Compile Include="IOptionComplexFactory.cs" />
<Compile Include="IpV4\IpV4Address.cs" />
......@@ -184,7 +185,7 @@
-->
<PropertyGroup>
<PreBuildEvent>if not exist "$(SolutionDir)$(SolutionName).snk" ("%25PROGRAMFILES%25\Microsoft SDKs\Windows\v6.0A\bin\sn.exe" -k "$(SolutionDir)$(SolutionName).snk")</PreBuildEvent>
<PostBuildEvent>cd $(OutDir)
zip Pcap.Net.Binary.zip $(TargetFileName) $(ProjectName).pdb $(ProjectName).xml</PostBuildEvent>
<PostBuildEvent>
</PostBuildEvent>
</PropertyGroup>
</Project>
\ No newline at end of file
This diff is collapsed.
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