开发者

Windows Mobile 6 - .net Socket advice [Compact Framework 3.5]

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 opt开发者_如何学编程ions 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, 
                           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
//IOControlCode.ReceiveAll is equivalent to SIO_RCVALL constant of Winsock 2
mainSocket.IOControl(IOControlCode.ReceiveAll, 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 :)


CE really isn't capable of doing what you're after at a socket level. You're much better off creating and installing an NDIS Intermediate driver where you can inspect and handle all packets coming through.

As a side note, the ActiveSync connection is not a full-up network connection, but a partial RNDIS connection. Some packet types do not get forwarded through (ICMP comes to mind as an example).

Also, don't hard-code the ActiveSync address - it changed in the past and could in the future. Instead do a DNS resolve of "ppp-peer" to get the address.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