网络流量测量软件的设计与实现摘要:为了方便网络编程,90年代初,由Microsoft联合了其他几家公司共同制定了一套WINDOWS下的网络编程接口,即WindowsSockets规范,它不是一种网络协议,而是一套开放的、支持多种协议的Windows下的网络编程接口。本篇论文主要是介绍了在TCP/IP基础上利用winsock2对网卡进行编程,以达到网络流量监测的目的。论文首先介绍了TCP/IP协议,旨在介绍IP,TCP,UDP等比较重要的协议。主要是介绍IP头,TCP头,UDP头的特点,以便从IP头中可以获取源地址,目的地址,协议类型等信息。在随后的章节中提出了Socket的概念,Socket实际上提供了一个通信端口使所有拥有Socket的端口的计算机之间能够相互通信,在本论文中主要说明了socket的建立,监听和撤销的过程。具体到程序实现中,对网卡混杂模式的设置是通过原始套接字(rawsocket)来实现的。为了让原始套接字能接受所有的数据,还需要通过将SOCK_RAW设置成SIO_RCVALL。对数据包的获取通过recv()函数来完成。最后要完成的工作就是对所捕获的IP数据包进行分析以提取出我们所需要的信息。在论文的最后是旨在说明进一步工作的展开。关键字:TCP/IP,Winsock,原始套接字,NetBiosAbstract:Forconvenienceofnetworkprogramming,intheearly1990s,anewsetofnetworkprogramminginterfaceusingunderWINDOWSwasestablishedbysomecompaniesunitedbyMicrosoft.ItisknownasWindowsSocketNorm.Itisn'takindofnetworkprotocol,butanopennetworkprogramminginterfacesupportmultipleprotocolsunderWINDOWS.ThemainpurposeofthethesisistointroducehowtouseWinsock2programonnetworkadapterundertheprotocolofTCP/IP.Thisisforthepurposeofmeasurethenetworkdischarge.Atthebeginningofthethesis,weintroduceallimportantprotocolsofTCP/IP,likeIP,TCP,andUDP.WeintroduceIPheader,TCPheaderandUDPheaderforthemostimportantbecauseweneedacquiretheinformationofsourceaddress,destinationaddress,andprotocoltypefromtheIPheader.Inthefollowingsection,wegivetheconceptofSocket.SocketsactuallyprovideacommunicationporttoallowallthecomputersthathaveSocketporttocommunicatewitheachother.Inthethesis,wetalkontheprocessoftheSocket’sbuildinglisteningandcanceling.Intheprogram,weuseRAWSockettosetadapteronthemixedmode.TolettheSocketreceivealldata,wealsoneedtosettheonSIO_RCVALL.Thenweusethefunctionrecv()togetdatapack.Atlastweneedanalyzethedatapacktogettheinformationweneed.KEYWORDS:TCP/IP,Winsock,RAWSOCKET,NetBIOS目录摘要…………………………………………………………………….1Abstract………………………………………………………..2前言…………………………………………………………………….4第一章绪论……………………………………………………………51.1TCP/IP协议及其协议分析方法……………………………….51.1.1分层…………………………………………………………..51.1.2IP地址……………………………………………………….61.1.3端口…………………………………………………………..61.1.4TCP/IP协议在Windows中的实现………………………….71.2Winsock编程…………………………………………………...71.3网络流量测量的程序实现原理………………………………..8第二章TCP/IP协议集………………………………………………92.1TCP/IP协议简介……………………………………………….92.2IP协议………………………………………………………….92.3TCP协议………………………………………………………..102.3.1TCP服务模型………………………………………………..102.3.2TCP数据段头………………………………………………..112.3.3TCP协议的建立……………………………………………..122.4UDP协议………………………………………………………..13第三章WINSOCK编程概述…………………………………………143.1套接字的概念………………………………………………….143.2套接字的种类...