/// <summary> /// Start listening for packets. /// </summary> /// <param name="networkInterface"> /// The network interface to listen on. /// </param> /// <param name="mode"> /// The mode to run in. /// </param> public void StartListening(IPEndPoint networkInterface, SnifferModeType mode) { StartListening(networkInterface, mode, ProtocolType.IP); }
/// <summary> /// Start listening for packets. /// </summary> /// <param name="networkInterface"> /// The network interface to listen on. /// </param> /// <param name="mode"> /// The mode to run in. /// </param> public void StartListening(IPEndPoint networkInterface, SnifferModeType mode) { StartListening (networkInterface, mode, ProtocolType.IP); }
/// <summary> /// Start listening for packets. /// </summary> /// <param name="networkInterface"> /// The network interface to listen on. /// </param> /// <param name="mode"> /// The mode to run in. /// </param> /// <param name="protocol"> /// The protocl to listen for. /// </param> public void StartListening(IPEndPoint networkInterface, SnifferModeType mode, ProtocolType protocol) { // make sure the socket is closed if (m_isRunning) { m_state.SocketObject.Close(); } // create a raw ip socket m_state.SocketObject = new Socket(AddressFamily.InterNetwork, SocketType.Raw, protocol); // bind the socket to the interface m_state.SocketObject.Bind(networkInterface); int inBuff = 1; int outBuff = 1; // set the socket to receive all packets //0x4004667F int ra = unchecked ((int)0x4004667F); if (!Wireless) { try { m_state.SocketObject.IOControl(RecieveAll, BitConverter.GetBytes(inBuff), BitConverter.GetBytes(outBuff)); } catch (Exception) { //maybe a wireless card? m_state.SocketObject.IOControl(ra, BitConverter.GetBytes(inBuff), BitConverter.GetBytes(outBuff)); Wireless = true; } } else { try { //maybe a wireless card? m_state.SocketObject.IOControl(ra, BitConverter.GetBytes(inBuff), BitConverter.GetBytes(outBuff)); } catch (Exception) { m_state.SocketObject.IOControl(RecieveAll, BitConverter.GetBytes(inBuff), BitConverter.GetBytes(outBuff)); Wireless = false; } } // save some state variables m_isRunning = true; m_mode = mode; // reset the wait object for blocking mode m_state.WaitObject.Reset(); // start the recieve loop m_state.SocketObject.BeginReceive(m_state.RecieveBuffer, 0, m_state.RecieveBuffer.Length, SocketFlags.None, new AsyncCallback(ReceiveCallback), m_state); // if in blocking mode then block until the wait object is triggered // by the callback if (mode == SnifferModeType.Blocking) { m_state.WaitObject.WaitOne(); } }
/// <summary> /// Start listening for packets. /// </summary> /// <param name="networkInterface"> /// The network interface to listen on. /// </param> /// <param name="mode"> /// The mode to run in. /// </param> /// <param name="protocol"> /// The protocl to listen for. /// </param> public void StartListening(IPEndPoint networkInterface, SnifferModeType mode, ProtocolType protocol) { // make sure the socket is closed if (m_isRunning) { m_state.SocketObject.Close (); } // create a raw ip socket m_state.SocketObject = new Socket (AddressFamily.InterNetwork, SocketType.Raw, protocol); // bind the socket to the interface m_state.SocketObject.Bind (networkInterface); int inBuff = 1; int outBuff = 1; // set the socket to receive all packets //0x4004667F int ra = unchecked((int)0x4004667F); if(!Wireless) { try { m_state.SocketObject.IOControl(RecieveAll, BitConverter.GetBytes(inBuff), BitConverter.GetBytes(outBuff)); } catch(Exception exc) { //maybe a wireless card? m_state.SocketObject.IOControl(ra, BitConverter.GetBytes(inBuff), BitConverter.GetBytes(outBuff)); Wireless=true; } } else { try { //maybe a wireless card? m_state.SocketObject.IOControl(ra, BitConverter.GetBytes(inBuff), BitConverter.GetBytes(outBuff)); } catch(Exception exc) { m_state.SocketObject.IOControl(RecieveAll, BitConverter.GetBytes(inBuff), BitConverter.GetBytes(outBuff)); Wireless=false; } } // save some state variables m_isRunning = true; m_mode = mode; // reset the wait object for blocking mode m_state.WaitObject.Reset(); // start the recieve loop m_state.SocketObject.BeginReceive (m_state.RecieveBuffer, 0, m_state.RecieveBuffer.Length, SocketFlags.None, new AsyncCallback (ReceiveCallback), m_state); // if in blocking mode then block until the wait object is triggered // by the callback if (mode == SnifferModeType.Blocking) { m_state.WaitObject.WaitOne (); } }