我看已有的实例上是允许获取TCP,UDP,ARP协议的数据包,但我不知道他的这个过滤
的规则具体写在哪里。我本人要做的是除了以上协议也允许获取OSPF协议的数据包,
求大神指教,我需要改哪里。具体代码如下:
struct bpf_program fcode;
bpf_u_int32 NetMask;
NetMask=0xffffff;
pcap_t *pCap;
char strErrorBuf[1025];
//OnButtonFiltersave();
char filter[1024];
strcpy(filter, m_strFilterString.GetBuffer(m_strFilterString.GetLength()));
m_strFilterString.ReleaseBuffer();
if( getDevice() != NULL )
{
if((pCap=pcap_open_live(getDevice()->name,65536,1,1000,strErrorBuf))==NULL)
{
return ;
}
if(pcap_compile(pCap, &fcode, filter, 1, NetMask) < 0)
{
//fprintf(stderr,"\nError compiling filter: wrong syntax.\n");
AfxMessageBox("编译字符串失败,请确认你的规则编写的正确性,或查看帮助文档中规则的编写规范");
return ;
}
AfxMessageBox("规则:"+m_strFilterString+"\n测试通过!!!!");
pcap_close(pCap);
}
else
AfxMessageBox("当前没有选持要测试的网卡");