2010-04-14 108 views
0

我試圖打開一個套接字,它將接收通過Active Sync網絡發送到Windows Mobile設備的所有數據包。Windows Mobile 6 - .net Socket建議[Compact Framework 3.5]

我使用代碼:CS Network Sniffer for Windows

具體做法是:

//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)); 

我通過活動同步

特異性結合的IP設置和以下套接字選項不可用在Windows Mobile上,是否有任何其他選項可以在Windows Mobile上使用以獲得相同的效果?我看到在MSDN上沒有太大的幫助名單 - 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); 

最後的代碼,即可獲得:

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

再次,我的目標是通過Active Sync網絡在我的Windows Mobile設備上的TCP和UDP的所有端口上接收所有傳入數據包。 任何幫助,建議或代碼非常感謝,C#,VB.net,C++都很好:)

回答

0

CE真的不能夠做你在插座級別。你最好創建並安裝一個NDIS Intermediate driver,你可以檢查和處理所有通過的數據包。

請注意,ActiveSync連接不是完整的網絡連接,而是部分RNDIS連接。某些數據包類型無法通過轉發(例如ICMP)。

另外,不要對ActiveSync地址進行硬編碼 - 它在過去和未來都會發生變化。而是做一個「ppp-peer」的DNS解析來獲取地址。

相關問題