views:

411

answers:

0

Hi,

I'm trying to open a socket that will receive all packets sent to the Windows Mobile Device over the Active Sync network.

I'm using code from: CS Network Sniffer for Windows

Specifically:

                //For sniffing the socket to capture the packets has to be a raw socket, with the
                //address family being of type internetwork, and protocol being IP
                mainSocket = new Socket(AddressFamily.InterNetwork,
                    SocketType.Raw, ProtocolType.IP);

                //Bind the socket to All Network Communication
                mainSocket.Bind(new IPEndPoint(IPAddress.Parse("169.254.2.1"), 0));

I'm binding specifically to the IP setup through Active Sync

And the following socket options aren't available on Windows Mobile, are there any other options that can be used on Windows Mobile to get the same effect? The list I've seen on MSDN doesn't help much - msdn.microsoft.com/en-us/library/aa926870.aspx

                //Set the socket  options
                mainSocket.SetSocketOption(SocketOptionLevel.IP,            //Applies only to IPv4 packets
                                           SocketOptionName.HeaderIncluded, //Set the include the header
                                           true);                           //option to true

                byte[] byTrue = new byte[4] { 1, 0, 0, 0 };
                byte[] byOut = new byte[4] { 1, 0, 0, 0 }; //Capture outgoing packets

                //Socket.IOControl is analogous to the WSAIoctl method of Winsock 2
                mainSocket.IOControl(IOControlCode.ReceiveAll,              //Equivalent to SIO_RCVALL constant
                //of Winsock 2
                                     byTrue,
                                     byOut);

Finally the Code to Receive:

                //Start receiving the packets asynchronously
                mainSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None,
                    new AsyncCallback(OnReceive), null);

Again, my goal is to receive all incoming packets on all ports for TCP and UDP on my Windows Mobile Device, through the Active Sync network. Any help, advice or code is greatly appreciated, C#, VB.net, C++ is all good :)

Thanks,

-Tim