/// <summary> /// Closes this adapter /// </summary> public virtual void Close() { if (PcapHandle == IntPtr.Zero) { return; } if (Started) { try { StopCapture(); } catch (Exception) { } } LibPcapSafeNativeMethods.pcap_close(PcapHandle); PcapHandle = IntPtr.Zero; //Remove event handlers if (OnPacketArrival != null) { foreach (PacketArrivalEventHandler pa in OnPacketArrival.GetInvocationList()) { OnPacketArrival -= pa; } } }
/// <summary> /// Returns true if the filter expression was able to be compiled into a /// program without errors /// </summary> public static bool CheckFilter(string filterExpression, out string errorString) { IntPtr fakePcap = LibPcapSafeNativeMethods.pcap_open_dead((int)PacketDotNet.LinkLayers.Ethernet, Pcap.MAX_PACKET_SIZE); uint mask = 0; if (!CompileFilter(fakePcap, filterExpression, mask, out IntPtr bpfProgram, out errorString)) { LibPcapSafeNativeMethods.pcap_close(fakePcap); return(false); } FreeBpfProgram(bpfProgram); LibPcapSafeNativeMethods.pcap_close(fakePcap); return(true); }
private static bool GetIsHardwareAccelerated() { var handle = LibPcapSafeNativeMethods.pcap_open_dead(1, 60); try { pcap_send_queue queue = default; LibPcapSafeNativeMethods.pcap_sendqueue_transmit(handle, ref queue, 0); return(true); } catch (TypeLoadException) { // Function pcap_sendqueue_transmit not found return(false); } finally { LibPcapSafeNativeMethods.pcap_close(handle); } }
/// <summary> /// Closes this adapter /// </summary> public virtual void Close() { //Remove event handlers OnPacketArrival = null; if (PcapHandle == IntPtr.Zero) { return; } if (Started) { try { StopCapture(); } catch (Exception) { } } LibPcapSafeNativeMethods.pcap_close(PcapHandle); PcapHandle = IntPtr.Zero; }
protected override bool ReleaseHandle() { LibPcapSafeNativeMethods.pcap_close(handle); return(true); }