资源描述:
《计算机网络课程设计报告网络协议与应用程序设计》由会员上传分享,免费在线阅读,更多相关内容在工程资料-天天文库。
1、计算机网络课程设计报告课程设计项目名称:网络协议与应用程序设计系:专业:实验地点:实验日期:一、目的与要求基于典型的网络协议和网络应用的源代码进行分析,通过本科目,使学员了解网络通信流程,掌握网络通信程序的设计以及通信协议的应用技能,培养学员网络协议与网络应用的设计实现能力。二、实验环境VisualC++6.0三、程序设计3.1IP报头格式typedefstructtagIPINFOu-charTt1;u-charTos;u-charIPFlags;u-charOptSize;//TimeToLive//Type
2、OfService//IPflags//Sizeofoptionsdatau.charFAR*0ptions;//Optionsdatabuffer}IPINFO,*PIPINFO生存时间+服务类型+标识字段+数据报大小+数据报缓存区3.2ICMP报头格式typedefstructtagICMPECHOu.longSource;u.longStatus;//Sourceaddress//IPstatusu.longRTTime;//Roundtriptimeinmi11isecondsu.shortDataSiz
3、e;//Replydatasizeu.shortReserved;//UnknownvoidFAR*pData;//ReplydatabufferIPINFOiplnfo;//Replyoptions}ICMPECHO,*PICMPECHO;源地址+IP状态+往返延迟+返回数据大小+未知接受数据+返回数据缓存+返回IP报头数据函数流程设计//初始化模块:初始化全局标量,初始化加载库。voidmain(intargc,char**argv)ICMPECHOicmpEcho;//ICMPEchoreplybuffer
4、HANDLEhndllcmp;//LoadLibrary()handletoICMP.DLLHANDLEhndlFile;//HandleforIcmpCreateFile()LPHOSTENTpHost;//Pointertohostentrystructurestructin.addriaDest;//InternetaddressstructureDWORD*dwAddress;//IPAddressintnRet;//GeneralusereturncodeIPINFOiplnfo;//IPOptions
5、structureDWORDdwRet;//DWORDreturncodeintx;//Checkargumentsif(argc!=2)fprintf(stderr,HSyntax:pingiHostNameOrIPAddress");return;//DynamicallyloadtheICMP.DLLhndllcmp=LoadLibrary("ICMP.DLLn);if(hndllcmp==NULL){fprintf(stderr,nCouldnotloadICMP.DLLH);return
6、;}//RetrieveICMPfunctionpointerspIcmpCreateFile=(HANDLE(WINAPI*)(void))GetProcAddress(hndllcmp,"IcmpCreateFilen);pIcmpCloseHandle=(BOOL(WINAPI*)(HANDLE))GetProcAddress(hndllcmp,MIcmpCloseHandle1');pIcmpSendEcho=(DWORD(WINAPI*)(HANDLE,DWORD,LPVOID,WORD,PIPINFO
7、,LPVOID,DWORD,DWORD))GetProcAddress(hndllcmp,"IcmpSendEcho1');//Checkallthefunctionpointers//功能控制模块:计算校验和填充数据报文、释放占用资源。if(pIcmpCreateFile==NULL
8、pIcmpCloseHandle==NULLIIpIcmpSendEcho==NULL)fprintf(stderr,nErrorgettingICMPprocaddressM);FreeLibrary(hndlIcmp)
9、;return;}//InitWinSocknRet=WSAStartup(0x0101,SwsaData);if(nRet){fprintf(stderr,nWSAStartup()error:%dn,nRet);WSACleanup();FreeLibrary(hndlIcmp);return;}//CheckWinSockversionif(0x0101!=