Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support statically linked NativeAOT distribution #448

Open
wants to merge 16 commits into
base: master
Choose a base branch
from
Prev Previous commit
Next Next commit
Use pcap_open
hez2010 committed Mar 6, 2023
commit 97ab64c0771ecefc3803449fd6c6638a4928549e
9 changes: 6 additions & 3 deletions SharpPcap/LibPcap/LibPcapLiveDevice.cs
Original file line number Diff line number Diff line change
@@ -176,6 +176,8 @@ public override void Open(DeviceConfiguration configuration)
}
else
{
// We got authentication, so this is an rpcap device
var auth = RemoteAuthentication.CreateAuth(credentials);
// Immediate and MaxResponsiveness are the same thing
if (immediateMode == true)
{
@@ -185,11 +187,12 @@ public override void Open(DeviceConfiguration configuration)
immediateMode = null;
try
{
Handle = LibPcapSafeNativeMethods.pcap_open_live(
Handle = LibPcapSafeNativeMethods.pcap_open(
Name, // name of the device
configuration.Snaplen, // portion of the packet to capture.
(int)mode, // flags
configuration.ReadTimeout, // read timeout
(short)mode, // flags
(short)configuration.ReadTimeout, // read timeout
ref auth, // authentication
errbuf); // error buffer
}
catch (TypeLoadException)
9 changes: 5 additions & 4 deletions SharpPcap/LibPcap/LibPcapSafeNativeMethods.Interop.cs
Original file line number Diff line number Diff line change
@@ -77,11 +77,12 @@ internal extern static int pcap_findalldevs_ex(
/// Open a generic source in order to capture / send (WinPcap only) traffic.
/// </summary>
[DllImport(PCAP_DLL, CallingConvention = CallingConvention.Cdecl)]
internal extern static PcapHandle /* pcap_t* */ pcap_open_live(
internal extern static PcapHandle /* pcap_t* */ pcap_open(
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PcapStringMarshaler))] string dev,
int snaplen,
int promisc,
int to_ms,
int packetLen,
int flags,
int read_timeout,
ref pcap_rmtauth rmtauth,
[MarshalAs(UnmanagedType.CustomMarshaler, MarshalTypeRef = typeof(PcapStringMarshaler))] StringBuilder errbuf
);