Reading incoming packets using raw socket in IP protocol in C #

I am trying to read incoming packets on a raw socket with headers enabled. By looking at other projects, such as MJsniffer in CodeProject, I was able to create my own code to read everything I want. Problem: I receive only information that is FAULT. Here is my code to initialize the raw socket, the processing code does not matter at the moment.

// Resolve the host name or IP address to am IPHostEntry instance
IPHostEntry hIPHostEntry = Dns.GetHostEntry( Dns.GetHostName());

// Initialize a new instance of the Socket class.
Socket hSocket = new Socket( AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Unspecified ); // IP is possible.

// Bind the socket to each resolved IP address.
foreach ( IPAddress hIPAddress in hIPHostEntry.AddressList ) try { hSocket.Bind( new IPEndPoint( hIPAddress, 0 )); } catch( Exception ) { continue; }

// Configure the incoming socket to accept all the required information.
hSocket.SetSocketOption( SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true );

// Configure the incoming socket to receive all the required information.
hSocket.IOControl( IOControlCode.ReceiveAll, BitConverter.GetBytes( 1 ), BitConverter.GetBytes( 1 ));

// Return the configured socket.
return hSocket;

Running on Windows 7 64-bit, I have full administrator rights, how can I change this code to get a socket capable of reading incoming packets? Outbound is good, and I need it too, but I also need incoming packets.

P.S: WinPcap. - , , ..

+3
2

, - :

, , , Visual Studio. , ! VS debug.exe(MJSniff.vshost.exe) , . ( ...)

: :

+1

IPAddress.Any ? , .

, Receive() ReceiveFrom(), ReceivedFrom() .

0

All Articles