コード例 #1
0
ファイル: PcapDevice.cs プロジェクト: rj2Skipper/sharppcap
        /// <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;
                }
            }
        }
コード例 #2
0
ファイル: PcapDevice.cs プロジェクト: zhouzu/sharppcap
        /// <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);
        }
コード例 #3
0
        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);
            }
        }
コード例 #4
0
ファイル: PcapDevice.cs プロジェクト: zhouzu/sharppcap
        /// <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;
        }
コード例 #5
0
ファイル: PcapHandle.cs プロジェクト: kayoub5/sharppcap
 protected override bool ReleaseHandle()
 {
     LibPcapSafeNativeMethods.pcap_close(handle);
     return(true);
 }