winpcap截包问题!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

xuggzu 2010-03-30 04:44:05
使用winpcap捕获网络数据包时,如果源ip=目的ip,也就是本机不同进程通讯,能捕获到吗?如果可以,捕获的代码是否有什么特别的设置?因为我自己试过winpcap给的捕获例程,没有发现捕获到的源ip=目的ip的数据包。希望高手们解惑!
...全文
119 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
skyxie 2010-03-30
  • 打赏
  • 举报
回复
抓回环接口的包
xuggzu 2010-03-30
  • 打赏
  • 举报
回复
另外,再附带说明一下,用wpe完全可以截获本机进程间的通讯数据,但是我用的winpcap截获不到。。。
xuggzu 2010-03-30
  • 打赏
  • 举报
回复
如楼上2位所说,我也感觉不应该,不过实际我接收到的数据包没有源ip=目的ip的,下面是我的测试代码,基本就是pcap例程代码,简单修改了一下而已,代码在一个线程中运行:

if ((adhandle= pcap_open_live(devN, // name of the device
65536, // portion of the packet to capture.
// 65536 grants that the whole packet will be captured on all the MACs.
1, // promiscuous mode (nonzero means promiscuous)
1000, // read timeout
errbuf // error buffer
)) == NULL)
{
...
return 0;
}

if (lpPD->filterLen!= 0)
{
// We should loop through the adapters returned by the pcap_findalldevs_ex()
// in order to locate the correct one.
//
// Let's do things simpler: we suppose to be in a C class network ;-)
NetMask=0xffffff;

//compile the filter
if(pcap_compile(adhandle, &fcode, filter, 1, NetMask) < 0)
{
...
pcap_close(adhandle);
return 3;
}
//set the filter
if(pcap_setfilter(adhandle, &fcode)<0)
{
...
pcap_close(adhandle);
return 4;
}
delete[] filter;
}
dumpfile=pcap_dump_open(adhandle,(const char *)tmpfile);
if(dumpfile==NULL)
{
...
return 0;
}
/* Retrieve the packets */

while(1)
{
...
if(bExit) break;

res = pcap_next_ex(adhandle, &header, &data);
if(res==0)
{
Sleep(10);
continue;
}
else if(res<0)
{
break;
}

pcap_dump((u_char *)dumpfile, header, data);
...
}

希望有更好的答案。。。
jxb_memory 2010-03-30
  • 打赏
  • 举报
回复
只要经过了网卡就一定能捕获到。
cchvsgame 2010-03-30
  • 打赏
  • 举报
回复
肯定能,但端口是不一样的

18,356

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 网络编程
c++c语言开发语言 技术论坛(原bbs)
社区管理员
  • 网络编程
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