Exemplo n.º 1
0
        /// <summary>
        /// Closes this adapter
        /// </summary>
        public virtual void Close()
        {
            if (PcapHandle == IntPtr.Zero)
            {
                return;
            }

            if (Started)
            {
                StopCapture();
            }
            SafeNativeMethods.pcap_close(PcapHandle);
            PcapHandle = IntPtr.Zero;

            //Remove event handlers
            if (OnPacketArrival != null)
            {
                foreach (Pcap.PacketArrivalEvent pa in OnPacketArrival.GetInvocationList())
                {
                    OnPacketArrival -= pa;
                }
            }
            if (OnPcapStatistics != null)
            {
                foreach (Pcap.PcapStatisticsEvent pse in OnPcapStatistics.GetInvocationList())
                {
                    OnPcapStatistics -= pse;
                }
            }
        }
Exemplo n.º 2
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;
                }
            }
        }