/// <summary> /// Open the device. To start capturing call the 'StartCapture' function /// </summary> /// <param name="mode"> /// A <see cref="DeviceMode"/> /// </param> /// <param name="read_timeout"> /// A <see cref="System.Int32"/> /// </param> public override void Open(DeviceMode mode, int read_timeout) { if (!Opened) { StringBuilder errbuf = new StringBuilder(Pcap.PCAP_ERRBUF_SIZE); //will hold errors // set the StopCaptureTimeout value to twice the read timeout to ensure that // we wait long enough before considering the capture thread to be stuck when stopping // a background capture via StopCapture() // // NOTE: Doesn't affect Mono if unix poll is available, doesn't affect Linux because // Linux devices have no timeout, they always block. Only affects Windows devices. StopCaptureTimeout = new TimeSpan(0, 0, 0, 0, read_timeout * 2); PcapHandle = LibPcapSafeNativeMethods.pcap_open_live (Name, // name of the device Pcap.MAX_PACKET_SIZE, // portion of the packet to capture. // MAX_PACKET_SIZE (65536) grants that the whole packet will be captured on all the MACs. (int)mode, // promiscuous mode read_timeout, // read timeout errbuf); // error buffer if (PcapHandle == IntPtr.Zero) { string err = "Unable to open the adapter (" + Name + "). " + errbuf.ToString(); throw new PcapException(err); } } }