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
611dfbbe
Commit
611dfbbe
authored
Jul 17, 2009
by
Brickner_cp
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
--no commit message
--no commit message
parent
4a505ab8
Hide whitespace changes
Inline
Side-by-side
Showing
24 changed files
with
168 additions
and
39 deletions
+168
-39
MoreByteArray.cs
PcapDotNet/src/Packets/MoreByteArray.cs
+24
-0
Packet.cs
PcapDotNet/src/Packets/Packet.cs
+13
-0
PacketSendQueueTests.cs
PcapDotNet/src/PcapDotNet.Core.Test/PacketSendQueueTests.cs
+4
-4
CodeAnalysisDictionary.xml
PcapDotNet/src/PcapDotNet.Core/CodeAnalysisDictionary.xml
+21
-1
LivePacketCommunicator.cpp
PcapDotNet/src/PcapDotNet.Core/LivePacketCommunicator.cpp
+2
-2
LivePacketCommunicator.h
PcapDotNet/src/PcapDotNet.Core/LivePacketCommunicator.h
+1
-1
OfflinePacketCommunicator.cpp
PcapDotNet/src/PcapDotNet.Core/OfflinePacketCommunicator.cpp
+1
-1
OfflinePacketCommunicator.h
PcapDotNet/src/PcapDotNet.Core/OfflinePacketCommunicator.h
+1
-1
PacketCommunicator.cpp
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.cpp
+10
-10
PacketCommunicator.h
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.h
+2
-2
PacketDevice.h
PcapDotNet/src/PcapDotNet.Core/PacketDevice.h
+3
-0
PacketHeader.h
PcapDotNet/src/PcapDotNet.Core/PacketHeader.h
+3
-0
PacketSendQueue.cpp
PcapDotNet/src/PcapDotNet.Core/PacketSendQueue.cpp
+4
-4
PacketSendQueue.h
PcapDotNet/src/PcapDotNet.Core/PacketSendQueue.h
+3
-3
PacketTotalStatistics.cpp
PcapDotNet/src/PcapDotNet.Core/PacketTotalStatistics.cpp
+11
-2
PacketTotalStatistics.h
PcapDotNet/src/PcapDotNet.Core/PacketTotalStatistics.h
+3
-1
PcapDataLink.cpp
PcapDotNet/src/PcapDotNet.Core/PcapDataLink.cpp
+36
-4
PcapDataLink.h
PcapDotNet/src/PcapDotNet.Core/PcapDataLink.h
+10
-1
PcapError.h
PcapDotNet/src/PcapDotNet.Core/PcapError.h
+3
-0
PcapLibrary.h
PcapDotNet/src/PcapDotNet.Core/PcapLibrary.h
+4
-1
SamplingMethod.h
PcapDotNet/src/PcapDotNet.Core/SamplingMethod.h
+3
-0
SocketAddressFamily.h
PcapDotNet/src/PcapDotNet.Core/SocketAddressFamily.h
+2
-1
Timestamp.h
PcapDotNet/src/PcapDotNet.Core/Timestamp.h
+3
-0
WinPCapDotNet.Core.vcproj
PcapDotNet/src/PcapDotNet.Core/WinPCapDotNet.Core.vcproj
+1
-0
No files found.
PcapDotNet/src/Packets/MoreByteArray.cs
View file @
611dfbbe
...
@@ -24,6 +24,19 @@ namespace Packets
...
@@ -24,6 +24,19 @@ namespace Packets
return
(
ushort
)
ReadShort
(
buffer
,
offset
,
endianity
);
return
(
ushort
)
ReadShort
(
buffer
,
offset
,
endianity
);
}
}
public
static
uint
ReadUInt
(
this
byte
[]
buffer
,
int
offset
,
Endianity
endianity
)
{
return
(
uint
)
ReadInt
(
buffer
,
offset
,
endianity
);
}
public
static
int
ReadInt
(
this
byte
[]
buffer
,
int
offset
,
Endianity
endianity
)
{
int
value
=
ReadInt
(
buffer
,
offset
);
if
(
IsWrongEndianity
(
endianity
))
value
=
IPAddress
.
HostToNetworkOrder
(
value
);
return
value
;
}
public
static
void
Write
(
this
byte
[]
buffer
,
int
offset
,
short
value
,
Endianity
endianity
)
public
static
void
Write
(
this
byte
[]
buffer
,
int
offset
,
short
value
,
Endianity
endianity
)
{
{
if
(
IsWrongEndianity
(
endianity
))
if
(
IsWrongEndianity
(
endianity
))
...
@@ -52,6 +65,17 @@ namespace Packets
...
@@ -52,6 +65,17 @@ namespace Packets
}
}
}
}
private
static
int
ReadInt
(
byte
[]
buffer
,
int
offset
)
{
unsafe
{
fixed
(
byte
*
ptr
=
&
buffer
[
offset
])
{
return
*((
int
*)
ptr
);
}
}
}
private
static
void
Write
(
byte
[]
buffer
,
int
offset
,
short
value
)
private
static
void
Write
(
byte
[]
buffer
,
int
offset
,
short
value
)
{
{
unsafe
unsafe
...
...
PcapDotNet/src/Packets/Packet.cs
View file @
611dfbbe
...
@@ -57,6 +57,19 @@ namespace Packets
...
@@ -57,6 +57,19 @@ namespace Packets
return
Equals
(
obj
as
Packet
);
return
Equals
(
obj
as
Packet
);
}
}
public
override
int
GetHashCode
()
{
int
hashCode
=
0
;
int
offset
=
0
;
for
(;
offset
<
_data
.
Length
-
3
;
offset
+=
4
)
hashCode
^=
_data
.
ReadInt
(
offset
,
Endianity
.
Small
);
if
(
offset
<
_data
.
Length
-
1
)
hashCode
^=
_data
.
ReadShort
(
offset
,
Endianity
.
Small
);
if
(
offset
<
_data
.
Length
)
hashCode
^=
_data
[
offset
]
>>
2
;
return
hashCode
;
}
private
readonly
byte
[]
_data
;
private
readonly
byte
[]
_data
;
private
readonly
DateTime
_timestamp
;
private
readonly
DateTime
_timestamp
;
private
readonly
IDataLink
_dataLink
;
private
readonly
IDataLink
_dataLink
;
...
...
PcapDotNet/src/PcapDotNet.Core.Test/PacketSendQueueTests.cs
View file @
611dfbbe
...
@@ -76,7 +76,7 @@ namespace PcapDotNet.Core.Test
...
@@ -76,7 +76,7 @@ namespace PcapDotNet.Core.Test
const
string
DestinationMac
=
"77:88:99:AA:BB:CC"
;
const
string
DestinationMac
=
"77:88:99:AA:BB:CC"
;
List
<
Packet
>
packetsToSend
;
List
<
Packet
>
packetsToSend
;
using
(
PacketSend
Queue
queue
=
BuildQueue
(
out
packetsToSend
,
100
,
100
,
SourceMac
,
DestinationMac
,
0.5
))
using
(
PacketSend
Buffer
queue
=
BuildQueue
(
out
packetsToSend
,
100
,
100
,
SourceMac
,
DestinationMac
,
0.5
))
{
{
using
(
PacketCommunicator
communicator
=
OfflinePacketDeviceTests
.
OpenOfflineDevice
())
using
(
PacketCommunicator
communicator
=
OfflinePacketDeviceTests
.
OpenOfflineDevice
())
{
{
...
@@ -92,7 +92,7 @@ namespace PcapDotNet.Core.Test
...
@@ -92,7 +92,7 @@ namespace PcapDotNet.Core.Test
const
string
DestinationMac
=
"77:88:99:AA:BB:CC"
;
const
string
DestinationMac
=
"77:88:99:AA:BB:CC"
;
List
<
Packet
>
packetsToSend
;
List
<
Packet
>
packetsToSend
;
using
(
PacketSend
Queue
queue
=
BuildQueue
(
out
packetsToSend
,
numPacketsToSend
,
packetSize
,
SourceMac
,
DestinationMac
,
secondsBetweenTimestamps
))
using
(
PacketSend
Buffer
queue
=
BuildQueue
(
out
packetsToSend
,
numPacketsToSend
,
packetSize
,
SourceMac
,
DestinationMac
,
secondsBetweenTimestamps
))
{
{
using
(
PacketCommunicator
communicator
=
LivePacketDeviceTests
.
OpenLiveDevice
())
using
(
PacketCommunicator
communicator
=
LivePacketDeviceTests
.
OpenLiveDevice
())
{
{
...
@@ -137,11 +137,11 @@ namespace PcapDotNet.Core.Test
...
@@ -137,11 +137,11 @@ namespace PcapDotNet.Core.Test
}
}
}
}
private
static
PacketSend
Queue
BuildQueue
(
out
List
<
Packet
>
packetsToSend
,
int
numPackets
,
int
packetSize
,
string
sourceMac
,
string
destinationMac
,
double
secondsBetweenTimestamps
)
private
static
PacketSend
Buffer
BuildQueue
(
out
List
<
Packet
>
packetsToSend
,
int
numPackets
,
int
packetSize
,
string
sourceMac
,
string
destinationMac
,
double
secondsBetweenTimestamps
)
{
{
int
rawPacketSize
=
packetSize
+
16
;
// I don't know why 16
int
rawPacketSize
=
packetSize
+
16
;
// I don't know why 16
PacketSend
Queue
queue
=
new
PacketSendQueue
((
uint
)(
numPackets
*
rawPacketSize
));
PacketSend
Buffer
queue
=
new
PacketSendBuffer
((
uint
)(
numPackets
*
rawPacketSize
));
try
try
{
{
DateTime
timestamp
=
DateTime
.
Now
.
AddSeconds
(-
100
);
DateTime
timestamp
=
DateTime
.
Now
.
AddSeconds
(-
100
);
...
...
PcapDotNet/src/PcapDotNet.Core/CodeAnalysisDictionary.xml
View file @
611dfbbe
<?xml version="1.0" encoding="utf-8" ?>
<?xml version="1.0" encoding="utf-8" ?>
<Dictionary>
<Dictionary>
<Words>
<Words>
<Unrecognized>
<!--Word>cb</Word-->
</Unrecognized>
<Recognized>
<Recognized>
<Word>
netmask
</Word>
<Word>
pcap
</Word>
<Word>
pcap
</Word>
<Word>
eof
</Word>
<Word>
netmask
</Word>
</Recognized>
</Recognized>
<Deprecated>
<!--Term PreferredAlternate="EnterpriseServices">complus</Term-->
</Deprecated>
<Compound>
<!--Term CompoundAlternate="DataStore">datastore</Term-->
</Compound>
<DiscreteExceptions>
<!--Term>netmask</Term-->
</DiscreteExceptions>
</Words>
</Words>
<Acronyms>
<CasingExceptions>
<!-->Acronym>Eof</Acronym-->
<Acronym>
Ip
</Acronym>
<Acronym>
Ms
</Acronym>
</CasingExceptions>
</Acronyms>
</Dictionary>
</Dictionary>
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core/LivePacketCommunicator.cpp
View file @
611dfbbe
...
@@ -25,7 +25,7 @@ PacketTotalStatistics^ LivePacketCommunicator::TotalStatistics::get()
...
@@ -25,7 +25,7 @@ PacketTotalStatistics^ LivePacketCommunicator::TotalStatistics::get()
return
gcnew
PacketTotalStatistics
(
packetsReceived
,
packetsDroppedByDriver
,
packetsDroppedByInterface
,
packetsCaptured
);
return
gcnew
PacketTotalStatistics
(
packetsReceived
,
packetsDroppedByDriver
,
packetsDroppedByInterface
,
packetsCaptured
);
}
}
void
LivePacketCommunicator
::
Transmit
(
PacketSend
Queue
^
sendQueue
,
bool
isSync
)
void
LivePacketCommunicator
::
Transmit
(
PacketSend
Buffer
^
sendBuffer
,
bool
isSync
)
{
{
send
Queue
->
Transmit
(
PcapDescriptor
,
isSync
);
send
Buffer
->
Transmit
(
PcapDescriptor
,
isSync
);
}
}
PcapDotNet/src/PcapDotNet.Core/LivePacketCommunicator.h
View file @
611dfbbe
...
@@ -15,7 +15,7 @@ namespace PcapDotNet { namespace Core
...
@@ -15,7 +15,7 @@ namespace PcapDotNet { namespace Core
PacketTotalStatistics
^
get
()
override
;
PacketTotalStatistics
^
get
()
override
;
}
}
virtual
void
Transmit
(
PacketSend
Queue
^
sendQueue
,
bool
isSync
)
override
;
virtual
void
Transmit
(
PacketSend
Buffer
^
sendBuffer
,
bool
isSync
)
override
;
internal
:
internal
:
LivePacketCommunicator
(
const
char
*
source
,
int
snapshotLength
,
PacketDeviceOpenFlags
flags
,
int
readTimeout
,
pcap_rmtauth
*
auth
,
LivePacketCommunicator
(
const
char
*
source
,
int
snapshotLength
,
PacketDeviceOpenFlags
flags
,
int
readTimeout
,
pcap_rmtauth
*
auth
,
...
...
PcapDotNet/src/PcapDotNet.Core/OfflinePacketCommunicator.cpp
View file @
611dfbbe
...
@@ -13,7 +13,7 @@ OfflinePacketCommunicator::OfflinePacketCommunicator(const char* source, int sna
...
@@ -13,7 +13,7 @@ OfflinePacketCommunicator::OfflinePacketCommunicator(const char* source, int sna
{
{
}
}
void
OfflinePacketCommunicator
::
Transmit
(
PacketSend
Queue
^
sendQueue
,
bool
isSync
)
void
OfflinePacketCommunicator
::
Transmit
(
PacketSend
Buffer
^
sendBuffer
,
bool
isSync
)
{
{
throw
gcnew
InvalidOperationException
(
"Can't transmit queue to an offline device"
);
throw
gcnew
InvalidOperationException
(
"Can't transmit queue to an offline device"
);
}
}
PcapDotNet/src/PcapDotNet.Core/OfflinePacketCommunicator.h
View file @
611dfbbe
...
@@ -13,7 +13,7 @@ namespace PcapDotNet { namespace Core
...
@@ -13,7 +13,7 @@ namespace PcapDotNet { namespace Core
PacketTotalStatistics
^
get
()
override
;
PacketTotalStatistics
^
get
()
override
;
}
}
virtual
void
Transmit
(
PacketSend
Queue
^
sendQueue
,
bool
isSync
)
override
;
virtual
void
Transmit
(
PacketSend
Buffer
^
sendBuffer
,
bool
isSync
)
override
;
internal
:
internal
:
OfflinePacketCommunicator
(
const
char
*
source
,
int
snapshotLength
,
PacketDeviceOpenFlags
flags
,
int
readTimeout
,
pcap_rmtauth
*
auth
);
OfflinePacketCommunicator
(
const
char
*
source
,
int
snapshotLength
,
PacketDeviceOpenFlags
flags
,
int
readTimeout
,
pcap_rmtauth
*
auth
);
...
...
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.cpp
View file @
611dfbbe
...
@@ -122,13 +122,13 @@ void PacketCommunicator::NonBlocking::set(bool value)
...
@@ -122,13 +122,13 @@ void PacketCommunicator::NonBlocking::set(bool value)
void
PacketCommunicator
::
SetKernelBufferSize
(
int
size
)
void
PacketCommunicator
::
SetKernelBufferSize
(
int
size
)
{
{
if
(
pcap_setbuff
(
_pcapDescriptor
,
size
)
!=
0
)
if
(
pcap_setbuff
(
_pcapDescriptor
,
size
)
!=
0
)
throw
BuildInvalidOperation
(
"Error setting kernel buffer size to "
+
size
.
ToString
());
throw
BuildInvalidOperation
(
"Error setting kernel buffer size to "
+
size
.
ToString
(
CultureInfo
::
InvariantCulture
));
}
}
void
PacketCommunicator
::
SetKernelMinimumBytesToCopy
(
int
size
)
void
PacketCommunicator
::
SetKernelMinimumBytesToCopy
(
int
size
)
{
{
if
(
pcap_setmintocopy
(
_pcapDescriptor
,
size
)
!=
0
)
if
(
pcap_setmintocopy
(
_pcapDescriptor
,
size
)
!=
0
)
throw
BuildInvalidOperation
(
"Error setting kernel minimum bytes to copy to "
+
size
.
ToString
());
throw
BuildInvalidOperation
(
"Error setting kernel minimum bytes to copy to "
+
size
.
ToString
(
CultureInfo
::
InvariantCulture
));
}
}
void
PacketCommunicator
::
SetSamplingMethod
(
SamplingMethod
^
method
)
void
PacketCommunicator
::
SetSamplingMethod
(
SamplingMethod
^
method
)
...
@@ -156,7 +156,7 @@ PacketCommunicatorReceiveResult PacketCommunicator::ReceivePacket([Out] Packet^%
...
@@ -156,7 +156,7 @@ PacketCommunicatorReceiveResult PacketCommunicator::ReceivePacket([Out] Packet^%
return
result
;
return
result
;
}
}
PacketCommunicatorReceiveResult
PacketCommunicator
::
ReceiveSomePackets
([
Out
]
int
%
numPackets
Got
,
int
maxPackets
,
HandlePacket
^
callBack
)
PacketCommunicatorReceiveResult
PacketCommunicator
::
ReceiveSomePackets
([
Out
]
int
%
count
Got
,
int
maxPackets
,
HandlePacket
^
callBack
)
{
{
AssertMode
(
PacketCommunicatorMode
::
Capture
);
AssertMode
(
PacketCommunicatorMode
::
Capture
);
...
@@ -164,22 +164,22 @@ PacketCommunicatorReceiveResult PacketCommunicator::ReceiveSomePackets([Out] int
...
@@ -164,22 +164,22 @@ PacketCommunicatorReceiveResult PacketCommunicator::ReceiveSomePackets([Out] int
HandlerDelegate
^
packetHandlerDelegate
=
gcnew
HandlerDelegate
(
packetHandler
,
&
PacketHandler
::
Handle
);
HandlerDelegate
^
packetHandlerDelegate
=
gcnew
HandlerDelegate
(
packetHandler
,
&
PacketHandler
::
Handle
);
pcap_handler
functionPointer
=
(
pcap_handler
)
Marshal
::
GetFunctionPointerForDelegate
(
packetHandlerDelegate
).
ToPointer
();
pcap_handler
functionPointer
=
(
pcap_handler
)
Marshal
::
GetFunctionPointerForDelegate
(
packetHandlerDelegate
).
ToPointer
();
numPackets
Got
=
pcap_dispatch
(
_pcapDescriptor
,
count
Got
=
pcap_dispatch
(
_pcapDescriptor
,
maxPackets
,
maxPackets
,
functionPointer
,
functionPointer
,
NULL
);
NULL
);
switch
(
numPackets
Got
)
switch
(
count
Got
)
{
{
case
-
2
:
case
-
2
:
numPackets
Got
=
0
;
count
Got
=
0
;
return
PacketCommunicatorReceiveResult
::
BreakLoop
;
return
PacketCommunicatorReceiveResult
::
BreakLoop
;
case
-
1
:
case
-
1
:
throw
BuildInvalidOperation
(
"Failed reading from device"
);
throw
BuildInvalidOperation
(
"Failed reading from device"
);
case
0
:
case
0
:
if
(
packetHandler
->
PacketCounter
!=
0
)
if
(
packetHandler
->
PacketCounter
!=
0
)
{
{
numPackets
Got
=
packetHandler
->
PacketCounter
;
count
Got
=
packetHandler
->
PacketCounter
;
return
PacketCommunicatorReceiveResult
::
Eof
;
return
PacketCommunicatorReceiveResult
::
Eof
;
}
}
}
}
...
...
PcapDotNet/src/PcapDotNet.Core/PacketCommunicator.h
View file @
611dfbbe
...
@@ -76,7 +76,7 @@ namespace PcapDotNet { namespace Core
...
@@ -76,7 +76,7 @@ namespace PcapDotNet { namespace Core
delegate
void
HandlePacket
(
Packets
::
Packet
^
packet
);
delegate
void
HandlePacket
(
Packets
::
Packet
^
packet
);
PacketCommunicatorReceiveResult
ReceivePacket
([
System
::
Runtime
::
InteropServices
::
Out
]
Packets
::
Packet
^%
packet
);
PacketCommunicatorReceiveResult
ReceivePacket
([
System
::
Runtime
::
InteropServices
::
Out
]
Packets
::
Packet
^%
packet
);
PacketCommunicatorReceiveResult
ReceiveSomePackets
([
System
::
Runtime
::
InteropServices
::
Out
]
int
%
numPackets
Got
,
int
maxPackets
,
HandlePacket
^
callback
);
PacketCommunicatorReceiveResult
ReceiveSomePackets
([
System
::
Runtime
::
InteropServices
::
Out
]
int
%
count
Got
,
int
maxPackets
,
HandlePacket
^
callback
);
PacketCommunicatorReceiveResult
ReceivePackets
(
int
count
,
HandlePacket
^
callback
);
PacketCommunicatorReceiveResult
ReceivePackets
(
int
count
,
HandlePacket
^
callback
);
delegate
void
HandleStatistics
(
PacketSampleStatistics
^
statistics
);
delegate
void
HandleStatistics
(
PacketSampleStatistics
^
statistics
);
...
@@ -86,7 +86,7 @@ namespace PcapDotNet { namespace Core
...
@@ -86,7 +86,7 @@ namespace PcapDotNet { namespace Core
void
Break
();
void
Break
();
void
SendPacket
(
Packets
::
Packet
^
packet
);
void
SendPacket
(
Packets
::
Packet
^
packet
);
virtual
void
Transmit
(
PacketSend
Queue
^
sendQueue
,
bool
isSync
)
=
0
;
virtual
void
Transmit
(
PacketSend
Buffer
^
sendBuffer
,
bool
isSync
)
=
0
;
BerkeleyPacketFilter
^
CreateFilter
(
System
::
String
^
filterValue
);
BerkeleyPacketFilter
^
CreateFilter
(
System
::
String
^
filterValue
);
void
SetFilter
(
BerkeleyPacketFilter
^
filter
);
void
SetFilter
(
BerkeleyPacketFilter
^
filter
);
...
...
PcapDotNet/src/PcapDotNet.Core/PacketDevice.h
View file @
611dfbbe
...
@@ -32,5 +32,8 @@ namespace PcapDotNet { namespace Core
...
@@ -32,5 +32,8 @@ namespace PcapDotNet { namespace Core
virtual
PacketCommunicator
^
Open
(
int
snapshotLength
,
PacketDeviceOpenFlags
flags
,
int
readTimeout
)
=
0
;
virtual
PacketCommunicator
^
Open
(
int
snapshotLength
,
PacketDeviceOpenFlags
flags
,
int
readTimeout
)
=
0
;
virtual
PacketCommunicator
^
Open
();
virtual
PacketCommunicator
^
Open
();
protected
:
PacketDevice
(){}
};
};
}}
}}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core/PacketHeader.h
View file @
611dfbbe
...
@@ -8,5 +8,8 @@ namespace PcapDotNet { namespace Core
...
@@ -8,5 +8,8 @@ namespace PcapDotNet { namespace Core
{
{
public
:
public
:
static
void
GetPcapHeader
(
pcap_pkthdr
&
header
,
Packets
::
Packet
^
packet
);
static
void
GetPcapHeader
(
pcap_pkthdr
&
header
,
Packets
::
Packet
^
packet
);
private
:
PacketHeader
(){}
};
};
}}
}}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core/PacketSendQueue.cpp
View file @
611dfbbe
...
@@ -7,12 +7,12 @@ using namespace System;
...
@@ -7,12 +7,12 @@ using namespace System;
using
namespace
PcapDotNet
::
Core
;
using
namespace
PcapDotNet
::
Core
;
using
namespace
Packets
;
using
namespace
Packets
;
PacketSend
Queue
::
PacketSendQueue
(
unsigned
int
capacity
)
PacketSend
Buffer
::
PacketSendBuffer
(
unsigned
int
capacity
)
{
{
_pcapSendQueue
=
pcap_sendqueue_alloc
(
capacity
);
_pcapSendQueue
=
pcap_sendqueue_alloc
(
capacity
);
}
}
void
PacketSend
Queue
::
Enqueue
(
Packet
^
packet
)
void
PacketSend
Buffer
::
Enqueue
(
Packet
^
packet
)
{
{
pcap_pkthdr
pcapHeader
;
pcap_pkthdr
pcapHeader
;
PacketHeader
::
GetPcapHeader
(
pcapHeader
,
packet
);
PacketHeader
::
GetPcapHeader
(
pcapHeader
,
packet
);
...
@@ -21,12 +21,12 @@ void PacketSendQueue::Enqueue(Packet^ packet)
...
@@ -21,12 +21,12 @@ void PacketSendQueue::Enqueue(Packet^ packet)
throw
gcnew
InvalidOperationException
(
"Failed enqueueing to SendQueue"
);
throw
gcnew
InvalidOperationException
(
"Failed enqueueing to SendQueue"
);
}
}
PacketSend
Queue
::~
PacketSendQueue
()
PacketSend
Buffer
::~
PacketSendBuffer
()
{
{
pcap_sendqueue_destroy
(
_pcapSendQueue
);
pcap_sendqueue_destroy
(
_pcapSendQueue
);
}
}
void
PacketSend
Queue
::
Transmit
(
pcap_t
*
pcapDescriptor
,
bool
isSync
)
void
PacketSend
Buffer
::
Transmit
(
pcap_t
*
pcapDescriptor
,
bool
isSync
)
{
{
unsigned
int
numBytesTransmitted
=
pcap_sendqueue_transmit
(
pcapDescriptor
,
_pcapSendQueue
,
isSync
);
unsigned
int
numBytesTransmitted
=
pcap_sendqueue_transmit
(
pcapDescriptor
,
_pcapSendQueue
,
isSync
);
if
(
numBytesTransmitted
<
_pcapSendQueue
->
len
)
if
(
numBytesTransmitted
<
_pcapSendQueue
->
len
)
...
...
PcapDotNet/src/PcapDotNet.Core/PacketSendQueue.h
View file @
611dfbbe
...
@@ -4,14 +4,14 @@
...
@@ -4,14 +4,14 @@
namespace
PcapDotNet
{
namespace
Core
namespace
PcapDotNet
{
namespace
Core
{
{
public
ref
class
PacketSend
Queue
:
System
::
IDisposable
public
ref
class
PacketSend
Buffer
:
System
::
IDisposable
{
{
public
:
public
:
PacketSend
Queue
(
unsigned
int
capacity
);
PacketSend
Buffer
(
unsigned
int
capacity
);
void
Enqueue
(
Packets
::
Packet
^
packet
);
void
Enqueue
(
Packets
::
Packet
^
packet
);
~
PacketSend
Queue
();
~
PacketSend
Buffer
();
internal
:
internal
:
void
Transmit
(
pcap_t
*
pcapDescriptor
,
bool
isSync
);
void
Transmit
(
pcap_t
*
pcapDescriptor
,
bool
isSync
);
...
...
PcapDotNet/src/PcapDotNet.Core/PacketTotalStatistics.cpp
View file @
611dfbbe
...
@@ -43,9 +43,18 @@ bool PacketTotalStatistics::Equals(PacketTotalStatistics^ other)
...
@@ -43,9 +43,18 @@ bool PacketTotalStatistics::Equals(PacketTotalStatistics^ other)
PacketsCaptured
==
other
->
PacketsCaptured
);
PacketsCaptured
==
other
->
PacketsCaptured
);
}
}
bool
PacketTotalStatistics
::
Equals
(
Object
^
o
ther
)
bool
PacketTotalStatistics
::
Equals
(
Object
^
o
bj
)
{
{
return
Equals
(
dynamic_cast
<
PacketTotalStatistics
^>
(
other
));
return
Equals
(
dynamic_cast
<
PacketTotalStatistics
^>
(
obj
));
}
int
PacketTotalStatistics
::
GetHashCode
()
{
return
_packetsReceived
^
_packetsDroppedByDriver
^
_packetsDroppedByInterface
^
_packetsCaptured
;
}
}
String
^
PacketTotalStatistics
::
ToString
()
String
^
PacketTotalStatistics
::
ToString
()
...
...
PcapDotNet/src/PcapDotNet.Core/PacketTotalStatistics.h
View file @
611dfbbe
...
@@ -28,7 +28,9 @@ namespace PcapDotNet { namespace Core
...
@@ -28,7 +28,9 @@ namespace PcapDotNet { namespace Core
}
}
virtual
bool
Equals
(
PacketTotalStatistics
^
other
);
virtual
bool
Equals
(
PacketTotalStatistics
^
other
);
virtual
bool
Equals
(
System
::
Object
^
other
)
override
;
virtual
bool
Equals
(
System
::
Object
^
obj
)
override
;
virtual
int
GetHashCode
()
override
;
virtual
System
::
String
^
ToString
()
override
;
virtual
System
::
String
^
ToString
()
override
;
...
...
PcapDotNet/src/PcapDotNet.Core/PcapDataLink.cpp
View file @
611dfbbe
...
@@ -6,6 +6,7 @@
...
@@ -6,6 +6,7 @@
#include "Pcap.h"
#include "Pcap.h"
using
namespace
System
;
using
namespace
System
;
using
namespace
System
::
Globalization
;
using
namespace
Packets
;
using
namespace
Packets
;
using
namespace
PcapDotNet
::
Core
;
using
namespace
PcapDotNet
::
Core
;
...
@@ -36,7 +37,7 @@ DataLinkKind PcapDataLink::Kind::get()
...
@@ -36,7 +37,7 @@ DataLinkKind PcapDataLink::Kind::get()
case
1
:
case
1
:
return
DataLinkKind
::
Ethernet
;
return
DataLinkKind
::
Ethernet
;
default
:
default
:
throw
gcnew
NotSupportedException
(
"PcapDataLink "
+
Value
.
ToString
()
+
" - "
+
ToString
()
+
" is unsupported"
);
throw
gcnew
NotSupportedException
(
"PcapDataLink "
+
Value
.
ToString
(
CultureInfo
::
InvariantCulture
)
+
" - "
+
ToString
()
+
" is unsupported"
);
}
}
}
}
...
@@ -50,7 +51,7 @@ String^ PcapDataLink::Name::get()
...
@@ -50,7 +51,7 @@ String^ PcapDataLink::Name::get()
{
{
const
char
*
name
=
pcap_datalink_val_to_name
(
Value
);
const
char
*
name
=
pcap_datalink_val_to_name
(
Value
);
if
(
name
==
NULL
)
if
(
name
==
NULL
)
throw
gcnew
ArgumentException
(
"datalink "
+
Value
.
ToString
()
+
" has no name"
,
"Valu
e"
);
throw
gcnew
InvalidOperationException
(
"datalink "
+
Value
.
ToString
(
CultureInfo
::
InvariantCulture
)
+
" has no nam
e"
);
return
gcnew
String
(
name
);
return
gcnew
String
(
name
);
}
}
...
@@ -59,18 +60,49 @@ String^ PcapDataLink::Description::get()
...
@@ -59,18 +60,49 @@ String^ PcapDataLink::Description::get()
{
{
const
char
*
description
=
pcap_datalink_val_to_description
(
Value
);
const
char
*
description
=
pcap_datalink_val_to_description
(
Value
);
if
(
description
==
NULL
)
if
(
description
==
NULL
)
throw
gcnew
ArgumentException
(
"datalink "
+
Value
.
ToString
()
+
" has no description"
,
"Value
"
);
throw
gcnew
InvalidOperationException
(
"datalink "
+
Value
.
ToString
(
CultureInfo
::
InvariantCulture
)
+
" has no description
"
);
return
gcnew
String
(
description
);
return
gcnew
String
(
description
);
}
}
String
^
PcapDataLink
::
ToString
()
String
^
PcapDataLink
::
ToString
()
{
{
return
Name
+
" ("
+
Description
+
")"
;
return
Name
+
" ("
+
Description
+
")"
;
}
}
bool
PcapDataLink
::
Equals
(
PcapDataLink
other
)
{
return
_value
==
other
.
_value
;
}
bool
PcapDataLink
::
Equals
(
System
::
Object
^
obj
)
{
PcapDataLink
^
other
=
dynamic_cast
<
PcapDataLink
^>
(
obj
);
if
(
other
==
nullptr
)
return
false
;
return
Equals
((
PcapDataLink
)
other
);
}
int
PcapDataLink
::
GetHashCode
()
{
return
Value
.
GetHashCode
();
}
// static
bool
PcapDataLink
::
operator
==
(
PcapDataLink
dataLink1
,
PcapDataLink
dataLink2
)
{
return
dataLink1
.
Equals
(
dataLink2
);
}
// static
// static
bool
PcapDataLink
::
operator
!=
(
PcapDataLink
dataLink1
,
PcapDataLink
dataLink2
)
{
return
!
dataLink1
.
Equals
(
dataLink2
);
}
// private
int
PcapDataLink
::
KindToValue
(
DataLinkKind
kind
)
int
PcapDataLink
::
KindToValue
(
DataLinkKind
kind
)
{
{
switch
(
kind
)
switch
(
kind
)
...
...
PcapDotNet/src/PcapDotNet.Core/PcapDataLink.h
View file @
611dfbbe
...
@@ -2,7 +2,7 @@
...
@@ -2,7 +2,7 @@
namespace
PcapDotNet
{
namespace
Core
namespace
PcapDotNet
{
namespace
Core
{
{
public
value
class
PcapDataLink
:
Packets
::
IDataLink
public
value
class
PcapDataLink
:
Packets
::
IDataLink
,
System
::
IEquatable
<
PcapDataLink
>
{
{
public
:
public
:
PcapDataLink
(
Packets
::
DataLinkKind
kind
);
PcapDataLink
(
Packets
::
DataLinkKind
kind
);
...
@@ -31,6 +31,15 @@ namespace PcapDotNet { namespace Core
...
@@ -31,6 +31,15 @@ namespace PcapDotNet { namespace Core
virtual
System
::
String
^
ToString
()
override
;
virtual
System
::
String
^
ToString
()
override
;
virtual
bool
Equals
(
PcapDataLink
other
);
virtual
bool
Equals
(
System
::
Object
^
obj
)
override
;
virtual
int
GetHashCode
()
override
;
static
bool
operator
==
(
PcapDataLink
dataLink1
,
PcapDataLink
dataLink2
);
static
bool
operator
!=
(
PcapDataLink
dataLink1
,
PcapDataLink
dataLink2
);
private
:
private
:
static
int
KindToValue
(
Packets
::
DataLinkKind
kind
);
static
int
KindToValue
(
Packets
::
DataLinkKind
kind
);
...
...
PcapDotNet/src/PcapDotNet.Core/PcapError.h
View file @
611dfbbe
...
@@ -9,5 +9,8 @@ namespace PcapDotNet { namespace Core
...
@@ -9,5 +9,8 @@ namespace PcapDotNet { namespace Core
public
:
public
:
static
System
::
String
^
GetErrorMessage
(
pcap_t
*
pcapDescriptor
);
static
System
::
String
^
GetErrorMessage
(
pcap_t
*
pcapDescriptor
);
static
System
::
InvalidOperationException
^
BuildInvalidOperation
(
System
::
String
^
errorMessage
,
pcap_t
*
pcapDescriptor
);
static
System
::
InvalidOperationException
^
BuildInvalidOperation
(
System
::
String
^
errorMessage
,
pcap_t
*
pcapDescriptor
);
private
:
PcapError
(){}
};
};
}}
}}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core/PcapLibrary.h
View file @
611dfbbe
...
@@ -2,12 +2,15 @@
...
@@ -2,12 +2,15 @@
namespace
PcapDotNet
{
namespace
Core
namespace
PcapDotNet
{
namespace
Core
{
{
public
ref
class
PcapLibrary
public
ref
class
PcapLibrary
sealed
{
{
public
:
public
:
static
property
System
::
String
^
Version
static
property
System
::
String
^
Version
{
{
System
::
String
^
get
();
System
::
String
^
get
();
}
}
private
:
PcapLibrary
(){}
};
};
}}
}}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core/SamplingMethod.h
View file @
611dfbbe
...
@@ -14,5 +14,8 @@ namespace PcapDotNet { namespace Core
...
@@ -14,5 +14,8 @@ namespace PcapDotNet { namespace Core
{
{
int
get
()
=
0
;
int
get
()
=
0
;
}
}
protected
:
SamplingMethod
(){}
};
};
}}
}}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core/SocketAddressFamily.h
View file @
611dfbbe
...
@@ -16,7 +16,8 @@ namespace PcapDotNet { namespace Core
...
@@ -16,7 +16,8 @@ namespace PcapDotNet { namespace Core
OSI
=
ISO
,
// OSI is ISO
OSI
=
ISO
,
// OSI is ISO
ECMA
=
8
,
// european computer manufacturers
ECMA
=
8
,
// european computer manufacturers
DATAKIT
=
9
,
// datakit protocols
DATAKIT
=
9
,
// datakit protocols
CCITT
=
10
,
// CCITT protocols, X.25 etc
CCITT
=
10
,
// CCITT protocols, X.25 etc
SNA
=
11
,
// IBM SNA
SNA
=
11
,
// IBM SNA
DECnet
=
12
,
// DECnet
DECnet
=
12
,
// DECnet
DLI
=
13
,
// Direct data link interface
DLI
=
13
,
// Direct data link interface
...
...
PcapDotNet/src/PcapDotNet.Core/Timestamp.h
View file @
611dfbbe
...
@@ -9,5 +9,8 @@ namespace PcapDotNet { namespace Core
...
@@ -9,5 +9,8 @@ namespace PcapDotNet { namespace Core
public
:
public
:
static
void
PcapTimestampToDateTime
(
const
timeval
&
pcapTimestamp
,
[
System
::
Runtime
::
InteropServices
::
Out
]
System
::
DateTime
%
dateTime
);
static
void
PcapTimestampToDateTime
(
const
timeval
&
pcapTimestamp
,
[
System
::
Runtime
::
InteropServices
::
Out
]
System
::
DateTime
%
dateTime
);
static
void
DateTimeToPcapTimestamp
(
System
::
DateTime
dateTime
,
timeval
&
pcapTimestamp
);
static
void
DateTimeToPcapTimestamp
(
System
::
DateTime
dateTime
,
timeval
&
pcapTimestamp
);
private
:
Timestamp
(){}
};
};
}}
}}
\ No newline at end of file
PcapDotNet/src/PcapDotNet.Core/WinPCapDotNet.Core.vcproj
View file @
611dfbbe
...
@@ -92,6 +92,7 @@
...
@@ -92,6 +92,7 @@
/>
/>
<Tool
<Tool
Name=
"VCFxCopTool"
Name=
"VCFxCopTool"
Rules=
"-Microsoft.Design#CA1021;-Microsoft.Design#CA1028;-Microsoft.Design#CA1027"
EnableFxCop=
"true"
EnableFxCop=
"true"
Dictionaries=
"CodeAnalysisDictionary.xml"
Dictionaries=
"CodeAnalysisDictionary.xml"
/>
/>
...
...
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