Wincap设置过滤器,该如何解决
答案:2 悬赏:80
解决时间 2021-12-12 17:30
- 提问者网友:熱戀丶瘋
- 2021-12-12 12:37
Wincap设置过滤器,该如何解决
最佳答案
- 二级知识专家网友:滚出爷的世界
- 2021-12-12 13:44
我按照Wincap官方的例子,设置我的抓包程序的过滤器。
BOOL CapturePacket::SetFilter(char * packet_filter)//设置过滤器{if (pcap_compile(adhandle, &fcode, packet_filter, 1, netmask) <0 )//设置过滤器{AfxMessageBox(Unable to compil e the packet filter. Check the syntax.);
TRACE(Error reading the packets: %s\n, pcap_geterr(adhandle));//语法错误,&fcode为0
pcap_freealldevs(alldevs);//return -1;}if (pcap_setfilter(adhandle, &fcode)<0)//设置过滤器{AfxMessageBox(Error setting the filter.);
pcap_freealldevs(alldevs);return -1;}// pcap_loop(adhandle, 0, packet_handler, NULL);return 0;}pcap_compile函数执行返回小于0的数,就是没设置成功。于是我调试发现是&fcode为0。
就是开始定义struct bpf_program fcode;
然后pcap_compile,pcap_setfilter的参数调用啊!没其他地方调用,我问别人说,这个值要有值才行。
在pcap_compile(adhandle, &fcode, packet_filter, 1, netmask)中,fcode的使用方式
基本上就是 :struct bpf_program fcode;然后传给这个接口就好了,这个参数的值是由pcap_compile来写的
我觉得之所以返回值小于0,你可能需要检查:
(1)adhandle,这个是一个网卡;
(2)packet_filter是不是符合winpcap的语法规则
(3)netmask是否正确,拿不准的话可以用0xffffff
希望对你有用
------解决方案--------------------------------------------------------
int pcap_setfilter ( pcap_t * p,
struct bpf_program * fp)Associate a filter to a capture.
pcap_setfilter() is used to specify a filter program. fp is a pointer to a bpf_program struct, usually the result of a call to pcap_compile(). -1 is returned on failure, in which case pcap_geterr() may be used to display the error text; 0 is returned on success.
------解决方案--------------------------------------------------------
应该肯定不是fcode的问题你看看是不是掩码没有设置正确
BOOL CapturePacket::SetFilter(char * packet_filter)//设置过滤器{if (pcap_compile(adhandle, &fcode, packet_filter, 1, netmask) <0 )//设置过滤器{AfxMessageBox(Unable to compil e the packet filter. Check the syntax.);
TRACE(Error reading the packets: %s\n, pcap_geterr(adhandle));//语法错误,&fcode为0
pcap_freealldevs(alldevs);//return -1;}if (pcap_setfilter(adhandle, &fcode)<0)//设置过滤器{AfxMessageBox(Error setting the filter.);
pcap_freealldevs(alldevs);return -1;}// pcap_loop(adhandle, 0, packet_handler, NULL);return 0;}pcap_compile函数执行返回小于0的数,就是没设置成功。于是我调试发现是&fcode为0。
就是开始定义struct bpf_program fcode;
然后pcap_compile,pcap_setfilter的参数调用啊!没其他地方调用,我问别人说,这个值要有值才行。
在pcap_compile(adhandle, &fcode, packet_filter, 1, netmask)中,fcode的使用方式
基本上就是 :struct bpf_program fcode;然后传给这个接口就好了,这个参数的值是由pcap_compile来写的
我觉得之所以返回值小于0,你可能需要检查:
(1)adhandle,这个是一个网卡;
(2)packet_filter是不是符合winpcap的语法规则
(3)netmask是否正确,拿不准的话可以用0xffffff
希望对你有用
------解决方案--------------------------------------------------------
int pcap_setfilter ( pcap_t * p,
struct bpf_program * fp)Associate a filter to a capture.
pcap_setfilter() is used to specify a filter program. fp is a pointer to a bpf_program struct, usually the result of a call to pcap_compile(). -1 is returned on failure, in which case pcap_geterr() may be used to display the error text; 0 is returned on success.
------解决方案--------------------------------------------------------
应该肯定不是fcode的问题你看看是不是掩码没有设置正确
全部回答
- 1楼网友:丢不掉的轻狂
- 2021-12-12 14:33
任务占坑
我要举报
如以上问答内容为低俗、色情、不良、暴力、侵权、涉及违法等信息,可以点下面链接进行举报!
大家都在看
推荐资讯