0
使用设备我试图做出会收到多个网络设备的数据包,并送他们上的其他设备(像软件中心)的程序。我正在使用C#和pcapdotnet。这个简单的方法捕获设备通信:C#pcapdotnet ReceivePackets回调
public void sniff(LivePacketDevice device)
{
using(PacketCommunicator comm = device.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
{
comm.ReceivePackets(0, printandsend);
}
}
在回调方法“printandsend”我想每个设备上发送数据包,除非数据包是从哪里来的设备。为防止将数据包发送到设备,我需要知道从哪个设备发送数据包。问题是,我不知道如何解析当前使用的设备到该回调方法。方法之外的变量对我来说不是一个解决方案,因为捕获数据包可以同时在多个设备上使用。通过创建“嗅探”方法的线程在同一时间捕获设备。
有一个可能的解决方法使用方法receivePacket:
Packet packet;
While(true)
{
comm.ReceivePacket(out packet);
send(packet,device)
//this would send packet on every device except the one which is used as a parameter
}
问题是,我不知道,如果这个解决方法可以提供所有的数据包将被成功地接收和发送。