/// <summary>
 /// Closes the currently open device
 /// </summary>
 public void CloseDevice()
 {
     if (bRun)
     {
         throw new InvalidOperationException("A capture is currently running");
     }
     if (iptrOpenDevice != IntPtr.Zero)
     {
         pcap_close(iptrOpenDevice);
         iptrOpenDevice          = IntPtr.Zero;
         wpcCurrentOpenInterface = null;
         wpfCurrentFilter        = null;
     }
 }
        /// <summary>
        /// Opens the specified device for sniffing
        /// </summary>
        /// <param name="wpiInterface">The device to open</param>
        /// <param name="pofFlags">Configuration flags for opening</param>
        public void OpenDevice(WinPcapInterface wpiInterface, PcapOpenflags pofFlags)
        {
            if (bRun)
            {
                throw new InvalidOperationException("A capture is currently running");
            }
            CloseDevice();
            string strErrorbuff = "";
            IntPtr ptrDevice    = pcap_open(wpiInterface.Name, 65535, pofFlags, 5, IntPtr.Zero, strErrorbuff);

            if (ptrDevice == IntPtr.Zero)
            {
                throw new Exception("Error when trying to open WinPcap device: " + strErrorbuff);
            }
            iptrOpenDevice          = ptrDevice;
            wpcCurrentOpenInterface = wpiInterface;
            wpfCurrentFilter        = CompileFilter("", true, new Subnetmask());
        }