简单路由器设计与实现Word文件下载.doc

上传人:b****9 文档编号:13044821 上传时间:2022-10-03 格式:DOC 页数:38 大小:1.40MB
下载 相关 举报
简单路由器设计与实现Word文件下载.doc_第1页
第1页 / 共38页
简单路由器设计与实现Word文件下载.doc_第2页
第2页 / 共38页
简单路由器设计与实现Word文件下载.doc_第3页
第3页 / 共38页
简单路由器设计与实现Word文件下载.doc_第4页
第4页 / 共38页
简单路由器设计与实现Word文件下载.doc_第5页
第5页 / 共38页
点击查看更多>>
下载资源
资源描述

简单路由器设计与实现Word文件下载.doc

《简单路由器设计与实现Word文件下载.doc》由会员分享,可在线阅读,更多相关《简单路由器设计与实现Word文件下载.doc(38页珍藏版)》请在冰豆网上搜索。

简单路由器设计与实现Word文件下载.doc

推荐开发工具:

VisualStudio2010;

推荐编程语言:

C++/VisualC++;

函数库/开发包:

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的分组,使得两个子网中的主机能够互相访问

图5-1实验验证环境配置示意图

4.实验方式

每位同学独立上机编程实验,实验指导教师现场指导。

5.参考内容

(1)WinPcap简介

Winpcap(windowspacketcapture)是windows平台下一个免费、公共的网络访问系统。

开发Winpcap项目的目的在于为win32应用程序提供访问网络底层的能力。

它用于windows系统下的直接的网络编程。

关于Winpcap的介绍请参阅

Winpcap开发包可以在http:

//www.winpcap.org/上下载,Winpcap的技术文档可以从http:

//www.winpcap.org/docs/default.htm下载。

附录中给出了主要函数的说明文档。

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

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

(1).intpcap_findalldevs_ex(char*source,structpcap_rmtauth*auth,pcap_if_t**alldevs,char*errbuf)

函数功能:

Createalistofnetworkdevicesthatcanbeopenedwith 

pcap_open().

参数说明:

source:

achar*bufferthatkeepsthe'

sourcelocaltion'

accordingtothenewWinPcapsyntax.Thissourcewillbeexaminedlookingforadapters(localorremote)orpcapfiles,Thestringsthatmustbeprependedtothe'

source'

inordertodefineifwewantlocal/remoteadaptersorfilesisdefinedinthenewSourceSpecificationSyntax.

auth:

apointertoapcap_rmtauthstructure.ThispointerkeepstheinformationrequiredtoauthenticatetheRPCAPconnectiontotheremotehost.Thisparameterisnotmeaningfulincaseofaquerytothelocalhost:

inthatcaseitcanbeNULL.

alldevs:

a'

structpcap_if_t'

pointer,whichwillbeproperlyallocatedinsidethisfunction.Whenthefunctionreturns,itissettopointtothefirstelementoftheinterfacelist;

eachelementofthelistisoftype'

.

errbuf:

apointertoauser-allocatedbuffer(ofsizePCAP_ERRBUF_SIZE)thatwillcontaintheerrormessage(incasethereisone).

返回值:

'

0'

ifeverythingisfine,'

-1'

ifsomeerrorsoccurred.Thelistofthedevicesisreturnedinthe'

alldevs'

variable.Whenthefunctionreturnscorrectly,'

cannotbeNULL.Inotherwords,thisfunctionreturns'

alsoincasethesystemdoesnothaveanyinterfacetolist.

(2).voidpcap_freealldevs_ex(pcap_if_t*alldevsp)

函数功能:

Freeaninterfacelistreturnedbypcap_findalldevs().

(3).pcap_t*pcap_open(constchar*source,intsnaplen,intflags,intread_timeout,structpcap_rmtauth*auth,char*errbuf)

Openagenericsourceinordertocapture/send(WinPcaponly)traffic.

zero-terminatedstringcontainingthesourcenametoopen.ThesourcenamehastoincludetheformatprefixaccordingtothenewSourceSpecificationSyntaxanditcannotbeNULL.OnonLinuxsystemswith2.2orlaterkernels,adeviceargumentof"

any"

canbeusedtocapturepacketsfromallinterfaces.Inordertomakesthesourcesyntaxeasier,pleaserememberthat:

theadaptersreturnedbythepcap_findalldevs_ex()canbeusedimmediatelybythepcap_open()incasetheuserwantstopassitsownsourcestringtothepcap_open(),thepcap_createsrcstr()helpsincreatingthecorrectsourceidentifier.

snaplen:

lengthofthepacketthathastoberetained.Foreachpacketreceivedbythefilter,onlythefirst'

snaplen'

bytesarestoredinthebufferandpassedtotheuserapplication.Forinstance,snaplenequalto100meansthatonlythefirst100bytesofeachpacketarestored.

flags:

keepsseveralflagsthatcanbeneededforcapturingpackets.Theallowedflagsaredefinedinthepcap_open()flags.

read_timeout:

readtimeoutinmilliseconds.Thereadtimeoutisusedtoarrangethatthereadnotnecessarilyreturnimmediatelywhenapacketisseen,butthatitwaitsforsomeamountoftimetoallowmorepacketstoarriveandtoreadmultiplepacketsfromtheOSkernelinoneoperation.Notallplatformssupportareadtimeout;

onplatformsthatdon'

t,thereadtimeoutisignored.

apointertoa'

structpcap_rmtauth'

thatkeepstheinformationrequiredtoauthenticatetheuseronaremotemachine.Incasethisisnotaremotecapture,thispointercanbesettoNULL.

apointertoauser-allocatedbufferwhichwillcontaintheerrorincasethisfunctionfails.Thepcap_open()andfindalldevs()aretheonlytwofunctionswhichhavethisparameter,sincetheydonothave(yet)apointertoapcap_tstructure,whichreservesspacefortheerrorstring.Sincethesefunctionsdonothave(yet)apcap_tpointer(thepcap_tpointerisNULLincaseoferrors),theyneedanexpl

展开阅读全文
相关资源
猜你喜欢
相关搜索

当前位置:首页 > 求职职场 > 简历

copyright@ 2008-2022 冰豆网网站版权所有

经营许可证编号:鄂ICP备2022015515号-1