Ping程序开发设计文档(范例)

  1. 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
  2. 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
  3. 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。

课程实验开发文档

题目Ping程序设计和实现

所在院系计算机与通信学院

专业班级

学生姓名

学生学号

指导老师

实验所在课程计算机互联网与TCP/IP

200年月

第一部分、Ping 的原理概述(实验目的)TCP/IP协议提供工具帮助管理员或用户识别网络问题。其中最常用的调试工具就是使用ICMP的回送请求(Echo request)和回送应答(Echo reply)。其原理主要是主机或路由器向指定目的站发送回送请求报文。收到回送请求报文的目的站的机器形成一个回送应答,并把它返还给最初的发送者。回送请求包含一个可选数据区;应答包含了在请求中所发送数据的一分副本。回送请求及其关联的应答可用来测试目的站是否可达和是否响应。因为请求

和应答都是在IP数据报中传输的,所以应答的成功接收就证实传输系统的主要部分是正常的。在DOS和WINDOWS操作系统中已经附带了一个实现这种功能的程序Ping,本次实验的目的就是要在熟练掌握Ping的工作原理的情况下试着自己编一个能实现类似功能的程序,以验证我们对于TCP/IP协议和ICMP协议的熟练掌握程度。

第二部分、Ping 原理的具体实现(实验过程)

这个实验我是采用MFC类库来编写Ping程序的,源程序如下:

/ MfcPing.cpp : Defines the class behaviors for the application.

//

#include "stdafx.h"

#include "MfcPing.h"

#include "MfcPingDlg.h"

#ifdef _DEBUG

#define new DEBUG_NEW

#undef THIS_FILE

static char THIS_FILE[] = __FILE__;

#endif

/////////////////////////////////////////////////////////////////////////////

// CMfcPingApp

BEGIN_MESSAGE_MAP(CMfcPingApp, CWinApp)

//{{AFX_MSG_MAP(CMfcPingApp)

// NOTE - the ClassWizard will add and remove mapping macros here.

// DO NOT EDIT what you see in these blocks of generated code!

//}}AFX_MSG

ON_COMMAND(ID_HELP, CWinApp::OnHelp)

END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////

// CMfcPingApp construction

CMfcPingApp::CMfcPingApp()

{

// TODO: add construction code here,

// Place all significant initialization in InitInstance

}

/////////////////////////////////////////////////////////////////////////////

// The one and only CMfcPingApp object

CMfcPingApp theApp;

/////////////////////////////////////////////////////////////////////////////

// CMfcPingApp initializat

BOOL CMfcPingApp::InitInstance()

{

if (!AfxSocketInit())

{

AfxMessageBox(IDP_SOCKETS_INIT_FAILED);

return FALSE;

}

AfxEnableControlContainer();

// Standard initialization

// If you are not using these features and wish to reduce the size

// of your final executable, you should remove from the following

// the specific initialization routines you do not need.

#ifdef _AFXDLL

Enable3dControls(); // Call this when using MFC in a shared DLL #else

Enable3dControlsStatic(); // Call this when linking to MFC statically

#endif

CMfcPingDlg dlg;

m_pMainWnd = &dlg;

int nResponse = dlg.DoModal();

if (nResponse == IDOK)

{

// TODO: Place code here to handle when the dialog is

// dismissed with OK

}

else if (nResponse == IDCANCEL)

{

// TODO: Place code here to handle when the dialog is

// dismissed with Cancel

}

// Since the dialog has been closed, return FALSE so that we exit the

// application, rather than start the application's message pump.

return FALSE;

}

程序在编译连接后生成MFCPing. Exe,试着执行该程序,得到如下一些结果:

相关文档
最新文档