上机1基于WinPcap的网络嗅探器设计与实现.doc

上机1基于WinPcap的网络嗅探器设计与实现.doc

ID:58998091

大小:149.00 KB

页数:8页

时间:2020-09-16

上机1基于WinPcap的网络嗅探器设计与实现.doc_第1页
上机1基于WinPcap的网络嗅探器设计与实现.doc_第2页
上机1基于WinPcap的网络嗅探器设计与实现.doc_第3页
上机1基于WinPcap的网络嗅探器设计与实现.doc_第4页
上机1基于WinPcap的网络嗅探器设计与实现.doc_第5页
资源描述:

《上机1基于WinPcap的网络嗅探器设计与实现.doc》由会员上传分享,免费在线阅读,更多相关内容在教育资源-天天文库

1、上机1:基于WinPcap的网络嗅探器设计1、目的与要求掌握基于WinPcap的网络编程模式。理解并能应用WinPcap设计并实现网络数据包的捕获与解析。2、设备与上机环境l连网PC机(至少一台)。l计算机硬件要求:IntelPentium5处理器、256MB以上内存,Ethernet网卡,网线若干。l计算机软件要求:MSWindows9x/2000/XP操作系统,TCP/IP协议,WinPcap430,Visualc++6.0/.net系统。3、上机内容与步骤:在程序设计之前,请参照提供的软件安装WinPcap。之后,按照如下步骤操作:步骤1:在VC++6.0下创建一个DOS命

2、令行程序,工程名:自己的学号-PacketDump步骤2:打开main()函数,在主程序中增加如下头文件和常量定义:#include#defineLINE_LEN16pcap_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.");printf("Us

3、age:pktdump_ex[-ssource]""Examples:""pktdump_ex-sfile.acp""pktdump_ex-s\Device\NPF_{C-F3C3-4373-94AC-9A34B7DAD998}");if(argc<3){printf("Noadapterselected:printingthedevicelist:");/*Theuserdidn'tprovideapacketsource:Retrievethelocaldevicelist*/if(pcap_findalldevs(&alldevs,err

4、buf)==-1){fprintf(stderr,"Errorinpcap_findalldevs_ex:%s",errbuf);exit(1);}/*Printthelist*/for(d=alldevs;d;d=d->next){printf("%d.%s",++i,d->name);if(d->description)printf("(%s)",d->description);elseprintf("(Nodescriptionavailable)");}if(i==0){printf("Nointerfacesfound!MakesureWinPcap

5、isinstalled.");return-1;}printf("Entertheinterfacenumber(1-%d):",i);scanf("%d",&inum);if(inum<1

6、

7、inum>i){printf("Interfacenumberoutofrange.");/*Freethedevicelist*/pcap_freealldevs(alldevs);return-1;}/*Jumptotheselectedadapter*/for(d=alldevs,i=0;inext,i++);/*Opentheadapter*/

8、if((fp=pcap_open_live(d->name,//nameofthedevice65536,//portionofthepackettocapture.//65536grantsthatthewholepacketwillbecapturedonalltheMACs.1,//promiscuousmode(nonzeromeanspromiscuous)1000,//readtimeouterrbuf//errorbuffer))==NULL){fprintf(stderr,"Erroropeningadapter");return-1;}}else{/*D

9、onotcheckfortheswitchtype('-s')*/if((fp=pcap_open_live(argv[2],//nameofthedevice65536,//portionofthepackettocapture.//65536grantsthatthewholepacketwillbecapturedonalltheMACs.1,//promiscuousmode(nonzeromeanspromiscuous)1000,//readtimeouterrbuf

当前文档最多预览五页,下载文档查看全文

此文档下载收益归作者所有

当前文档最多预览五页,下载文档查看全文
温馨提示:
1. 部分包含数学公式或PPT动画的文件,查看预览时可能会显示错乱或异常,文件下载后无此问题,请放心下载。
2. 本文档由用户上传,版权归属用户,天天文库负责整理代发布。如果您对本文档版权有争议请及时联系客服。
3. 下载前请仔细阅读文档内容,确认文档内容符合您的需求后进行下载,若出现内容与标题不符可向本站投诉处理。
4. 下载文档时可能由于网络波动等原因无法下载或下载错误,付费完成后未能成功下载的用户请联系客服处理。