解析ARP数据包课程设计

上传人:gu****n 文档编号:53510118 上传时间:2022-02-10 格式:DOC 页数:18 大小:98.50KB
收藏 版权申诉 举报 下载
解析ARP数据包课程设计_第1页
第1页 / 共18页
解析ARP数据包课程设计_第2页
第2页 / 共18页
解析ARP数据包课程设计_第3页
第3页 / 共18页
资源描述:

《解析ARP数据包课程设计》由会员分享,可在线阅读,更多相关《解析ARP数据包课程设计(18页珍藏版)》请在装配图网上搜索。

1、yuan, an increase of 17.5%; local government general budget revenue of 500 million Yuan, . Painting, model culture creates new Ma Church community, creating Lake scenic spot culture education base, received high evaluation from provincial and municipal discipline Inspection Commission, the peoples d

2、aily special report. Constantly promote independent Commission against corruption culture construction to rural extends, created established Dahlin rural industry Park independent Commission against corruption culture positions, formed has a support service low double excellent of members lead team,

3、 constantly perfect and established Park funds assets management, and village audit supervision, and villagers democratic financial, system, strengthening Park party, and Chief, and financial, full public, powerful to guarantees has new rural construction, by city rural style clean government inspec

4、tion unit led of height evaluation. Through the implementation of honest and clean government cultural construction, and effectively educate the broad masses of party members and cadres and consciously regulated behavior and discipline, honesty in politics and culture to create a good atmosphere and

5、 fresh development environment. Although we in implement implementation independent Commission against corruption guidelines aspects made has must effectiveness, but away from superior of requirements also exists must of distance, main performance for: a is system enough sound, education, and superv

6、ision, and prevention, and punishment, aspects long-term mechanism also enough perfect, especially in enrollment bid work regulatory aspects also needed strengthening; II is regulatory supervision exists lost of Yu wide, and lost of Yu soft, investigation illegal disciplinary case of efforts also ne

7、eded strengthening, individual sector and cadres also different degree exists treat gift, not to benefits not do, and mess do of phenomenon; Three for honest work is the new situations and new problems in finding timely enough, treatment measures are not strong enough. To solve these problems, we wi

8、ll proceed from the following five aspects of rectification, make sure to implement the provisions of the code. (A) deepening the learning, enhance the consciousness of honesty in politics. To create event as an opportunity to Excel and learning party, further increasing the governance capability an

9、d advanced construction, reinforced rules of the broad masses of party members and cadres awareness, sense of responsibility, sense of honor, improve working ability and level of scientific development. Should make full use of meetings, in particular central group learning opportunity, further stren

10、gthening the study and education of the code, the intensive warning education, education the majority of party members and cadres known fear, knew fear, honesty in politics of tension the strings, consciousness and enhancing the implementation of the initiative. Also, pay attention to apply what the

11、y have learned, consciously study results into planning work, new ideas,南京工程学院 算通081 周洁 南京工程学院(课程设计)院系:通信工程学院课程名称:计算机网络与通信 设计名称:解析ARP数据包 班级:算通081班 姓名:周洁 学号:208080311设计时间:2011年06月13日2011年06月16日目录1. 课程设计目的22. 课程设计要求23. 相关知识31) ARP数据报的消息格式32) ARP协议的工作流程.44. 课程设计分析.61) 课程设计中的重点及难点.62) 参考算法.73) 核心代码.85.

12、相关扩展156. 心得体会167. 参考文献17一、 课程设计目的: 本课程设计的目的是对网络上的ARP数据包进行解析,从而熟悉ARP数据包的结构,对ARP协议有更好的理解和认识。二、 课程设计要求: 通过编制程序,获取网络中的ARP数据包,解析数据包的内容,将结果显示在标准输出上,并同时写入日志文件。程序的具体要求如下所示:1,以命令行的形式运行,如下所示:11ARP其中,11ARP为程序名;11为日志文件名。,程序输出内容如下所示: 源地址 源地址 目的地址 操作时间各部分的说明如下所示: 源IP地址:输出ARP消息格式中的源IP地址字段;源MAC地址:输出ARP消息格式中的源物理地址字段

