《计算机网络》实验指导书(软件学院2015) - 图文 联系客服

发布时间 : 星期四 文章《计算机网络》实验指导书(软件学院2015) - 图文更新完毕开始阅读ca79e137ec630b1c59eef8c75fbfc77da26997fc

《计算机网络》实验指导书

实验5:简单路由器设计与实现(选做)

1.实验目的

熟悉并掌握路由器的工作原理;熟悉Winpcap编程,掌握数据包捕获与发送的方法;在理解IP协议、ICMP协议与路由基本工作原理的基础上,完成一个(软件)路由器基本功能的设计与编程实现。 2.实验环境

? 接入局域网的PC机;

? 操作系统:Windows xp, Windows 7等; ? 推荐开发工具:Visual Studio 2010; ? 推荐编程语言:C++/ Visual C++; ? 函数库/开发包:Winpcap。 3.实验内容

(1) 学习并掌握winpcap编程:自行完成WinPcap教程中的内容,从而掌握winpcap编程。内容包括但不限于:

a) 获取设备列表;

b) 打开一个适配器并抓包(分组); c) 解析分组; d) 发送分组;

学习内容及源程序参见WinPcap官方教程:

http://www.winpcap.org/docs/docs_412/html/group_wpcap_tut.html。 (2) 利用winpcap开发包实现简单路由程序,该路由程序应该至少包括以下功能:

a) IP数据包捕获和转发; b) ARP请求与解析;

c) 重新计算IP数据包的头部校验和;

d) 处理IP数据包的头部校验和;处理IP数据包的TTL值; e) 静态路由表维护。

在下图所示的完了过拓扑结构中,当所开发的路由器程序部署并运行在计算机C上时,它将(作为一个路由器)能够连通两个子网,正确地捕获、转发来自计算机A和计算机B的分组,使得两个子网中的主机能够互相访问

49

《计算机网络》实验指导书

192.168.1.9210.10.1.10计算机C该机器设置为双IP:192.168.1.4410.10.1.44计算机A默认网关设为:192.168.1.44计算机B默认网关设为:10.10.1.44图5-1 实

验验证环境配置示意图

4.实验方式

每位同学独立上机编程实验,实验指导教师现场指导。 5.参考内容

(1) WinPcap简介

Winpcap (windows packet capture)是windows平台下一个免费、公共的网络访问系统。开发Winpcap项目的目的在于为win32应用程序提供访问网络底层的能力。它用于windows系统下的直接的网络编程。关于Winpcap的介绍请参阅

http://baike.http://www.china-audit.com//link?url=rQt7NLzLCFGDO8Fd2XoM3yMvpqRhA4NU6xjLdWtoS_JkMLVfgQ9mspXhMceA5RVYIl9CnA2w66uEPrSlUXKq3_。

Winpcap开发包可以在http://www.winpcap.org/上下载,Winpcap的技术文档可以从http://www.winpcap.org/docs/default.htm下载。附录中给出了主要函数的说明文档。

(2) Winpcap主要函数及功能介绍

Winpcap部分主要函数及其功能介绍如下:

(1).int pcap_findalldevs_ex(char * source, struct pcap_rmtauth * auth, pcap_if_t ** alldevs, char * errbuf)

函数功能:

Create a list of network devices that can be opened with pcap_open(). 参数说明:

source:a char* buffer that keeps the 'source localtion', according to the new WinPcap syntax. This source will be examined looking for adapters (local or remote) or pcap files,The strings that must be prepended to the 'source' in order to define if we want local/remote adapters or files is defined in the new Source Specification Syntax .

auth:a pointer to a pcap_rmtauth structure. This pointer keeps the information required to authenticate the RPCAP connection to the remote host. This parameter is not meaningful in case of a query to the local host: in that case it can be NULL.

alldevs:a 'struct pcap_if_t' pointer, which will be properly allocated inside this function.

50