pcap_set_rfmon 成功返回 0 但接口未设置为监视模式
我正在尝试编写一个小程序,使用 C
将我的网络接口设置为 monitor 模式
,函数 pcap_set_rfmon 返回 0 表示成功,但接口仍处于管理模式。我确信我的网卡支持监视器模式,因为我已经使用 ng-airmon 和 iwconfig wlp3s0 模式监视器检查过 wlp3s0 是我的网络接口的名称。
这是我的代码:
#include <pcap.h>
main()
{
char error_buffer[PCAP_ERRBUF_SIZE];
pcap_t *handle = pcap_create("wlp3s0", error_buffer);
int result = pcap_set_rfmon(handle, 1);
if (result != 0)
{
printf("failed to set pcap rfmon");
}
}
由于代码没有输出任何内容,只返回 0,我不知道出了什么问题,也不知道在哪里查看,你们能告诉我应该检查什么或缺少什么吗
I'm trying to write a small program which set my network interface to monitor mode
using C
, the function pcap_set_rfmon returns 0 as success but the interface is still in mange mode. I'm sure my network card supports Monitor mode because i have checked using ng-airmon
and iwconfig wlp3s0 mode monitor
the wlp3s0 is my network interface's name.
Here's my code:
#include <pcap.h>
main()
{
char error_buffer[PCAP_ERRBUF_SIZE];
pcap_t *handle = pcap_create("wlp3s0", error_buffer);
int result = pcap_set_rfmon(handle, 1);
if (result != 0)
{
printf("failed to set pcap rfmon");
}
}
Since the code output nothing and just returns 0, i don't know what has gone wrong and where to look at, can you guys tell me what i should check or something is missing
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
引用
pcap_set_rfmon()
的文档:我已经强调了其中的一部分 - “当手柄被激活时”。
pcap_set_rfmon()
所做的只是在pcap_t
中设置一个标志来指示,当程序调用pcap_activate()
>,适配器将进入监控模式(如果pcap_activate()
成功)。您没有调用
pcap_activate()
,因此什么也没有发生。您还必须保持
pcap_t
打开 - 即使程序这样做也只会让适配器在退出时恢复到托管模式。您需要在
main()
末尾添加一些内容,这样程序就不会退出,除非您中断或终止它。(注意:我向程序添加了更多错误检查和报告。这是一件好事,因为这意味着,如果某些功能不起作用,程序将给出详细的错误报告,帮助您或任何您寻求帮助的人- 尝试解决问题,而不是只是默默地失败,或者如果
pcap_create()
失败,则崩溃。)To quote the documentation for
pcap_set_rfmon()
:I've emphasized part of that - "when the handle is activated". All
pcap_set_rfmon()
does is set a flag in thepcap_t
to indicate that, when the program callspcap_activate()
, the adapter would be put in monitor mode (ifpcap_activate()
succeeds).You aren't calling
pcap_activate()
, so nothing happens.You will also have to keep the
pcap_t
open - even a program that doeswill just let the adapter revert to managed mode when it exits. You will need to add something such as
at the end of
main()
, so the program doesn't exit unless you interrupt or terminate it.(Note: I added more error checking and reporting to the program. This Is A Good Thing, as it means that, if something doesn't work, the program will give a detailed error report, helping you - or whoever you ask for help - try to fix the problem, rather than just silently failing or, if
pcap_create()
fails, crashing.)