我在我的应用程序中使用 PcapDotNet DLL,我遇到了一个问题:
我的应用程序需要一个 PCap 文件(Wireshark 文件)并将数据包发送到网卡。如果我多次发送一个或多个文件(通常约为 500 次),我的应用程序会崩溃并显示错误Failed opening file C:\file.pcap。我试图在项目论坛中询问,但开发人员不是永久在那里,所以也许其他人可以在这里帮助我。
错误原因在inputCommunicator中,发生错误时,此对象值为 null。请注意,这只发生在几百次迭代(大约 500 次)之后。
代码:
using (PacketCommunicator inputCommunicator = selectedInputDevice.Open(65536, PacketDeviceOpenAttributes.Promiscuous, 1000))
{
using (mOutputCommunicator = selectedOutputDevice.Open(100, PacketDeviceOpenAttributes.Promiscuous, 1000))
{
while (inputCommunicator.ReceivePacket(out packet) == PacketCommunicatorReceiveResult.Ok && _isStop) //fill the buffer with the packets from the file
{
using (PacketSendBuffer mSendBuffer = new PacketSendBuffer((uint)packet.Length * 4))
{
else if (packet != null)
{
lastTime = packet.Timestamp;
mSendBuffer.Enqueue(packet); //put the packet in the buffer
}
mOutputCommunicator.Transmit(mSendBuffer, _isBurst); //send the packet
_numberOfSendPackets++;
}
}
}
}