Exemplo n.º 1
0
        /// <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;
                }
            }
        }
Exemplo n.º 2
0
        /// <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);
        }
Exemplo n.º 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);
            }
        }
Exemplo n.º 4
0
        /// <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;
        }
Exemplo n.º 5
0
 protected override bool ReleaseHandle()
 {
     LibPcapSafeNativeMethods.pcap_close(handle);
     return(true);
 }