- 1、本文档共8页,可阅读全部内容。
- 2、原创力文档(book118)网站文档一经付费(服务费),不意味着购买了该文档的版权,仅供个人/单位学习、研究之用,不得用于商业用途,未经授权,严禁复制、发行、汇编、翻译或者网络传播等,侵权必究。
- 3、本站所有内容均由合作方或网友上传,本站不对文档的完整性、权威性及其观点立场正确性做任何保证或承诺!文档内容仅供研究参考,付费前请自行鉴别。如您付费,意味着您自己接受本站规则且自行承担风险,本站不退款、不进行额外附加服务;查看《如何避免下载的几个坑》。如果您已付费下载过本站文档,您可以点击 这里二次下载。
- 4、如文档侵犯商业秘密、侵犯著作权、侵犯人身权等,请点击“版权申诉”(推荐),也可以打举报电话:400-050-0827(电话支持时间:9:00-18:30)。
上机1:基于WinPcap网络嗅探器设计
1、目标和要求
掌握基于WinPcap网络编程模式。
了解并能应用WinPcap设计并实现网络数据包捕捉和解析。
2、设备和上机环境
连网PC机(最少一台)。
计算机硬件要求:IntelPentium5处理器、256MB以上内存,Ethernet网卡,网线若干。
计算机软件要求:MSWindows9x//XP操作系统,TCP/IP协议,WinPcap430,Visualc++6.0/.net系统。
3、上机内容和步骤:
在程序设计之前,请参考提供软件安装WinPcap。以后,根据以下步骤操作:
步骤1:在VC++6.0下创建一个DOS命令行程序,工程名:自己学号-PacketDump
步骤2:打开main()函数,在主程序中增加以下头文件和常量定义:
#include<pcap.h>
#include<pcap.h>
#defineLINE_LEN16
pcap_if_t*alldevs,*d;
pcap_t*fp;
u_intinum,i=0;
charerrbuf[PCAP_ERRBUF_SIZE];
intres;
structpcap_pkthdr*header;
constu_char*pkt_data;
printf("pktdump_ex:printsthepacketsofthenetworkusingWinPcap.\n");
printf("Usage:pktdump_ex[-ssource]\n\n"
"Examples:\n"
"pktdump_ex-sfile.acp\n"
"pktdump_ex-s\\Device\\NPF_{C8736017-F3C3-4373-94AC-9A
if(argc<3)
{
printf("\nNoadapterselected:printingthedevicelist:\n");
/*Theuserdidn'tprovideapacketsource:Retrievethelocaldevicelist*/
if(pcap_findalldevs(&alldevs,errbuf)==-1)
{
fprintf(stderr,"Errorinpcap_findalldevs_ex:%s\n",errbuf);
exit(1);
}
/*Printthelist*/
for(d=alldevs;d;d=d->next)
{
printf("%d.%s\n",++i,d->name);
if(d->description)
printf("(%s)\n",d->description);
else
printf("(Nodescriptionavailable)\n");
}
if(i==0)
{
printf("\nNointerfacesfound!MakesureWinPcapisinstalled.\n");
return-1;
}
printf("Entertheinterfacenumber(1-%d):",i);
scanf("%d",&inum);
if(inum<1||inum>i)
{
printf("\nInterfacenumberoutofrange.\n");
/*Freethedevicelist*/
pcap_freealldevs(alldevs);
return-1;
}
/*Jumptotheselectedadapter*/
for(d=alldevs,i=0;i<inum-1;d=d->next,i++);
/*Opentheadapter*/
if((fp=pcap_open_live(d->name, //nameofthedevice
65536, //portionofthepackettocapture.
//65536grantsthatthewholepacketwillbecapturedonalltheMACs.
1, //pro
文档评论(0)