13、;目的IP地址:输出ARP消息格式中的目的IP地址字段;目的MAC地址:输出ARP消息格式中的目的物理地址字段; 操作:输出ARP消息格式中的操作字段,若为ARP请求, 则为1,若为ARP应答,则为2;时间:该ARP包产生的时间。3,当程序接收到键盘输入Ctrl+C时字段三、 相关知识a) ARP数据报的消息格式 网络上的每台主机或设备都有一个或多个IP地址。IP地址是网络层的地址,在网络层,数据被组装成IP包。但是发送IP包需要物理设备的支持(通常是Ethernet设备,在本课程设计中我们指定为Ethernet设备),即发送端必须知道目的物理地址才能将IP包发送出去,所以需要一种将IP地址映

14、射为物理地址的机制。ARP协议就是用来完成这个任务的。ARP协议能够在同一个物理网络中,在给定目的主机或设备的IP地址的条件下,得到目的主机或设备的物理地址。ARP协议的数据包格式如图所示: 0 8 16 24 31(位) 硬件类型 协议类型物理地址长度协议地址长度 操作 源物理地址(八位组03) 源物理地址(八位组45) 源IP地址(八位组01) 源IP地址(八位组23) 目的物理地址(八位组01) 目的物理地址(八位组25) 目的IP地址(八位组03)ARP数据包的消息格式下面对数据包的各个部分进行说明l 硬件类型:指定硬件接口类型。例如,值为1表示Ethernetl 协议类型:指定发送方

15、支持的上层协议的类型l 物理地址长度:指定物理(硬件)地址的长度l 协议地址长度:网络层协议的地址长度。若为IP协议,其值为4l 操作:指定ARP的操作类型,例如,1表示ARP请求,2表示ARP应答l 源物理地址:指定发送方的IP地址l 目的物理地址:指定目的物理地址。l 目的IP地址:指定目的IP地址ARP分组必须在数据链路层中被封装成侦,才能发送出去封装形式如图所示ARP消息帧头部 帧数据 将ARP数据包封装成一个帧b)ARP协议的工作流程。1) 在发送一个ARP分组之前,源主机首先根据目的IP地址,在本地ARP高速缓存表中查找与之对应的目的物理地址。如果找到对应的物理地址,就不用进行地址

16、解析,否则需要进行地址解析。2) 实现地址解析的第一步是产生ARP请求分组。在相应的字段写入本地主机的源物理地址、源IP地址,在目的物理地址字段写入0,并在操作字段写入1。3) 将ARP分组发送到本地的数据链路层,并封装成帧。以源物理地址作为源地址,以物理广播地址(FF-FF-FF-FF-FF-FF)作为目的地址,通过物理层发送出去。4) 由于采用了广播地址,因此网段内所有的主机或设备都能接受到该帧。除了目的主机外,所有接受到该分组的主机和设备都会丢弃该分组,因为目的主机能够识别ARP消息中的目的IP地址。5) 目的主机发送ARP应答分组。在ARP应答分组中,以请求分组中源物理地址、源IP地址

17、作为其目的物理地址、目的IP地址,并将目的主机自身的物理地址、IP地址填入应答分组的源物理地址、源IP地址字段,并在操作字段中写入2。该分组通过数据链路层以点对点的方式发送出去(因为现在目的方已经知道双方的物理地址)。6) 源结点接收到ARP应答分组,知道对应于目的IP地址的目的物理地址,将它作为一条新记录加入到ARP高速缓存表。7) 源结点将有完整源IP地址、源物理地址、目的IP地址、目的物理地址的信息和数据作为一个发送分组,传送给它的数据链路层并封装成桢,然后以点对点的方式发送到目的主机。四、课程设计分析1. 课程设计中的重点及难点1) 程序中会用到Winpcap,Winpcap是Win3

