Ilya Margoulis

hi
I'm trying to get tx / rx data that sent/received by WebBrowser control on Windows Mobile 5. For this I'm trying to write sniffer on C# - to initialize Socket, bind it, set its options and start filtering the data going in/out. The problem is that each time I try to configure a socket, I got exceptions. This is the code:

// get network identification
IPHostEntry hostEntry = Dns.GetHostEntry(Dns.GetHostName());
IPAddress ip = hostEntry.AddressList[0];



// switch on sniffer
try {
mySocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw, ProtocolType.IP); ---> this line does not make any problems
 mySocket.Bind(new IPEndPoint(ip, 0)); ------------- > this line is fine too
mySocket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.HeaderIncluded, 1);
---> this line never succeeded to be executed -> always
....
}

catch (SocketException se) {
// for debugging
}

While se is "The requested address is not valid in its context", ErrorCode = 10049
I checked in MSDN and it said that this method supported in .NET CF.
Please, help !!!




Re: .NET Compact Framework Need to get tx/rx for a given site

AlexY

I think you'd be better off by using the GetIpStatisticsEx API:

http://msdn2.microsoft.com/fr-fr/library/aa450415.aspx





Re: .NET Compact Framework Need to get tx/rx for a given site

Ilya Margoulis

Thanks for your help but it is not good enough. I should get these statistics per each site I'm surfing in order to compare.

Did you look at the code I posted Do you have any idea why this does not work

thanks again





Re: .NET Compact Framework Need to get tx/rx for a given site

Sandeep Prabhakar

Maybe this might help answer the problem http://www.codeguru.com/forum/showthread.php t=320739

Searching online I got this as the reason for the error message: The requested address is not valid in its context. Normally results from an attempt to bind to an address that is not valid for the local machine. This can also result from connect, sendto, WSAConnect, WSAJoinLeaf, or WSASendTo when the remote address or port is not valid for a remote machine (e.g. address or port 0).

Thanks,

Sandy





Re: .NET Compact Framework Need to get tx/rx for a given site

Ilya Margoulis

Sandy, thanks again !
The exception happens on setSocketOption and not on bind. I'm still trying to figure out why is that but no success so far :(
The code posted above will capture all the traffic for a given network interface( ip ). May be somebody can post code that will listen to all TCP traffic, specifically HTTP.

Thanks again