我已经搜索了一段时间了,但是是否有一种方法可以使用已经内置到Qt库中的设备来监视特定应用程序中的网络流量呢?我已经找到了一些使用WinPCap和其他类似实用程序的解决方案,但我希望将其保存在Qt ( C++)中,因为这是我最熟悉的。
谢谢!任何指点都是非常感谢的!
发布于 2013-09-10 14:31:43
c#嗅探器套接字创建的一些示例。
mainSocket = new Socket(AddressFamily.InterNetwork, SocketType.Raw,
ProtocolType.IP);
// Bind the socket to the selected IP address
mainSocket.Bind(newIPEndPoint(IPAddress.Parse(cmbInterfaces.Text),0));
// Set the socket options
mainSocket.SetSocketOption(SocketOptionLevel.IP, //Applies only to IP packets
SocketOptionName.HeaderIncluded, //Set the include header
true); //option to true
byte[] byTrue = newbyte[4]{1, 0, 0, 0};
byte[] byOut = newbyte[4];
//Socket.IOControl is analogous to the WSAIoctl method of Winsock 2
mainSocket.IOControl(IOControlCode.ReceiveAll, //SIO_RCVALL of Winsock
byTrue, byOut);
//Start receiving the packets asynchronously
mainSocket.BeginReceive(byteData, 0, byteData.Length, SocketFlags.None,
newAsyncCallback(OnReceive), null);也许qt提供了一些api来创建这样的sockets.After,创建这样的套接字,您将在上面得到原始的pacets,解析头和其他信息。
https://stackoverflow.com/questions/18721348
复制相似问题