public IpSnifferWinPcap(string filter) { _filter = filter; BufferSize = 1 << 24; _devices = NpcapDeviceList.New(); //BasicTeraData.LogError(string.Join("\r\n",_devices.Select(x=>x.Description)),true,true); //check for winpcap installed if not - exception to fallback to rawsockets _devices = null; }
private void Start() { Debug.Assert(_devices == null); _devices = NpcapDeviceList.New(); var interestingDevices = _devices.Where(IsInteresting); foreach (var device in interestingDevices) { device.OnPacketArrival += device_OnPacketArrival; try { device.Open(DeviceMode.Normal, 100); } catch (Exception) { //Logger.Warn($"Failed to open device {device.Name}. {e.Message}"); continue; } device.Filter = _filter; if (BufferSize != null) { try { device.KernelBufferSize = (uint)BufferSize.Value; } catch (Exception) { //Logger.Warn( // $"Failed to set KernelBufferSize to {BufferSize.Value} on {device.Name}. {e.Message}"); } } device.StartCapture(); Debug.WriteLine("winpcap capture"); } }