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.
IPHostEntry hIPHostEntry = Dns.GetHostEntry( Dns.GetHostName());
Socket hSocket = new Socket( AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.Unspecified );
foreach ( IPAddress hIPAddress in hIPHostEntry.AddressList ) try { hSocket.Bind( new IPEndPoint( hIPAddress, 0 )); } catch( Exception ) { continue; }
hSocket.SetSocketOption( SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, true );
hSocket.IOControl( IOControlCode.ReceiveAll, BitConverter.GetBytes( 1 ), BitConverter.GetBytes( 1 ));
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. - , , ..