SharpPCap 中的第二个 LivePCapDevice 不起作用?

发布于 2024-10-08 09:03:21 字数 855 浏览 2 评论 0原文

我使用 lib SharpPCap 捕获数据包,然后分析它们以在 PacketArrivalEventHandler 函数中找到 flv 视频地址。类的主要部分是这样的:

class addrdetector
{
    private LivePCapDevice device;
    private device_OnPacketArrival(object sender, CaptureEventArgs e)
    {
        /* some analysis and some output */
        if (match)
        {
            device.StopCapture();
            device.Close();
        }
    }
    public Analyse()
    {
         var devices = LivePcapDeviceList.Instance;
         device = devices[2];
         device.OnPacketArrival +=
            new PacketArrivalEventHandler(device_OnPacketArrival);  
         device.Open();
         device.StartCapture();
    }
}

如果我在程序中有 2 个 addrdector 实例,第一个实例有正确的输出,但第二个实例没有任何输出。看起来第二个无法捕获任何数据包。
我已经在同一主函数中测试了 LivePCapDevice 的 2 个实例,它们工作正常。它们还可以在 2 个 EXE.s 中工作。但我不明白为什么它们在程序中冲突...... 谢谢~

I'm using the lib SharpPCap to capture packets, then analyse them to find the flv video address in PacketArrivalEventHandler function. The main part of class is like this:

class addrdetector
{
    private LivePCapDevice device;
    private device_OnPacketArrival(object sender, CaptureEventArgs e)
    {
        /* some analysis and some output */
        if (match)
        {
            device.StopCapture();
            device.Close();
        }
    }
    public Analyse()
    {
         var devices = LivePcapDeviceList.Instance;
         device = devices[2];
         device.OnPacketArrival +=
            new PacketArrivalEventHandler(device_OnPacketArrival);  
         device.Open();
         device.StartCapture();
    }
}

if I have 2 instances of addrdector in a program, the first instance has the correct output, but the second hasn't any output. It seems like the second can't capture any packet.
I've tested 2 instances of LivePCapDevice in a same main funcion, and they work correctly. They can also work in 2 EXE.s. But I can't find out why they conflict in a program...
Thanks~

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

卷耳 2024-10-15 09:03:21

克隆 SharpPcap 源代码并查看示例

我目前无法引用确切的示例,因为我远离我的开发计算机,但我绝对肯定有一个关于如何添加的示例额外的 LivePcapDevice 实例。

这并非不可能,但解决方案并不直观。我认为使用的示例被称为“CaptureMultipleFilters”。

祝你好运,我会尽快用更好的数据更新这个答案。

Clone the SharpPcap source and look at the examples

I can't reference the exact example at the moment because I'm away from my development computer but I'm absolutely positive that there's an example of how to add additional LivePcapDevice instances.

It's not impossible but the solution isn't intuitive. I think the example that uses is is called something along the lines of "CaptureMultipleFilters".

Good luck and I'll update this answer with better data as soon as I can.

星光不落少年眉 2024-10-15 09:03:21

项目名称:MultipleFiltersOnDevice。

代码如下:

var device1 = CaptureDeviceList.Instance[i];
var device2 = CaptureDeviceList.New()[i]; // NOTE: the call to New()

它对我有用。

Nameproject : MultipleFiltersOnDevice.

And the code is the following :

var device1 = CaptureDeviceList.Instance[i];
var device2 = CaptureDeviceList.New()[i]; // NOTE: the call to New()

It works for me.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文