Commit a21627ba authored by Brickner_cp's avatar Brickner_cp

--no commit message

--no commit message
parent 66887d2e
using System;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace Packets.Test
{
/// <summary>
/// Summary description for IpV4AddressTests
/// </summary>
[TestClass]
public class IpV4AddressTests
{
public IpV4AddressTests()
{
//
// TODO: Add constructor logic here
//
}
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;
}
}
#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 IpV4AddressTest()
{
Assert.AreEqual("0.0.0.0", new IpV4Address(0).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());
}
}
}
<Project ToolsVersion="3.5" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<Configuration Condition=" '$(Configuration)' == '' ">Debug</Configuration>
<Platform Condition=" '$(Platform)' == '' ">AnyCPU</Platform>
<ProductVersion>9.0.21022</ProductVersion>
<SchemaVersion>2.0</SchemaVersion>
<ProjectGuid>{6C7326EB-F230-4934-B74B-F99F87204E44}</ProjectGuid>
<OutputType>Library</OutputType>
<AppDesignerFolder>Properties</AppDesignerFolder>
<RootNamespace>Packets.Test</RootNamespace>
<AssemblyName>Packets.Test</AssemblyName>
<TargetFrameworkVersion>v3.5</TargetFrameworkVersion>
<FileAlignment>512</FileAlignment>
<ProjectTypeGuids>{3AC096D0-A1C2-E12C-1390-A8335801FDAB};{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}</ProjectTypeGuids>
<SccProjectName>SAK</SccProjectName>
<SccLocalPath>SAK</SccLocalPath>
<SccAuxPath>SAK</SccAuxPath>
<SccProvider>SAK</SccProvider>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Debug|AnyCPU' ">
<DebugSymbols>true</DebugSymbols>
<DebugType>full</DebugType>
<Optimize>false</Optimize>
<OutputPath>bin\Debug\</OutputPath>
<DefineConstants>DEBUG;TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
<Optimize>true</Optimize>
<OutputPath>bin\Release\</OutputPath>
<DefineConstants>TRACE</DefineConstants>
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
</PropertyGroup>
<ItemGroup>
<Reference Include="Microsoft.VisualStudio.QualityTools.UnitTestFramework, Version=9.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a, processorArchitecture=MSIL" />
<Reference Include="System" />
<Reference Include="System.Core">
<RequiredTargetFramework>3.5</RequiredTargetFramework>
</Reference>
</ItemGroup>
<ItemGroup>
<Compile Include="Properties\AssemblyInfo.cs" />
<Compile Include="IpV4AddressTests.cs" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\Packets\Packets.csproj">
<Project>{8A184AF5-E46C-482C-81A3-76D8CE290104}</Project>
<Name>Packets</Name>
</ProjectReference>
</ItemGroup>
<Import Project="$(MSBuildBinPath)\Microsoft.CSharp.targets" />
<!-- To modify your build process, add your task inside one of the targets below and uncomment it.
Other similar extension points exist, see Microsoft.Common.targets.
<Target Name="BeforeBuild">
</Target>
<Target Name="AfterBuild">
</Target>
-->
</Project>
\ No newline at end of file
""
{
"FILE_VERSION" = "9237"
"ENLISTMENT_CHOICE" = "NEVER"
"PROJECT_FILE_RELATIVE_PATH" = ""
"NUMBER_OF_EXCLUDED_FILES" = "0"
"ORIGINAL_PROJECT_FILE_PATH" = ""
"NUMBER_OF_NESTED_PROJECTS" = "0"
"SOURCE_CONTROL_SETTINGS_PROVIDER" = "PROVIDER"
}
using System.Reflection;
using System.Runtime.CompilerServices;
using System.Runtime.InteropServices;
// General Information about an assembly is controlled through the following
// set of attributes. Change these attribute values to modify the information
// associated with an assembly.
[assembly: AssemblyTitle("Packets.Test")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("Packets.Test")]
[assembly: AssemblyCopyright("Copyright © 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM componenets. If you need to access a type in this assembly from
// COM, set the ComVisible attribute to true on that type.
[assembly: ComVisible(false)]
// The following GUID is for the ID of the typelib if this project is exposed to COM
[assembly: Guid("5484dcf9-1bd4-44f5-a709-a35d52f7415c")]
// Version information for an assembly consists of the following four values:
//
// Major Version
// Minor Version
// Build Number
// Revision
//
// You can specify all the values or you can default the Revision and Build Numbers
// by using the '*' as shown below:
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
using System.Text;
namespace Packets
{
public struct IpV4Address
{
public IpV4Address(uint value)
{
_value = value;
}
public uint ToUInt()
{
return _value;
}
public static IpV4Address FromReversedEndianity(uint value)
{
uint result = value >> 24;
result += (value >> 16) % 256 << 8;
result += (value >> 8) % 256 << 16;
result += value % 256 << 24;
return new IpV4Address(result);
}
public override string ToString()
{
StringBuilder stringBuilder = new StringBuilder(15);
stringBuilder.Append(_value >> 24);
stringBuilder.Append('.');
stringBuilder.Append((_value >> 16) % 256);
stringBuilder.Append('.');
stringBuilder.Append((_value >> 8) % 256);
stringBuilder.Append('.');
stringBuilder.Append(_value % 256);
return stringBuilder.ToString();
}
private readonly uint _value;
}
}
\ No newline at end of file
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
namespace Packets
{
......
......@@ -59,6 +59,7 @@
<Compile Include="EthernetDatagram.cs" />
<Compile Include="EthernetType.cs" />
<Compile Include="IDataLink.cs" />
<Compile Include="IpV4Address.cs" />
<Compile Include="MacAddress.cs" />
<Compile Include="MoreByteArray.cs" />
<Compile Include="Packet.cs" />
......
......@@ -33,4 +33,4 @@ using System.Runtime.InteropServices;
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("0.1.0.*")]
[assembly: AssemblyFileVersion("0.1.0.*")]
[assembly: AssemblyFileVersion("0.1.0.0")]
using System;
using System.Collections.Generic;
using System.IO;
using System.Net;
using System.Text.RegularExpressions;
using System.Threading;
using Packets;
using Microsoft.VisualStudio.TestTools.UnitTesting;
......@@ -637,11 +639,14 @@ namespace PcapDotNet.Core.Test
IList<LivePacketDevice> devices = LivePacketDevice.AllLocalMachine;
MoreAssert.IsBiggerOrEqual(1, devices.Count);
LivePacketDevice device = devices[0];
Assert.AreEqual("Network adapter 'Atheros AR8121/AR8113 PCI-E Ethernet Controller (Microsoft's Packet Scheduler) ' on local host", device.Description);
MoreAssert.IsMatch(@"Network adapter '.* \(Microsoft's Packet Scheduler\) ' on local host", device.Description);
Assert.AreEqual(DeviceAttributes.None, device.Attributes);
Assert.AreEqual(1, device.Addresses.Count);
DeviceAddress address = device.Addresses[0];
Assert.AreEqual("Address: " + SocketAddressFamily.Internet + " 10.0.0.2 Netmask: " + SocketAddressFamily.Internet + " 255.0.0.0 Broadcast: " + SocketAddressFamily.Internet + " 255.255.255.255", address.ToString());
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());
PacketCommunicator communicator = device.Open();
try
{
......
using System;
using System.Text.RegularExpressions;
using Microsoft.VisualStudio.TestTools.UnitTesting;
namespace PcapDotNet.Core.Test
......@@ -38,5 +39,10 @@ namespace PcapDotNet.Core.Test
IsBiggerOrEqual(expectedMinimum, actual);
IsSmallerOrEqual(expectedMaximum, actual);
}
public static void IsMatch(string expectedPattern, string actualValue)
{
Assert.IsTrue(Regex.IsMatch(actualValue, expectedPattern), "Expected pattern: <" + expectedPattern + ">. Actual value: <" + actualValue + ">.");
}
}
}
\ No newline at end of file
using System;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using Packets;
namespace PcapDotNet.Core.Test
{
......
......@@ -65,7 +65,7 @@ namespace PcapDotNet.Core.Test
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 + "$";
string version = PcapLibrary.Version;
Assert.IsTrue(Regex.IsMatch(version, VersionRegex), "Version " + version + " doesn't match regex " + VersionRegex);
MoreAssert.IsMatch(VersionRegex, version);
}
}
}
......@@ -77,7 +77,7 @@ void BerkeleyPacketFilter::Initialize(pcap_t* pcapDescriptor, String^ filterStri
unsigned int netmaskValue = 0;
if (netmask != nullptr)
netmaskValue = netmask->Address;
netmaskValue = netmask->Address.ToUInt();
_bpf = new bpf_program();
......
......@@ -4,38 +4,16 @@
using namespace System;
using namespace System::Text;
using namespace PcapDotNet::Core;
using namespace Packets;
IpV4SocketAddress::IpV4SocketAddress(sockaddr *address)
: SocketAddress(address->sa_family)
{
sockaddr_in* ipV4Address = (struct sockaddr_in *)address;
_address = ipV4Address->sin_addr.S_un.S_addr;
}
unsigned int IpV4SocketAddress::Address::get()
IpV4Address IpV4SocketAddress::Address::get()
{
return _address;
}
String^ IpV4SocketAddress::AddressString::get()
{
StringBuilder^ result = gcnew StringBuilder();
unsigned int address = Address;
result->Append(address % 256);
result->Append(".");
address /= 256;
result->Append(address % 256);
result->Append(".");
address /= 256;
result->Append(address % 256);
result->Append(".");
address /= 256;
result->Append(address % 256);
return result->ToString();
return Address.ToString();
}
String^ IpV4SocketAddress::ToString()
......@@ -46,3 +24,12 @@ String^ IpV4SocketAddress::ToString()
result->Append(AddressString);
return result->ToString();
}
// Internal
IpV4SocketAddress::IpV4SocketAddress(sockaddr *address)
: SocketAddress(address->sa_family)
{
sockaddr_in* ipV4Address = (struct sockaddr_in *)address;
_address = IpV4Address::FromReversedEndianity(ipV4Address->sin_addr.S_un.S_addr);
}
......@@ -7,12 +7,10 @@ namespace PcapDotNet { namespace Core
{
public ref class IpV4SocketAddress : SocketAddress
{
public:
IpV4SocketAddress(sockaddr *address);
property unsigned int Address
public:
property Packets::IpV4Address Address
{
unsigned int get();
Packets::IpV4Address get();
}
property System::String^ AddressString
......@@ -22,7 +20,10 @@ namespace PcapDotNet { namespace Core
virtual System::String^ ToString() override;
internal:
IpV4SocketAddress(sockaddr *address);
private:
unsigned int _address;
Packets::IpV4Address _address;
};
}}
\ No newline at end of file
......@@ -15,9 +15,11 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Packets", "Packets\Packets.csproj", "{8A184AF5-E46C-482C-81A3-76D8CE290104}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Packets.Test", "Packets.Test\Packets.Test.csproj", "{6C7326EB-F230-4934-B74B-F99F87204E44}"
EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects = 5
SccNumberOfProjects = 6
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://tfs06.codeplex.com/
SccLocalPath0 = .
......@@ -33,6 +35,9 @@ Global
SccProjectUniqueName4 = Packets\\Packets.csproj
SccProjectName4 = Packets
SccLocalPath4 = Packets
SccProjectUniqueName5 = Packets.Test\\Packets.Test.csproj
SccProjectName5 = Packets.Test
SccLocalPath5 = Packets.Test
EndGlobalSection
GlobalSection(TestCaseManagementSettings) = postSolution
CategoryFile = PcapDotNet.vsmdi
......@@ -88,6 +93,16 @@ Global
{8A184AF5-E46C-482C-81A3-76D8CE290104}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{8A184AF5-E46C-482C-81A3-76D8CE290104}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{8A184AF5-E46C-482C-81A3-76D8CE290104}.Release|Win32.ActiveCfg = Release|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Debug|Any CPU.Build.0 = Debug|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Debug|Mixed Platforms.ActiveCfg = Debug|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Debug|Mixed Platforms.Build.0 = Debug|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Debug|Win32.ActiveCfg = Debug|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Any CPU.ActiveCfg = Release|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Any CPU.Build.0 = Release|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Mixed Platforms.ActiveCfg = Release|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Mixed Platforms.Build.0 = Release|Any CPU
{6C7326EB-F230-4934-B74B-F99F87204E44}.Release|Win32.ActiveCfg = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
......
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