Commit 34ce48d6 authored by Brickner_cp's avatar Brickner_cp

--no commit message

--no commit message
parent 7cb2d82d
<?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.Core\PcapDotNet.Core.snk">
<CodeCoverage enabled="true" keyFile="PcapDotNet.snk">
<Regular>
<CodeCoverageItem binaryFile="c:\Documents and Settings\Boaz\My Documents\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.dll" pdbFile="c:\Documents and Settings\Boaz\My Documents\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\PcapDotNet.Core.pdb" instrumentInPlace="true" />
<CodeCoverageItem binaryFile="C:\Documents and Settings\Boaz\My Documents\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\Packets.dll" pdbFile="C:\Documents and Settings\Boaz\My Documents\TFS\tfs06.codeplex.com\PcapDotNet\PcapDotNet\bin\Debug\Packets.pdb" instrumentInPlace="true" />
</Regular>
</CodeCoverage>
<TestTypeSpecific>
......
......@@ -29,6 +29,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType>
......@@ -38,7 +39,7 @@
<ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunCodeAnalysis>false</RunCodeAnalysis>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup>
<ItemGroup>
<Reference Include="System" />
......
......@@ -80,25 +80,25 @@ namespace PcapDotNet.Core.Test
{
using (PacketCommunicator communicator = LivePacketDeviceTests.OpenLiveDevice())
{
communicator.SetFilter(filter);
for (int i = 0; i != 5; ++i)
{
communicator.SendPacket(expectedPacket);
communicator.SendPacket(unexpectedPacket);
TestFilter(communicator, filter, expectedPacket, unexpectedPacket);
}
}
}
Packet packet;
PacketCommunicatorReceiveResult result;
for (int i = 0; i != 5; ++i)
[TestMethod]
public void NoCommunicatorConstructorWithNetmaskTest()
{
result = communicator.ReceivePacket(out packet);
Assert.AreEqual(PacketCommunicatorReceiveResult.Ok, result);
Assert.AreEqual(expectedPacket, packet);
}
const string SourceMac = "11:22:33:44:55:66";
const string DestinationMac = "77:88:99:AA:BB:CC";
result = communicator.ReceivePacket(out packet);
Assert.AreEqual(PacketCommunicatorReceiveResult.Timeout, result);
Assert.IsNull(packet);
Packet expectedPacket = MoreRandom.BuildRandomPacket(SourceMac, DestinationMac, 1000);
Packet unexpectedPacket = MoreRandom.BuildRandomPacket(DestinationMac, SourceMac, 1000);
using (PacketCommunicator communicator = LivePacketDeviceTests.OpenLiveDevice())
{
using (BerkeleyPacketFilter filter = new BerkeleyPacketFilter("ether src " + SourceMac + " and ether dst " + DestinationMac, 1000, DataLinkKind.Ethernet, communicator.IpV4Netmask))
{
TestFilter(communicator, filter, expectedPacket, unexpectedPacket);
}
}
}
......@@ -126,5 +126,28 @@ namespace PcapDotNet.Core.Test
Assert.AreEqual(snapshotLength, actualSnapshotLength);
}
}
private static void TestFilter(PacketCommunicator communicator, BerkeleyPacketFilter filter, Packet expectedPacket, Packet unexpectedPacket)
{
communicator.SetFilter(filter);
for (int i = 0; i != 5; ++i)
{
communicator.SendPacket(expectedPacket);
communicator.SendPacket(unexpectedPacket);
}
Packet packet;
PacketCommunicatorReceiveResult result;
for (int i = 0; i != 5; ++i)
{
result = communicator.ReceivePacket(out packet);
Assert.AreEqual(PacketCommunicatorReceiveResult.Ok, result);
Assert.AreEqual(expectedPacket, packet);
}
result = communicator.ReceivePacket(out packet);
Assert.AreEqual(PacketCommunicatorReceiveResult.Timeout, result);
Assert.IsNull(packet);
}
}
}
\ No newline at end of file
......@@ -652,11 +652,14 @@ namespace PcapDotNet.Core.Test
{
PacketTotalStatistics totalStatistics = communicator.TotalStatistics;
Assert.AreEqual(totalStatistics, totalStatistics);
Assert.AreEqual(totalStatistics.GetHashCode(), totalStatistics.GetHashCode());
Assert.IsTrue(totalStatistics.Equals(totalStatistics));
Assert.AreNotEqual(null, totalStatistics);
Assert.AreEqual(0, totalStatistics.PacketsCaptured);
Assert.AreEqual(0, totalStatistics.PacketsDroppedByDriver);
Assert.AreEqual(0, totalStatistics.PacketsDroppedByInterface);
Assert.AreEqual(0, totalStatistics.PacketsReceived);
Assert.AreEqual<uint>(0, totalStatistics.PacketsCaptured, "PacketsCaptured");
Assert.AreEqual<uint>(0, totalStatistics.PacketsDroppedByDriver, "PacketsDroppedByDriver");
Assert.AreEqual<uint>(0, totalStatistics.PacketsDroppedByInterface, "PacketsDroppedByInterface");
Assert.AreEqual<uint>(0, totalStatistics.PacketsReceived, "PacketsReceived");
Assert.IsNotNull(totalStatistics.ToString());
communicator.SetKernelBufferSize(2 * 1024 * 1024); // 2 MB instead of 1
communicator.SetKernelMinimumBytesToCopy(10); // 10 bytes minimum to copy
communicator.SetSamplingMethod(new SamplingMethodNone());
......
......@@ -247,6 +247,13 @@ namespace PcapDotNet.Core.Test
}
}
[TestMethod]
[ExpectedException(typeof(InvalidOperationException))]
public void DumpToBadFileTest()
{
OpenOfflineDevice(10, MoreRandom.BuildRandomPacket(100), TimeSpan.Zero, "??");
}
private static void TestGetSomePackets(int numPacketsToSend, int numPacketsToGet, int numPacketsToBreakLoop,
PacketCommunicatorReceiveResult expectedResult, int expectedNumPackets,
double expectedMinSeconds, double expectedMaxSeconds)
......@@ -325,8 +332,11 @@ namespace PcapDotNet.Core.Test
public static PacketCommunicator OpenOfflineDevice(int numPackets, Packet packet, TimeSpan intervalBetweenPackets)
{
string dumpFilename = Path.GetTempPath() + @"dump.pcap";
return OpenOfflineDevice(numPackets, packet, intervalBetweenPackets, Path.GetTempPath() + @"dump.pcap");
}
private static PacketCommunicator OpenOfflineDevice(int numPackets, Packet packet, TimeSpan intervalBetweenPackets, string dumpFilename)
{
PacketCommunicator communicator;
using (communicator = LivePacketDeviceTests.OpenLiveDevice())
{
......@@ -337,7 +347,6 @@ namespace PcapDotNet.Core.Test
{
if (intervalBetweenPackets != TimeSpan.Zero && i != 0)
{
// Thread.Sleep(intervalBetweenPackets);
DateTime timestamp = packet.Timestamp;
timestamp = timestamp.Add(intervalBetweenPackets);
packet = new Packet(packet.Buffer, timestamp, packet.DataLink);
......
......@@ -62,6 +62,7 @@ namespace PcapDotNet.Core.Test
{
PcapDataLink dataLink = new PcapDataLink();
Assert.AreEqual(new PcapDataLink("NULL"), dataLink);
string previousDataLinkName = null;
for (int i = 0; i != 1000; ++i)
{
dataLink = new PcapDataLink(i);
......@@ -77,11 +78,15 @@ namespace PcapDotNet.Core.Test
}
Assert.AreEqual(new PcapDataLink(dataLinkName), dataLink);
Assert.IsFalse(dataLink.Equals(null));
Assert.IsTrue(new PcapDataLink(dataLinkName) == dataLink);
Assert.IsFalse(new PcapDataLink(dataLinkName) != dataLink);
Assert.IsTrue(previousDataLinkName == null || new PcapDataLink(previousDataLinkName) != dataLink);
Assert.IsNotNull(dataLink.Description);
Assert.AreEqual(i, dataLink.Value);
Assert.AreEqual(dataLink.Value.GetHashCode(), dataLink.GetHashCode());
previousDataLinkName = dataLinkName;
}
}
......
......@@ -28,7 +28,7 @@ PacketCommunicator::PacketCommunicator(const char* source, int snapshotLength, P
if (pcapDescriptor == NULL)
{
throw gcnew InvalidOperationException(String::Format(CultureInfo::InvariantCulture, "Unable to open the adapter. %s is not supported by WinPcap", gcnew String(source)));
throw gcnew InvalidOperationException("Unable to open the adapter. " + gcnew String(source) + " is not supported by WinPcap");
}
_pcapDescriptor = pcapDescriptor;
......@@ -76,6 +76,11 @@ int PacketCommunicator::SnapshotLength::get()
return pcap_snapshot(_pcapDescriptor);
}
IpV4SocketAddress^ PacketCommunicator::IpV4Netmask::get()
{
return _ipV4Netmask;
}
bool PacketCommunicator::IsFileSystemByteOrder::get()
{
return (pcap_is_swapped(_pcapDescriptor) == 0);
......
......@@ -51,6 +51,14 @@ namespace PcapDotNet { namespace Core
int get();
}
/// <summary>
/// The IPv4 netmask of the network on which packets are being captured; useful for filters when checking for IPv4 broadcast addresses in the filter program. If the netmask of the network on which packets are being captured isn't known to the program, or if packets are being captured on the Linux "any" pseudo-interface that can capture on more than one network, the value will be null and a filter that tests for IPv4 broadcast addreses won't be done correctly, but all other tests in the filter program will be OK.
/// </summary>
property IpV4SocketAddress^ IpV4Netmask
{
IpV4SocketAddress^ get();
}
/// <summary>
/// True if the current file uses a different byte order than the current system.
/// </summary>
......
......@@ -132,7 +132,7 @@
<Tool
Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;..\..\3rdParty\WpdPack\Include&quot;"
PreprocessorDefinitions="WIN32;NDEBUG"
PreprocessorDefinitions="WIN32;NDEBUG;CODE_ANALYSIS"
RuntimeLibrary="2"
UsePrecompiledHeader="0"
WarningLevel="3"
......@@ -171,6 +171,7 @@
/>
<Tool
Name="VCFxCopTool"
EnableFxCop="true"
/>
<Tool
Name="VCAppVerifierTool"
......
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