18、2环境下数据包捕获的开放代码函数库。基于Winpcap的应用程序一般按照下面几个步骤进行设计:l 输出网卡设备列表。l 选择网卡并打开。l 捕获数据包时,可能需要设置过滤器。l 捕获数据包或者发送数据包。2) 在程序设计过程中需要注意网络主机字节顺序的转化。由于不同的计算机系统所采用的数据表示方式不同,对于2B或4B的数据,有的采用低字节地址存放数据的高权值位,而有的却以低地址字节存放数据低权位值,在网络的数据传输中,我们应该统一表示,所以我们在捕获数据包后,应将数据包头部的表示长度或类型的数据转换成本地机的表达形式。可以利用函数ntohs()将网络字节序转换为主机字节序。3) 选择网卡并打开

19、时,注意选择可用的网卡。2. 参考算法1) 取得当前网卡设备列表。2) 选择Ethernet网卡并打开,注意判断所选网卡是否为实际存在的可用网卡。3) 设置过滤器,此处的过滤器正则表达式为“arp”或者“ether protoarp”。4) 捕获数据包并进行处理(包括输出各IP地址,物理地址,操作类型以及时间)。由于要记录日志文件,为了便于输出流参数,建议采用pcap_next_ex()函数。流程图如图所示:开始获取网卡列表选取Ethernet网卡打开网卡(混杂模式)编译设置过滤器捕获ARP包并将其相应内容输出3. 核心代码l ARP数据包结构struct arppkt unsigned sh

20、ort hdtyp; /硬件类型。值0001表示其为Ethernetunsigned short protyp; /协议类型。值0800表示上层协议为IPunsigned char hdsize; /硬件地址长度。值为06unsigned char prosize; /协议地址长度。值为04unsigned short op; /操作值为0001/0002,分别表示ARP请求/应答u_char smac6; /源MAC地址,6Bu_char sip4; /源IP地址,4Bu_char dmac6; /目的MAC地址u_char dip4; /目的IP地址;l 获取网络设备列表,并以混杂模式打开

21、网络设备/获取网络设备列表if(pcap_findalldevs(&alldevs,errbuf)=-1)coutError in pcap_findalldevs:next) /以混杂模式打开网卡,以接受所有的帧if(adhandle=pcap_open_live(d-name,1000,1,300,errbuf)=NULL)coutaddresses!=NULL)break;l 编译过滤器并设置过滤器,只捕获ARP数据包char packet_filter=”ether proto arp”; /过滤,选择arp协议if(pcap_compile(adhandle,&fcode,packe

22、t_filter,1,netmask)0) coutnUnable to compile the packet filter.Check the syntax.n; pcap_freealldevs(alldevs); return;/设置过滤器if(pcap_setfilter(adhandle,&fcode)0) cout=0) 输出ARP数据包的各个域的内容到文件和屏幕上 l 源程序#include#pragma comment(lib,Ws2_32.lib) /用到ntobs()/等同于点击project-setting-link打开object/library module编辑框后加

23、入文件#pragma comment(lib,wpcap.lib)#include pcap.h /此头文件没有包含在VC中,需要另外加入#include#include /格式化输出需要用到#include /用到_getch() /注意到接收的数据包头中代表类型,数据长度的字段采用的是big-endian /所以对于2B/4B的数据要用ntohs()转换为本机形式 /ARP包结构struct arppktunsigned short hdtyp; /硬件类型.值0001unsigned short protyp;unsigned char hdsize;unsigned char pros

24、ize;unsigned short op;u_char smac6;u_char sip4;u_char dmac6;u_char dip4;void packet_handler(const pcap_pkthdr *header,const u_char *pkt_data,ostream& out);void main(int argc,char *argv )if(argc!=2)coutUsage:arpparse logfilenameendl;coutpress any key to continue.endl;_getch();return;pcap_if_t *alldev

25、s;pcap_if_t *d;pcap_t *adhandle;char errbufPCAP_ERRBUF_SIZE;u_int netmask;char packet_filter=ether proto arp;struct bpf_program fcode;struct pcap_pkthdr *header;const u_char *pkt_data;if(pcap_findalldevs(&alldevs,errbuf)=-1)coutError in pcap_findalldevs:next) if(adhandle=pcap_open_live(d-name,1000,1

26、,300,errbuf)=NULL)coutaddressess!=NULL)break;if(d=NULL) coutnetmask)-sin_addr.s_un.s_addr;/编译过滤器,只捕获ARP包if(pcap_compile(adhandle,&fcode,packet_filter,1,netmask)0) coutnUnable to compile the packet filter.Check the syntax.n; pcap_freealldevs(alldevs); return;/设置过滤器if(pcap_setfilter(ashandle,&fcode)0)

27、 coutnError setting the filter.n; pcap_freealldevs(alldevs); return;coutttlistening on description.endlendl;/显示提示信息及每项含义ofstream fout(argv1,ios:app); /日志记录文件/为了查看日志时的方便,其中加入了日期记录time_t t;time(&t);fout.seekp(0,ios:end);if(fout.tellp()!=0) foutendl;foutttARP request(1)/reply(2) onctime(&t);coutSour Ip

28、 Addr Sour MAC Address Des Ip Addr Des MAC Address OP Timeendl;foutSour Ip Addr Sour MAC Address Des Ip Addr Des MAC Address OP Time=0) if(result=0) continue; packer_handler(header,pkt_data,cout); packet_handler(header,pkt_data,fout);void packet_handler(const pcap_pkthdr *header,const u_char *pkt_da

29、ta,ostream& out) arpkt* arph = (arppkt *)(pkt_data +14); for(int i=0;i3;i+) outsipi).; out.setf(ios:left); outsetw(3)sip3) ; out.unsetf(ios:uppercase); for(i=0;i5;i+) outhexsetw(2)smaci)-; outhexsetw(2)smac5) ; out.fill(oldfillchar); out.unsetf(ios:hex|ios:uppercase); for(i=0;i3;i+) outdip3).;out.un

30、setf(ios:left);/输出目的MAC地址out.fill(0);out.setf(ios:uppercase);for(i=0;i5;i+) outhexsetw(2)dmaci)-;out.fill(oldfillchar);out.unsetf(ios:hex|ios:uppercase);outop)ts.tv_sec);out.fill(0);outtm_hour:setw(2)tm_min:setw(2)tm_sec;out.fill(oldfillchar);outether_type)=0x0806) &(ntohs(arp_header-ar_hrd)=0x0001)

31、 &(ntohs(arp_header-ar_pro)=0x0800) &(arp_header-ar_hln=0x06)&(arp_header-ar_pln=0x04)&( (ntohs(arp_header-ar_op)=0x01)| (ntohs(arp_header-ar_op)=0x02) 对ARP数据包进行分析并打印5) 算法在3、4步之间进行循环,直到强行退出为止。六、心得体会本次课程设计,完成了在xp环境下的解析ARP数据包。在具体实现获取网络中的ARP数据包解析数据包的内容,并将其写入日志文件的过程中,是我更加清楚物理地址、IP地址的关联,源地址与目的地址的关系,以及二者对

32、数据类型的格式要求。最重要的是通过这次的实际训练让我对ARP协议更加理解。本次课程设计查阅了大量的案例,学到了很多知识,使我对计算机网络有了更深入的了解。我觉得这次课程设计我觉得收获挺大的。之前的学习仅限于书本,网络的很多东西都只知道其然而不知道其所以然。在这次课程设计中,也遇到了很多的难题,如:在开始查找资料并编写程序时,需用到Wincap软件,且要对它进行正确的安装。把Wincap文件中的Include和Lib里的全部文件分别复制到安装VC+的位置中的Include和Lib中。课程设计是培养我们综合运用所学知识,发现、提出、分析和解决实际问题,锻炼实践能力的重要环节,是对我们实际工作能力的

33、具体训练和考察过程。随着科学技术发展的日新月异,网络已经成为当今计算机发展中空前活跃的领域,在生活中可以说是无处不在,因此作为二十一世纪的计算机专业的大学生来说掌握网络组网技术是十分重要的。七、参考资料1. 谢希人著. 计算机网络(第四版)大连理工大学出版社20032. 宋凯等著. 计算机网络. 北京:清华大学出版社 20103. 吴功宜等著. 计算机网络课程设计. 北京:机械工业出版社2005.94. 李爱华等著. 面向对象程序设计(C+语言). 北京:清华大学出版社2010new measures to promote work, the courage to take responsib

34、ility, dare to break hard to ensure district, Government decisions and arrangements to implement. (B) strengthening supervision, severely punish acts of violation. One is to open the channels of supervision. Vigorously promote the party affairs public, open, widely accepted supervision by the masses

35、, pay attention to social groups and public opinion supervision, the powerful force formed to urge party members and leading cadres properly exercise their powers. Second, strong supervision and inspection. Democratic life into full play, important briefings, reports related to personal matters and

36、evaluation of cadres study of inner-party supervisory system, a comprehensive grasp of guidelines for the implementation of the independent Commission against corruption-related cases of leading cadres of party members, focus on strengthening key areas of project selection, funding, officials monito

37、r, detect and rectify the problem, promote honesty in politics. Third, strengthen disciplinary investigation. Seriously the implementation of JI .Recently, the County leading bodies at the county level to carry out three trees practice, which is to improve the governing ability and promoting the dev

38、elopment of XX effective measure. I carefully follow your deployment requirements, and actively participate in the three trees campaign. Read Group, prepared by the Department in the near future of the ideological and political construction of leading cadres in the city reader, read the relevant inf

39、ormation, larger harvest, inspired. I think the ability of repelling is to strengthen the partys governing capacity in questions of the construction of meaning, an important topic remains in front of party members and cadres at all levels, we need to further explore and ponder. The ability of repell

40、ing the name suggests, is asking party members and cadres at all levels in particular, leading cadres at all levels, not only ourselves, establish a correct concept of the independent Commission against corruption, political integrity, self-discipline, rejection of corruption, made for the people, p

41、ragmatic, honest leadership, and strengthen the sense of responsibility, earnestly implement the responsibility of uncorrupted, implementation of the baolian anti-corruption measures to ensure the realization of business-building, construction of a win-win situation. Next, I combined with their thin

42、king, experience and contact XX practical, on how to enhance the ability of repelling, on four aspects of cognition. Irregularities, please comment. First, the construction of the propulsion system, and enhance the system of corruption since the founding of our party, have been thinking about tackli

43、ng corruption. Currently, democratic legal system, management system and supervision mechanism is not perfect, administrative acts are not very standardized, Enterprise behavior and market behavior, corruption presents a diverse, pluralistic, complex trends, this shift the struggle between the two, will accompany17

展开阅读全文
温馨提示:
1: 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
2: 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
3.本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
5. 装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
关于我们 - 网站声明 - 网站地图 - 资源地图 - 友情链接 - 网站客服 - 联系我们

copyright@ 2023-2025  zhuangpeitu.com 装配图网版权所有   联系电话:18123376007

备案号:ICP2024067431-1 川公网安备51140202000466号


本站为文档C2C交易模式,即用户上传的文档直接被用户下载,本站只是中间服务平台,本站所有文档下载所得的收益归上传人(含作者)所有。装配图网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对上载内容本身不做任何修改或编辑。若文档所含内容侵犯了您的版权或隐私,请立即通知装配图网,我们立即给予删除!