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"?> <?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"> <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> <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> <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\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> </Regular>
</CodeCoverage> </CodeCoverage>
<TestTypeSpecific> <TestTypeSpecific>
......
...@@ -29,6 +29,7 @@ ...@@ -29,6 +29,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup> </PropertyGroup>
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' "> <PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|AnyCPU' ">
<DebugType>pdbonly</DebugType> <DebugType>pdbonly</DebugType>
...@@ -38,7 +39,7 @@ ...@@ -38,7 +39,7 @@
<ErrorReport>prompt</ErrorReport> <ErrorReport>prompt</ErrorReport>
<WarningLevel>4</WarningLevel> <WarningLevel>4</WarningLevel>
<AllowUnsafeBlocks>true</AllowUnsafeBlocks> <AllowUnsafeBlocks>true</AllowUnsafeBlocks>
<RunCodeAnalysis>false</RunCodeAnalysis> <RunCodeAnalysis>true</RunCodeAnalysis>
</PropertyGroup> </PropertyGroup>
<ItemGroup> <ItemGroup>
<Reference Include="System" /> <Reference Include="System" />
......
...@@ -80,25 +80,25 @@ namespace PcapDotNet.Core.Test ...@@ -80,25 +80,25 @@ namespace PcapDotNet.Core.Test
{ {
using (PacketCommunicator communicator = LivePacketDeviceTests.OpenLiveDevice()) using (PacketCommunicator communicator = LivePacketDeviceTests.OpenLiveDevice())
{ {
communicator.SetFilter(filter); TestFilter(communicator, filter, expectedPacket, unexpectedPacket);
for (int i = 0; i != 5; ++i) }
{ }
communicator.SendPacket(expectedPacket); }
communicator.SendPacket(unexpectedPacket);
} [TestMethod]
public void NoCommunicatorConstructorWithNetmaskTest()
Packet packet; {
PacketCommunicatorReceiveResult result; const string SourceMac = "11:22:33:44:55:66";
for (int i = 0; i != 5; ++i) const string DestinationMac = "77:88:99:AA:BB:CC";
{
result = communicator.ReceivePacket(out packet); Packet expectedPacket = MoreRandom.BuildRandomPacket(SourceMac, DestinationMac, 1000);
Assert.AreEqual(PacketCommunicatorReceiveResult.Ok, result); Packet unexpectedPacket = MoreRandom.BuildRandomPacket(DestinationMac, SourceMac, 1000);
Assert.AreEqual(expectedPacket, packet);
} using (PacketCommunicator communicator = LivePacketDeviceTests.OpenLiveDevice())
{
result = communicator.ReceivePacket(out packet); using (BerkeleyPacketFilter filter = new BerkeleyPacketFilter("ether src " + SourceMac + " and ether dst " + DestinationMac, 1000, DataLinkKind.Ethernet, communicator.IpV4Netmask))
Assert.AreEqual(PacketCommunicatorReceiveResult.Timeout, result); {
Assert.IsNull(packet); TestFilter(communicator, filter, expectedPacket, unexpectedPacket);
} }
} }
} }
...@@ -126,5 +126,28 @@ namespace PcapDotNet.Core.Test ...@@ -126,5 +126,28 @@ namespace PcapDotNet.Core.Test
Assert.AreEqual(snapshotLength, actualSnapshotLength); 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 ...@@ -652,11 +652,14 @@ namespace PcapDotNet.Core.Test
{ {
PacketTotalStatistics totalStatistics = communicator.TotalStatistics; PacketTotalStatistics totalStatistics = communicator.TotalStatistics;
Assert.AreEqual(totalStatistics, totalStatistics); Assert.AreEqual(totalStatistics, totalStatistics);
Assert.AreEqual(totalStatistics.GetHashCode(), totalStatistics.GetHashCode());
Assert.IsTrue(totalStatistics.Equals(totalStatistics));
Assert.AreNotEqual(null, totalStatistics); Assert.AreNotEqual(null, totalStatistics);
Assert.AreEqual(0, totalStatistics.PacketsCaptured); Assert.AreEqual<uint>(0, totalStatistics.PacketsCaptured, "PacketsCaptured");
Assert.AreEqual(0, totalStatistics.PacketsDroppedByDriver); Assert.AreEqual<uint>(0, totalStatistics.PacketsDroppedByDriver, "PacketsDroppedByDriver");
Assert.AreEqual(0, totalStatistics.PacketsDroppedByInterface); Assert.AreEqual<uint>(0, totalStatistics.PacketsDroppedByInterface, "PacketsDroppedByInterface");
Assert.AreEqual(0, totalStatistics.PacketsReceived); Assert.AreEqual<uint>(0, totalStatistics.PacketsReceived, "PacketsReceived");
Assert.IsNotNull(totalStatistics.ToString());
communicator.SetKernelBufferSize(2 * 1024 * 1024); // 2 MB instead of 1 communicator.SetKernelBufferSize(2 * 1024 * 1024); // 2 MB instead of 1
communicator.SetKernelMinimumBytesToCopy(10); // 10 bytes minimum to copy communicator.SetKernelMinimumBytesToCopy(10); // 10 bytes minimum to copy
communicator.SetSamplingMethod(new SamplingMethodNone()); communicator.SetSamplingMethod(new SamplingMethodNone());
......
...@@ -247,6 +247,13 @@ namespace PcapDotNet.Core.Test ...@@ -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, private static void TestGetSomePackets(int numPacketsToSend, int numPacketsToGet, int numPacketsToBreakLoop,
PacketCommunicatorReceiveResult expectedResult, int expectedNumPackets, PacketCommunicatorReceiveResult expectedResult, int expectedNumPackets,
double expectedMinSeconds, double expectedMaxSeconds) double expectedMinSeconds, double expectedMaxSeconds)
...@@ -325,8 +332,11 @@ namespace PcapDotNet.Core.Test ...@@ -325,8 +332,11 @@ namespace PcapDotNet.Core.Test
public static PacketCommunicator OpenOfflineDevice(int numPackets, Packet packet, TimeSpan intervalBetweenPackets) 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; PacketCommunicator communicator;
using (communicator = LivePacketDeviceTests.OpenLiveDevice()) using (communicator = LivePacketDeviceTests.OpenLiveDevice())
{ {
...@@ -337,7 +347,6 @@ namespace PcapDotNet.Core.Test ...@@ -337,7 +347,6 @@ namespace PcapDotNet.Core.Test
{ {
if (intervalBetweenPackets != TimeSpan.Zero && i != 0) if (intervalBetweenPackets != TimeSpan.Zero && i != 0)
{ {
// Thread.Sleep(intervalBetweenPackets);
DateTime timestamp = packet.Timestamp; DateTime timestamp = packet.Timestamp;
timestamp = timestamp.Add(intervalBetweenPackets); timestamp = timestamp.Add(intervalBetweenPackets);
packet = new Packet(packet.Buffer, timestamp, packet.DataLink); packet = new Packet(packet.Buffer, timestamp, packet.DataLink);
......
...@@ -62,6 +62,7 @@ namespace PcapDotNet.Core.Test ...@@ -62,6 +62,7 @@ namespace PcapDotNet.Core.Test
{ {
PcapDataLink dataLink = new PcapDataLink(); PcapDataLink dataLink = new PcapDataLink();
Assert.AreEqual(new PcapDataLink("NULL"), dataLink); Assert.AreEqual(new PcapDataLink("NULL"), dataLink);
string previousDataLinkName = null;
for (int i = 0; i != 1000; ++i) for (int i = 0; i != 1000; ++i)
{ {
dataLink = new PcapDataLink(i); dataLink = new PcapDataLink(i);
...@@ -77,11 +78,15 @@ namespace PcapDotNet.Core.Test ...@@ -77,11 +78,15 @@ namespace PcapDotNet.Core.Test
} }
Assert.AreEqual(new PcapDataLink(dataLinkName), dataLink); Assert.AreEqual(new PcapDataLink(dataLinkName), dataLink);
Assert.IsFalse(dataLink.Equals(null));
Assert.IsTrue(new PcapDataLink(dataLinkName) == dataLink); Assert.IsTrue(new PcapDataLink(dataLinkName) == dataLink);
Assert.IsFalse(new PcapDataLink(dataLinkName) != dataLink); Assert.IsFalse(new PcapDataLink(dataLinkName) != dataLink);
Assert.IsTrue(previousDataLinkName == null || new PcapDataLink(previousDataLinkName) != dataLink);
Assert.IsNotNull(dataLink.Description); Assert.IsNotNull(dataLink.Description);
Assert.AreEqual(i, dataLink.Value); Assert.AreEqual(i, dataLink.Value);
Assert.AreEqual(dataLink.Value.GetHashCode(), dataLink.GetHashCode()); Assert.AreEqual(dataLink.Value.GetHashCode(), dataLink.GetHashCode());
previousDataLinkName = dataLinkName;
} }
} }
......
...@@ -28,7 +28,7 @@ PacketCommunicator::PacketCommunicator(const char* source, int snapshotLength, P ...@@ -28,7 +28,7 @@ PacketCommunicator::PacketCommunicator(const char* source, int snapshotLength, P
if (pcapDescriptor == NULL) 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; _pcapDescriptor = pcapDescriptor;
...@@ -76,6 +76,11 @@ int PacketCommunicator::SnapshotLength::get() ...@@ -76,6 +76,11 @@ int PacketCommunicator::SnapshotLength::get()
return pcap_snapshot(_pcapDescriptor); return pcap_snapshot(_pcapDescriptor);
} }
IpV4SocketAddress^ PacketCommunicator::IpV4Netmask::get()
{
return _ipV4Netmask;
}
bool PacketCommunicator::IsFileSystemByteOrder::get() bool PacketCommunicator::IsFileSystemByteOrder::get()
{ {
return (pcap_is_swapped(_pcapDescriptor) == 0); return (pcap_is_swapped(_pcapDescriptor) == 0);
......
...@@ -51,6 +51,14 @@ namespace PcapDotNet { namespace Core ...@@ -51,6 +51,14 @@ namespace PcapDotNet { namespace Core
int get(); 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> /// <summary>
/// True if the current file uses a different byte order than the current system. /// True if the current file uses a different byte order than the current system.
/// </summary> /// </summary>
......
...@@ -132,7 +132,7 @@ ...@@ -132,7 +132,7 @@
<Tool <Tool
Name="VCCLCompilerTool" Name="VCCLCompilerTool"
AdditionalIncludeDirectories="&quot;..\..\3rdParty\WpdPack\Include&quot;" AdditionalIncludeDirectories="&quot;..\..\3rdParty\WpdPack\Include&quot;"
PreprocessorDefinitions="WIN32;NDEBUG" PreprocessorDefinitions="WIN32;NDEBUG;CODE_ANALYSIS"
RuntimeLibrary="2" RuntimeLibrary="2"
UsePrecompiledHeader="0" UsePrecompiledHeader="0"
WarningLevel="3" WarningLevel="3"
...@@ -171,6 +171,7 @@ ...@@ -171,6 +171,7 @@
/> />
<Tool <Tool
Name="VCFxCopTool" Name="VCFxCopTool"
EnableFxCop="true"
/> />
<Tool <Tool
Name="VCAppVerifierTool" 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