网络编程课程报告.docx
上传人:qw****27 上传时间:2024-09-12 格式:DOCX 页数:12 大小:234KB 金币:15 举报 版权申诉
预览加载中,请您耐心等待几秒...

网络编程课程报告.docx

网络编程课程报告.docx

预览

免费试读已结束,剩余 2 页请下载文档后查看

15 金币

下载此文档

如果您无法下载资料,请参考说明:

1、部分资料下载需要金币,请确保您的账户上有足够的金币

2、已购买过的文档,再次下载不重复扣费

3、资料包下载后请先用软件解压,在使用对应软件打开

一、设计描述该设计通过ControlList控件实现网络抓包的ip头部的展现,每个包头部各个部分为一行,包括版本号、头部长度、服务类型、总长度、标示符、片偏移、生存周期、协议、首部检验和、源IP地址、目的IP地址。抓到一个包提取IP头部各个部分插入,实现了对数据包头部分析。当点击ControlList数据行时,自动提取点击所在行的IP数据部分的详细信息即IP上层协议头部信息,显示在下面的编辑框中。程序完成后如图1所示。(图1)二、设计分析1.执行VC程序,选择FileNew命令,弹出New对话框,单击工程标签,转到工程选项卡,选择MFCAppWizard(exe),然后在工程名称文本框中输入“CATCHBAG”,单击确定后在弹出的MFC应用程序向导中选择基本对话框(图2)2.点击完成进行编程。3.进行编程时还需将“启动键”、“停止键”、“列表框”以及“文本编辑框”等的属性进行设置。3.1、启动键的属性修改如下图。3.2、停止键的属性修改如下图。3.3、列表框的属性修改如下图。3.4.文本编辑框的属性修改如下图。4、属性修改完后按Ctrl+W进入MFCClassWizard的MessageMaps为锁所增添的文件添加映射,然后再MemberVariables中设置如下图5、程序的最终运行效果如下图所示。三、源代码1,IP头部、TCP头部、UDP头部、ICMP头部结构定义与pack类声明:typedefstructipheader{unsignedcharip_hl:4;/*headerlength(报头长度)*/unsignedcharip_v:4;/*version(版本)*/unsignedcharip_tos;/*typeosservice服务类型*/unsignedshortintip_len;/*totallength(总长度)*/unsignedshortintip_id;/*identification(标识符)*/unsignedshortintip_off;/*fragmentoffsetfield(段移位域)*/unsignedcharip_ttl;/*timetolive(生存时间)*/unsignedcharip_p;/*protocol(协议)*/unsignedshortintip_sum;/*checksum(校验和)*/unsignedintip_src;/*sourceaddress(源地址)*/unsignedintip_dst;/*destinationaddress(目的地址)*/}ip_head;/*totalipheaderlength:20bytes(=160bits)*/typedefstructtcpheader{unsignedshortintsport;/*sourceport(源端口号)*/unsignedshortintdport;/*destinationport(目的端口号)*/unsignedintth_seq;/*sequencenumber(包的序列号)*/unsignedintth_ack;/*acknowledgementnumber(确认应答号)*/unsignedcharth_x:4;/*unused(未使用)*/unsignedcharth_off:4;/*dataoffset(数据偏移量)*/unsignedcharFlags;/*标志全*/unsignedshortintth_win;/*windows(窗口)*/unsignedshortintth_sum;/*checksum(校验和)*/unsignedshortintth_urp;/*urgentpointer(紧急指针)*/}TCP_HDR;typedefstructudphdr{unsignedshortsport;/*sourceport(源端口号)*/unsignedshortdport;/*destinationport(目的端口号)*/unsignedshortlen;/*udplength(udp长度)*/unsignedshortcksum;/*udpchecksum(udp校验和)*/}UDP_HDR;typedefstructicmphdr{unsignedshorticmp_type;/*ICMP类型*/unsignedsho