Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Contribute to GitLab
Sign in / Register
Toggle navigation
P
Pcap-Net
Project
Project
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Administrator
Pcap-Net
Commits
0322390e
Commit
0322390e
authored
Jul 25, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed Access Violation bug.
Added example project PcapDotNet.DevelopersPack.
parent
bd1582d5
Hide whitespace changes
Inline
Side-by-side
Showing
15 changed files
with
633 additions
and
11 deletions
+633
-11
InterpretingThePackets.csproj
.../src/InterpretingThePackets/InterpretingThePackets.csproj
+71
-0
InterpretingThePackets.csproj.vspscc
...terpretingThePackets/InterpretingThePackets.csproj.vspscc
+10
-0
Program.cs
...tNet.DevelopersPack/src/InterpretingThePackets/Program.cs
+89
-0
AssemblyInfo.cs
...ack/src/InterpretingThePackets/Properties/AssemblyInfo.cs
+36
-0
PcapDotNet.DevelopersPack.sln
PcapDotNet.DevelopersPack/src/PcapDotNet.DevelopersPack.sln
+28
-1
Program.cs
...DevelopersPack/src/ReadingPacketsFromADumpFile/Program.cs
+55
-0
AssemblyInfo.cs
...rc/ReadingPacketsFromADumpFile/Properties/AssemblyInfo.cs
+36
-0
ReadingPacketsFromADumpFile.csproj
...ngPacketsFromADumpFile/ReadingPacketsFromADumpFile.csproj
+71
-0
ReadingPacketsFromADumpFile.csproj.vspscc
...tsFromADumpFile/ReadingPacketsFromADumpFile.csproj.vspscc
+10
-0
Program.cs
...et.DevelopersPack/src/SavingPacketsToADumpFile/Program.cs
+75
-0
AssemblyInfo.cs
...k/src/SavingPacketsToADumpFile/Properties/AssemblyInfo.cs
+36
-0
SavingPacketsToADumpFile.csproj
.../SavingPacketsToADumpFile/SavingPacketsToADumpFile.csproj
+71
-0
SavingPacketsToADumpFile.csproj.vspscc
...PacketsToADumpFile/SavingPacketsToADumpFile.csproj.vspscc
+10
-0
OfflinePacketDeviceTests.cs
...tNet/src/PcapDotNet.Core.Test/OfflinePacketDeviceTests.cs
+30
-10
PacketCommunicator.cpp
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.cpp
+5
-0
No files found.
PcapDotNet.DevelopersPack/src/InterpretingThePackets/InterpretingThePackets.csproj
0 → 100644
View file @
0322390e
<?xml version="1.0" encoding="utf-8"?>
<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>
{C98B950D-E0DE-4250-9B14-4146FCBAEBAA}
</ProjectGuid>
<OutputType>
Exe
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
InterpretingThePackets
</RootNamespace>
<AssemblyName>
InterpretingThePackets
</AssemblyName>
<TargetFrameworkVersion>
v3.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<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=
"Packets, Version=0.1.0.33384, Culture=neutral, PublicKeyToken=58cf32d85728e684, processorArchitecture=MSIL"
>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
..\..\3rdParty\PcapDotNet\Packets.dll
</HintPath>
</Reference>
<Reference
Include=
"PcapDotNet.Core, Version=0.1.0.33550, Culture=neutral, PublicKeyToken=58cf32d85728e684, processorArchitecture=x86"
>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
..\..\3rdParty\PcapDotNet\PcapDotNet.Core.dll
</HintPath>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Xml.Linq"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Data.DataSetExtensions"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\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
PcapDotNet.DevelopersPack/src/InterpretingThePackets/InterpretingThePackets.csproj.vspscc
0 → 100644
View file @
0322390e
""
{
"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"
}
PcapDotNet.DevelopersPack/src/InterpretingThePackets/Program.cs
0 → 100644
View file @
0322390e
using
System
;
using
System.Collections.Generic
;
using
Packets
;
using
PcapDotNet.Core
;
namespace
InterpretingThePackets
{
class
Program
{
static
void
Main
(
string
[]
args
)
{
// Retrieve the device list from the local machine
IList
<
LivePacketDevice
>
allDevices
=
LivePacketDevice
.
AllLocalMachine
;
if
(
allDevices
.
Count
==
0
)
{
Console
.
WriteLine
(
"No interfaces found! Make sure WinPcap is installed."
);
return
;
}
// Print the list
for
(
int
i
=
0
;
i
!=
allDevices
.
Count
;
++
i
)
{
LivePacketDevice
device
=
allDevices
[
i
];
Console
.
Write
((
i
+
1
)
+
". "
+
device
.
Name
);
if
(
device
.
Description
!=
null
)
Console
.
WriteLine
(
" ("
+
device
.
Description
+
")"
);
else
Console
.
WriteLine
(
" (No description available)"
);
}
int
deviceIndex
=
0
;
do
{
Console
.
WriteLine
(
"Enter the interface number (1-"
+
allDevices
.
Count
+
"):"
);
string
deviceIndexString
=
Console
.
ReadLine
();
if
(!
int
.
TryParse
(
deviceIndexString
,
out
deviceIndex
)
||
deviceIndex
<
1
||
deviceIndex
>
allDevices
.
Count
)
{
deviceIndex
=
0
;
}
}
while
(
deviceIndex
==
0
);
// Take the selected adapter
PacketDevice
selectedDevice
=
allDevices
[
deviceIndex
-
1
];
// Open the device
using
(
PacketCommunicator
communicator
=
selectedDevice
.
Open
(
65536
,
// portion of the packet to capture
// 65536 guarantees that the whole packet will be captured on all the link layers
PacketDeviceOpenAttributes
.
Promiscuous
,
// promiscuous mode
1000
))
// read timeout
{
// Check the link layer. We support only Ethernet for simplicity.
if
(
communicator
.
DataLink
.
Kind
!=
DataLinkKind
.
Ethernet
)
{
Console
.
WriteLine
(
"This program works only on Ethernet networks."
);
return
;
}
// Compile the filter
using
(
BerkeleyPacketFilter
filter
=
communicator
.
CreateFilter
(
"ip and udp"
))
{
// Set the filter
communicator
.
SetFilter
(
filter
);
}
Console
.
WriteLine
(
"Listening on "
+
selectedDevice
.
Description
+
"..."
);
// start the capture
communicator
.
ReceivePackets
(
0
,
PacketHandler
);
}
}
// Callback function invoked by libpcap for every incoming packet
private
static
void
PacketHandler
(
Packet
packet
)
{
// print timestamp and length of the packet
Console
.
WriteLine
(
packet
.
Timestamp
.
ToString
(
"yyyy-MM-dd hh:mm:ss.fff"
)
+
" length:"
+
packet
.
Length
);
// TODO
//IpV4Datagram ip = packet.Ethernet.IpV4;
//UdpDatagram udp = ip.Udp;
// print ip addresses and udp ports
//Console.WriteLine(ip.Source + ":" + udp.Source + " -> " + ip.Destination + ":" + udp.Destination);
}
}
}
PcapDotNet.DevelopersPack/src/InterpretingThePackets/Properties/AssemblyInfo.cs
0 → 100644
View file @
0322390e
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("InterpretingThePackets")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("InterpretingThePackets")]
[assembly: AssemblyCopyright("Copyright © 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. 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("bd8564f1-6c6f-4e6a-92a9-20c93c294760")]
// 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 Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
PcapDotNet.DevelopersPack/src/PcapDotNet.DevelopersPack.sln
View file @
0322390e
...
...
@@ -9,9 +9,15 @@ Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpeningAnAdapterAndCapturin
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "CapturingThePacketsWithoutTheCallback", "CapturingThePacketsWithoutTheCallback\CapturingThePacketsWithoutTheCallback.csproj", "{A1E8AD04-50A1-409D-9E0F-5D10E36DF9F7}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "InterpretingThePackets", "InterpretingThePackets\InterpretingThePackets.csproj", "{C98B950D-E0DE-4250-9B14-4146FCBAEBAA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SavingPacketsToADumpFile", "SavingPacketsToADumpFile\SavingPacketsToADumpFile.csproj", "{17FAC756-D60D-46E5-A996-876B05BDFE69}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "ReadingPacketsFromADumpFile", "ReadingPacketsFromADumpFile\ReadingPacketsFromADumpFile.csproj", "{E94AA408-15EE-426B-8478-1453EA5A515A}"
EndProject
Global
GlobalSection(TeamFoundationVersionControl) = preSolution
SccNumberOfProjects =
5
SccNumberOfProjects =
8
SccEnterpriseProvider = {4CA58AB2-18FA-4F8D-95D4-32DDF27D184C}
SccTeamFoundationServer = https://tfs06.codeplex.com/
SccLocalPath0 = .
...
...
@@ -27,6 +33,15 @@ Global
SccProjectUniqueName4 = CapturingThePacketsWithoutTheCallback\\CapturingThePacketsWithoutTheCallback.csproj
SccProjectName4 = CapturingThePacketsWithoutTheCallback
SccLocalPath4 = CapturingThePacketsWithoutTheCallback
SccProjectUniqueName5 = InterpretingThePackets\\InterpretingThePackets.csproj
SccProjectName5 = InterpretingThePackets
SccLocalPath5 = InterpretingThePackets
SccProjectUniqueName6 = SavingPacketsToADumpFile\\SavingPacketsToADumpFile.csproj
SccProjectName6 = SavingPacketsToADumpFile
SccLocalPath6 = SavingPacketsToADumpFile
SccProjectUniqueName7 = ReadingPacketsFromADumpFile\\ReadingPacketsFromADumpFile.csproj
SccProjectName7 = ReadingPacketsFromADumpFile
SccLocalPath7 = ReadingPacketsFromADumpFile
EndGlobalSection
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -49,6 +64,18 @@ Global
{A1E8AD04-50A1-409D-9E0F-5D10E36DF9F7}.Debug|Any CPU.Build.0 = Debug|Any CPU
{A1E8AD04-50A1-409D-9E0F-5D10E36DF9F7}.Release|Any CPU.ActiveCfg = Release|Any CPU
{A1E8AD04-50A1-409D-9E0F-5D10E36DF9F7}.Release|Any CPU.Build.0 = Release|Any CPU
{C98B950D-E0DE-4250-9B14-4146FCBAEBAA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{C98B950D-E0DE-4250-9B14-4146FCBAEBAA}.Debug|Any CPU.Build.0 = Debug|Any CPU
{C98B950D-E0DE-4250-9B14-4146FCBAEBAA}.Release|Any CPU.ActiveCfg = Release|Any CPU
{C98B950D-E0DE-4250-9B14-4146FCBAEBAA}.Release|Any CPU.Build.0 = Release|Any CPU
{17FAC756-D60D-46E5-A996-876B05BDFE69}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{17FAC756-D60D-46E5-A996-876B05BDFE69}.Debug|Any CPU.Build.0 = Debug|Any CPU
{17FAC756-D60D-46E5-A996-876B05BDFE69}.Release|Any CPU.ActiveCfg = Release|Any CPU
{17FAC756-D60D-46E5-A996-876B05BDFE69}.Release|Any CPU.Build.0 = Release|Any CPU
{E94AA408-15EE-426B-8478-1453EA5A515A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{E94AA408-15EE-426B-8478-1453EA5A515A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{E94AA408-15EE-426B-8478-1453EA5A515A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{E94AA408-15EE-426B-8478-1453EA5A515A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
PcapDotNet.DevelopersPack/src/ReadingPacketsFromADumpFile/Program.cs
0 → 100644
View file @
0322390e
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading
;
using
Packets
;
using
PcapDotNet.Core
;
namespace
ReadingPacketsFromADumpFile
{
class
Program
{
static
void
Main
(
string
[]
args
)
{
// Check command line
if
(
args
.
Length
!=
1
)
{
Console
.
WriteLine
(
"usage: "
+
Environment
.
GetCommandLineArgs
()[
0
]
+
" <filename>"
);
return
;
}
// Create the offline device
OfflinePacketDevice
selectedDevice
=
new
OfflinePacketDevice
(
args
[
0
]);
// Open the capture file
using
(
PacketCommunicator
communicator
=
selectedDevice
.
Open
(
65536
,
// portion of the packet to capture
// 65536 guarantees that the whole packet will be captured on all the link layers
PacketDeviceOpenAttributes
.
Promiscuous
,
// promiscuous mode
1000
))
// read timeout
{
// Read and dispatch packets until EOF is reached
communicator
.
ReceivePackets
(
0
,
DispatcherHandler
);
}
}
private
static
void
DispatcherHandler
(
Packet
packet
)
{
// print packet timestamp and packet length
Console
.
WriteLine
(
packet
.
Timestamp
.
ToString
(
"yyyy-MM-dd hh:mm:ss.fff"
)
+
" length:"
+
packet
.
Length
);
// Print the packet
const
int
LineLength
=
64
;
for
(
int
i
=
0
;
i
!=
packet
.
Length
;
++
i
)
{
Console
.
Write
((
packet
[
i
]).
ToString
(
"X2"
));
if
((
i
+
1
)
%
LineLength
==
0
)
Console
.
WriteLine
();
}
Console
.
WriteLine
();
Console
.
WriteLine
();
}
}
}
\ No newline at end of file
PcapDotNet.DevelopersPack/src/ReadingPacketsFromADumpFile/Properties/AssemblyInfo.cs
0 → 100644
View file @
0322390e
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("ReadingPacketsFromADumpFile")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("ReadingPacketsFromADumpFile")]
[assembly: AssemblyCopyright("Copyright © 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. 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("b2c2266b-28a7-4ce8-be1c-42eeb0bbf5fa")]
// 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 Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
PcapDotNet.DevelopersPack/src/ReadingPacketsFromADumpFile/ReadingPacketsFromADumpFile.csproj
0 → 100644
View file @
0322390e
<?xml version="1.0" encoding="utf-8"?>
<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>
{E94AA408-15EE-426B-8478-1453EA5A515A}
</ProjectGuid>
<OutputType>
Exe
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
ReadingPacketsFromADumpFile
</RootNamespace>
<AssemblyName>
ReadingPacketsFromADumpFile
</AssemblyName>
<TargetFrameworkVersion>
v3.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<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=
"Packets, Version=0.1.0.33384, Culture=neutral, PublicKeyToken=58cf32d85728e684, processorArchitecture=MSIL"
>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
..\..\3rdParty\PcapDotNet\Packets.dll
</HintPath>
</Reference>
<Reference
Include=
"PcapDotNet.Core, Version=0.1.0.33550, Culture=neutral, PublicKeyToken=58cf32d85728e684, processorArchitecture=x86"
>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
..\..\3rdParty\PcapDotNet\PcapDotNet.Core.dll
</HintPath>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Xml.Linq"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Data.DataSetExtensions"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\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
PcapDotNet.DevelopersPack/src/ReadingPacketsFromADumpFile/ReadingPacketsFromADumpFile.csproj.vspscc
0 → 100644
View file @
0322390e
""
{
"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"
}
PcapDotNet.DevelopersPack/src/SavingPacketsToADumpFile/Program.cs
0 → 100644
View file @
0322390e
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Reflection
;
using
System.Text
;
using
Packets
;
using
PcapDotNet.Core
;
namespace
SavingPacketsToADumpFile
{
class
Program
{
static
void
Main
(
string
[]
args
)
{
// Check command line
if
(
args
.
Length
!=
1
)
{
Console
.
WriteLine
(
"usage: "
+
Environment
.
GetCommandLineArgs
()[
0
]
+
" <filename>"
);
return
;
}
// Retrieve the device list on the local machine
IList
<
LivePacketDevice
>
allDevices
=
LivePacketDevice
.
AllLocalMachine
;
if
(
allDevices
.
Count
==
0
)
{
Console
.
WriteLine
(
"No interfaces found! Make sure WinPcap is installed."
);
return
;
}
// Print the list
for
(
int
i
=
0
;
i
!=
allDevices
.
Count
;
++
i
)
{
LivePacketDevice
device
=
allDevices
[
i
];
Console
.
Write
((
i
+
1
)
+
". "
+
device
.
Name
);
if
(
device
.
Description
!=
null
)
Console
.
WriteLine
(
" ("
+
device
.
Description
+
")"
);
else
Console
.
WriteLine
(
" (No description available)"
);
}
int
deviceIndex
=
0
;
do
{
Console
.
WriteLine
(
"Enter the interface number (1-"
+
allDevices
.
Count
+
"):"
);
string
deviceIndexString
=
Console
.
ReadLine
();
if
(!
int
.
TryParse
(
deviceIndexString
,
out
deviceIndex
)
||
deviceIndex
<
1
||
deviceIndex
>
allDevices
.
Count
)
{
deviceIndex
=
0
;
}
}
while
(
deviceIndex
==
0
);
// Take the selected adapter
PacketDevice
selectedDevice
=
allDevices
[
deviceIndex
-
1
];
// Open the device
using
(
PacketCommunicator
communicator
=
selectedDevice
.
Open
(
65536
,
// portion of the packet to capture
// 65536 guarantees that the whole packet will be captured on all the link layers
PacketDeviceOpenAttributes
.
Promiscuous
,
// promiscuous mode
1000
))
// read timeout
{
// Open the dump file
using
(
PacketDumpFile
dumpFile
=
communicator
.
OpenDump
(
args
[
0
]))
{
Console
.
WriteLine
(
"Listening on "
+
selectedDevice
.
Description
+
"... Press Ctrl+C to stop..."
);
// start the capture
communicator
.
ReceivePackets
(
0
,
dumpFile
.
Dump
);
}
}
}
}
}
PcapDotNet.DevelopersPack/src/SavingPacketsToADumpFile/Properties/AssemblyInfo.cs
0 → 100644
View file @
0322390e
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("SavingPacketsToADumpFile")]
[assembly: AssemblyDescription("")]
[assembly: AssemblyConfiguration("")]
[assembly: AssemblyCompany("")]
[assembly: AssemblyProduct("SavingPacketsToADumpFile")]
[assembly: AssemblyCopyright("Copyright © 2009")]
[assembly: AssemblyTrademark("")]
[assembly: AssemblyCulture("")]
// Setting ComVisible to false makes the types in this assembly not visible
// to COM components. 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("966e120d-89f2-4ef6-b137-ca28623db459")]
// 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 Build and Revision Numbers
// by using the '*' as shown below:
// [assembly: AssemblyVersion("1.0.*")]
[assembly: AssemblyVersion("1.0.0.0")]
[assembly: AssemblyFileVersion("1.0.0.0")]
PcapDotNet.DevelopersPack/src/SavingPacketsToADumpFile/SavingPacketsToADumpFile.csproj
0 → 100644
View file @
0322390e
<?xml version="1.0" encoding="utf-8"?>
<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>
{17FAC756-D60D-46E5-A996-876B05BDFE69}
</ProjectGuid>
<OutputType>
Exe
</OutputType>
<AppDesignerFolder>
Properties
</AppDesignerFolder>
<RootNamespace>
SavingPacketsToADumpFile
</RootNamespace>
<AssemblyName>
SavingPacketsToADumpFile
</AssemblyName>
<TargetFrameworkVersion>
v3.5
</TargetFrameworkVersion>
<FileAlignment>
512
</FileAlignment>
<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=
"Packets, Version=0.1.0.33384, Culture=neutral, PublicKeyToken=58cf32d85728e684, processorArchitecture=MSIL"
>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
..\..\3rdParty\PcapDotNet\Packets.dll
</HintPath>
</Reference>
<Reference
Include=
"PcapDotNet.Core, Version=0.1.0.33550, Culture=neutral, PublicKeyToken=58cf32d85728e684, processorArchitecture=x86"
>
<SpecificVersion>
False
</SpecificVersion>
<HintPath>
..\..\3rdParty\PcapDotNet\PcapDotNet.Core.dll
</HintPath>
</Reference>
<Reference
Include=
"System"
/>
<Reference
Include=
"System.Core"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Xml.Linq"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Data.DataSetExtensions"
>
<RequiredTargetFramework>
3.5
</RequiredTargetFramework>
</Reference>
<Reference
Include=
"System.Data"
/>
<Reference
Include=
"System.Xml"
/>
</ItemGroup>
<ItemGroup>
<Compile
Include=
"Program.cs"
/>
<Compile
Include=
"Properties\AssemblyInfo.cs"
/>
</ItemGroup>
<Import
Project=
"$(MSBuildToolsPath)\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
PcapDotNet.DevelopersPack/src/SavingPacketsToADumpFile/SavingPacketsToADumpFile.csproj.vspscc
0 → 100644
View file @
0322390e
""
{
"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"
}
PcapDotNet/src/PcapDotNet.Core.Test/OfflinePacketDeviceTests.cs
View file @
0322390e
...
...
@@ -115,17 +115,17 @@ namespace PcapDotNet.Core.Test
const
int
NumPacketsToSend
=
100
;
// Normal
Test
Get
Packets
(
NumPacketsToSend
,
NumPacketsToSend
,
int
.
MaxValue
,
PacketCommunicatorReceiveResult
.
Ok
,
NumPacketsToSend
,
0.05
,
0.05
);
Test
Get
Packets
(
NumPacketsToSend
,
NumPacketsToSend
/
2
,
int
.
MaxValue
,
PacketCommunicatorReceiveResult
.
Ok
,
NumPacketsToSend
/
2
,
0.05
,
0.05
);
Test
Receive
Packets
(
NumPacketsToSend
,
NumPacketsToSend
,
int
.
MaxValue
,
PacketCommunicatorReceiveResult
.
Ok
,
NumPacketsToSend
,
0.05
,
0.05
);
Test
Receive
Packets
(
NumPacketsToSend
,
NumPacketsToSend
/
2
,
int
.
MaxValue
,
PacketCommunicatorReceiveResult
.
Ok
,
NumPacketsToSend
/
2
,
0.05
,
0.05
);
// Eof
Test
Get
Packets
(
NumPacketsToSend
,
0
,
int
.
MaxValue
,
PacketCommunicatorReceiveResult
.
Eof
,
NumPacketsToSend
,
0.05
,
0.05
);
Test
Get
Packets
(
NumPacketsToSend
,
-
1
,
int
.
MaxValue
,
PacketCommunicatorReceiveResult
.
Eof
,
NumPacketsToSend
,
0.05
,
0.05
);
Test
Get
Packets
(
NumPacketsToSend
,
NumPacketsToSend
+
1
,
int
.
MaxValue
,
PacketCommunicatorReceiveResult
.
Eof
,
NumPacketsToSend
,
0.05
,
0.05
);
Test
Receive
Packets
(
NumPacketsToSend
,
0
,
int
.
MaxValue
,
PacketCommunicatorReceiveResult
.
Eof
,
NumPacketsToSend
,
0.05
,
0.05
);
Test
Receive
Packets
(
NumPacketsToSend
,
-
1
,
int
.
MaxValue
,
PacketCommunicatorReceiveResult
.
Eof
,
NumPacketsToSend
,
0.05
,
0.05
);
Test
Receive
Packets
(
NumPacketsToSend
,
NumPacketsToSend
+
1
,
int
.
MaxValue
,
PacketCommunicatorReceiveResult
.
Eof
,
NumPacketsToSend
,
0.05
,
0.05
);
// Break loop
Test
Get
Packets
(
NumPacketsToSend
,
NumPacketsToSend
,
NumPacketsToSend
/
2
,
PacketCommunicatorReceiveResult
.
BreakLoop
,
NumPacketsToSend
/
2
,
0.05
,
0.05
);
Test
Get
Packets
(
NumPacketsToSend
,
NumPacketsToSend
,
0
,
PacketCommunicatorReceiveResult
.
BreakLoop
,
0
,
0.05
,
0.05
);
Test
Receive
Packets
(
NumPacketsToSend
,
NumPacketsToSend
,
NumPacketsToSend
/
2
,
PacketCommunicatorReceiveResult
.
BreakLoop
,
NumPacketsToSend
/
2
,
0.05
,
0.05
);
Test
Receive
Packets
(
NumPacketsToSend
,
NumPacketsToSend
,
0
,
PacketCommunicatorReceiveResult
.
BreakLoop
,
0
,
0.05
,
0.05
);
}
[
TestMethod
]
...
...
@@ -282,9 +282,9 @@ namespace PcapDotNet.Core.Test
}
}
private
static
void
Test
Get
Packets
(
int
numPacketsToSend
,
int
numPacketsToGet
,
int
numPacketsToBreakLoop
,
PacketCommunicatorReceiveResult
expectedResult
,
int
expectedNumPackets
,
double
expectedMinSeconds
,
double
expectedMaxSeconds
)
private
static
void
Test
Receive
Packets
(
int
numPacketsToSend
,
int
numPacketsToGet
,
int
numPacketsToBreakLoop
,
PacketCommunicatorReceiveResult
expectedResult
,
int
expectedNumPackets
,
double
expectedMinSeconds
,
double
expectedMaxSeconds
)
{
string
TestDescription
=
"NumPacketsToSend="
+
numPacketsToSend
+
". NumPacketsToGet="
+
numPacketsToGet
+
". NumPacketsToBreakLoop="
+
numPacketsToBreakLoop
;
...
...
@@ -319,6 +319,26 @@ namespace PcapDotNet.Core.Test
}
}
[
TestMethod
]
public
void
ReceivePacketsAndPrintTest
()
{
const
string
SourceMac
=
"11:22:33:44:55:66"
;
const
string
DestinationMac
=
"77:88:99:AA:BB:CC"
;
Packet
expectedPacket
=
MoreRandom
.
BuildRandomPacket
(
SourceMac
,
DestinationMac
,
24
);
using
(
PacketCommunicator
communicator
=
OpenOfflineDevice
(
1000
,
expectedPacket
))
{
communicator
.
SetFilter
(
"ether src "
+
SourceMac
+
" and ether dst "
+
DestinationMac
);
PacketCommunicatorReceiveResult
result
=
communicator
.
ReceivePackets
(
1000
,
delegate
(
Packet
p
)
{
for
(
int
i
=
0
;
i
!=
100
;
++
i
)
Console
.
Write
(
0
);
});
}
}
public
static
PacketCommunicator
OpenOfflineDevice
()
{
return
OpenOfflineDevice
(
10
,
MoreRandom
.
BuildRandomPacket
(
100
));
...
...
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.cpp
View file @
0322390e
...
...
@@ -173,6 +173,7 @@ PacketCommunicatorReceiveResult PacketCommunicator::ReceiveSomePackets([Out] int
maxPackets
,
functionPointer
,
NULL
);
GC
::
KeepAlive
(
packetHandlerDelegate
);
switch
(
countGot
)
{
...
...
@@ -201,6 +202,8 @@ PacketCommunicatorReceiveResult PacketCommunicator::ReceivePackets(int count, Ha
pcap_handler
functionPointer
=
(
pcap_handler
)
Marshal
::
GetFunctionPointerForDelegate
(
packetHandlerDelegate
).
ToPointer
();
int
result
=
pcap_loop
(
_pcapDescriptor
,
count
,
functionPointer
,
NULL
);
GC
::
KeepAlive
(
packetHandlerDelegate
);
switch
(
result
)
{
case
-
2
:
...
...
@@ -240,6 +243,8 @@ PacketCommunicatorReceiveResult PacketCommunicator::ReceiveStatistics(int count,
pcap_handler
functionPointer
=
(
pcap_handler
)
Marshal
::
GetFunctionPointerForDelegate
(
statisticsHandlerDelegate
).
ToPointer
();
int
result
=
pcap_loop
(
_pcapDescriptor
,
count
,
functionPointer
,
NULL
);
GC
::
KeepAlive
(
statisticsHandlerDelegate
);
if
(
result
==
-
1
)
throw
BuildInvalidOperation
(
"Failed reading from device"
);
if
(
result
==
-
2
)
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment