18,356
社区成员
发帖
与我相关
我的任务
分享
//编译过滤器
if(0==filter_index)
{
char filter[] = "ether host 54:EE:75:AB:E2:BD";
if (pcap_compile(adhandle, &fcode, filter, 1, netmask) <0 )
{
MessageBox(_T("语法错误,无法编译过滤器"));
pcap_freealldevs(alldev);
return -1;
}
}else{
CString str;
char *filter;
int len,x;
this->m_comboBoxRule.GetLBText(filter_index,str);
len = str.GetLength()+1;
filter = (char*)malloc(len);
for(x=0;x<len;x++)
{
filter[x] = str.GetAt(x);
}
if (pcap_compile(adhandle, &fcode, filter, 1, netmask) <0 )
{
MessageBox(_T("ether host 54:EE:75:AB:E2:BD"));
pcap_freealldevs(alldev);
return -1;
}
}
//设置过滤器
if (pcap_setfilter(adhandle, &fcode)<0)
{
MessageBox(_T("设置过滤器错误"));
pcap_freealldevs(alldev);
return -1;
}