- r - 以节省内存的方式增长 data.frame
- ruby-on-rails - ruby/ruby on rails 内存泄漏检测
- android - 无法解析导入android.support.v7.app
- UNIX 域套接字与共享内存(映射文件)
我正在使用 libpcap 编写嗅探器。我的问题是在调用 pcap_loop() 或 pcap_next() 和实际获取数据包(调用回调函数)之间有 7-10 秒的延迟。但是,如果我在同一台设备上使用带有相同过滤器的 wireshark,则在我点击“开始”按钮后就不会出现这种延迟。为什么我的程序有延迟,有没有办法解决这个问题?
我正在研究 atheros wifi 芯片。使用
将设备设置为监控模式airmon-ng start wlan0
我确信有很多流量可以监听,因为我可以在 wireshark 中看到这些包。谢谢。
最佳答案
I'm using 10000
pcap_open_live()
和 pcap_set_timeout()
的 to_ms 参数以毫秒为单位。
10000 毫秒是 10 秒。
尝试使用 1000,这是 tcpdump 使用的值 - 这会将延迟减少到 1 秒 - 或者使用 100,这是 Wireshark 使用的值 - 这会将延迟减少到 1/10 秒。
I read on a tutorial about this field: " on at least some platforms, this means that you may wait until a sufficient number of packets arrive before seeing any packets, so you should use a non-zero timeout"
有问题的教程是the tcpdump.org "How to use libpcap" tutorial ,并且有问题的段落已添加到此 CVS 提交中:
revision 1.8
date: 2005/08/27 23:58:39; author: guy; state: Exp; lines: +34 -31
Use a non-zero timeout in pcap_open_live(), so you don't wait for a
bufferful of packets before any are processed.
Correctly explain the difference between pcap_loop() and
pcap_dispatch().
In sniffex.c, don't print the payload if there isn't any.
所以我对它很熟悉。 :-)
我不得不花一些时间(再次)查看 Linux 内核代码,以了解超时值为 0 会对较新的内核产生什么影响。但是,在编写使用 libpcap/WinPcap 进行实时捕获的代码时,您应该始终表现得好像您正在为此类平台编写代码;如果零超时的行为发生变化,您的代码将更易于移植到其他平台并且不会中断。
关于c - 为什么 pcap_loop() 和获取数据包之间有很长的延迟?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29875110/
我正在尝试使用 C 中的 pcap 进行一些嗅探,如 here 所解释的那样我的问题是 pcap_loop 绝对不捕获任何数据包和/或不执行任何操作,我的回调函数从未被调用。我的猜测是超时值,但即使我
我收到这个警告: cast to pointer from integer of different size 尝试编译我的程序时。这段特殊的代码几乎是从一个示例 TCP 连接程序中提取出来的,我只是
我正在尝试使用 Linux 中 libpcab 库中的 pcap_loop 函数和这个原型(prototype): int pcap_loop(pcap_t *, int, pcap_handler,
我有一个数据包捕获应用程序,它使用 pcap_loop() 进行数据包捕获,但发现数据包丢失。 我正在尝试向主机发送 20 个 DNS 查询。在机器上运行 tcpdump 显示 1 已收到 20 个
我正在尝试使用 pcap 进行一些简单的数据包捕获,因此我创建了一个句柄来通过 eth0 进行监听。我的问题是代码末尾附近的 pcap_loop(handle, 10, myCallback, NUL
我需要将两个不同类型的指针传递给 pcap_loop(),以便 pcap_handler 可以读取/修改该数据。 pcap_loop() 看起来像: int pcap_loop(pcap_t *p,
我遇到了 pcap 过滤器的问题。以下是部分代码: #include #include void pcap_fatal(const char *failed_in, const char *err
我正在使用 libpcap 编写嗅探器。我的问题是在调用 pcap_loop() 或 pcap_next() 和实际获取数据包(调用回调函数)之间有 7-10 秒的延迟。但是,如果我在同一台设备上使用
pcap_loop 和 pcap_dispatch 到底有什么区别? 最佳答案 手册很好地描述了这一点(我是板着脸说的,保证)。来自 man pcap_loop : pcap_loop() pr
我的问题如下:pcap_loop() 从监听接口(interface)获取所有到达的帧,如果其中一个帧包含 IP 数据,我将使用 pcap_sendpacket() 转发它。一旦我发送它,pcap_l
为什么调用pcap_loop函数后,必须等几秒才能抓到第一个包? void print_packet(u_char *, const struct pcap_pkthdr *, const u_cha
我有一个问题,假设我有一个线程可以捕获数据包并自行处理它们。 使用 pcap_next_ex:我会使用一个循环,我会在每次交互中处理数据包,假设我调用 Sleep(200) 来模拟这些东西。使用 pc
我目前正在使用 libpcap 以混杂模式嗅探流量 int main() { // some stuff printf("Opening device: %s\n", devname.
因为我想用 libpcap 做一些测试和一个小的 C 程序,我试图将一个结构从 main() 传递到 got_packet()。阅读 libpcap 教程后,我发现了这一点: The prototyp
这两个函数都是无限循环, 一旦在同一线程中调用,程序就会挂起。 gtk_main(); ... pcap_loop(adhandle, 0, packet_handler, NULL); 当我点击“开
我对套接字编程完全陌生。我正在尝试嗅探和欺骗数据包。我在 Linux 的 libpcap 库中使用 pcap_loop 并使用以下签名: int pcap_loop(pcap_t *p, int cn
我有 libpcap 版本 0.6 和 linux 内核版本 2.6.18,其中我无法升级其中任何一个,pcap_breakloop() 函数可从版本 0.8 获得。 我的问题是如何在不使用 pcap
我用 Google 搜索了很多,但我不知道 user 参数是什么用于 pcap_loop()。我在网上找到的最好的一个来自斯坦福大学(链接:http://yuba.stanford.edu/~casa
您好,我正在使用 C++ 和 libpcap。当我尝试调用函数“mycallback”时,出现构建错误。这些是函数: void Capture::mycallback (unsigned char *
如果您使用阻塞式 pcap_loop() 或 pcap_dispatch() 通过合适的回调 fn 处理传入的数据包数据,您可能需要中断这些函数,即让他们返回。 现在 pcap_breakloop()
我是一名优秀的程序员,十分优秀!