private void StartSniffing() { isSniffing = true; var options = new PacketAnalyzerOptions() { FilterByIp = new List <IPAddress>() { _loginServerIp } }; _logger.Log(Severity.Info, "Sniffer is being loaded..."); _packetDataAnalyzer = new PacketDataAnalyzer(_logger, options); _packetDataAnalyzer.OnJoinedGame += OnJoinedGame; _sniffer = new SocketSniffer(SelectedNetworkInterface.Data, _logger, _packetDataAnalyzer); _sniffer.Start(); }
public SocketSniffer(NetworkInterfaceInfo nic, ILogger logger, PacketDataAnalyzer analyzer) { _logger = logger; _outputQueue = new BlockingCollection <TimestampedData>(); _analyzer = analyzer; _bufferManager = new BufferManager(BUFFER_SIZE, MAX_RECEIVE); _receivePool = new ConcurrentStack <SocketAsyncEventArgs>(); // IPv4 this._socket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP); this._socket.Bind(new IPEndPoint(nic.IPAddress, 0)); this._socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true); // Enter promiscuous mode try { this._socket.IOControl(IOControlCode.ReceiveAll, BitConverter.GetBytes(1), new byte[4]); } catch (Exception ex) { _logger.Log(Severity.Debug, $"Unable to enter promiscuous mode: {ex}"); throw; } }