网络流量测量软件的设计与实现摘 要:为了方便网络编程,90 年代初,由 Microsoft 联合了其他几家公 司 共 同 制 定 了 一 套 WINDOWS 下 的 网 络 编 程 接 口 , 即 Windows Sockets 规范,它不是一种网络协议,而是一套开放的、支持多种协议的 Windows 下的网络编程接口。本篇论文主要是介绍了在 TCP/IP 基础上利用 winsock2 对网卡进行编程,以达到网络流量监测的目的。论文首先介绍了 TCP/IP 协议,旨在介绍 IP,TCP,UDP 等比较重要的协议。主要是介绍 IP 头,TCP 头,UDP 头的特点,以便从 IP 头中可以获取源地址,目的地址,协议类型等信息。在随后的章节中提出了 Socket 的概念,Socket 实际上提供了一个通信端口使所有拥有 Socket 的端口的计算机之间能够相互通信,在本论文中主要说明了 socket 的建立,监听和撤销的过程。具体到程序实现中,对网卡混杂模式的设置是通过原始套接字(raw socket)来实现的。为了让原始套接字能接受所有的数据,还需要通过将 SOCK_RAW 设置成 SIO_RCVALL。对数据包的获取通过 recv()函数来完成。最后要完成的工作就是对所捕获的 IP数据包进行分析以提取出我们所需要的信息。在论文的最后是旨在说明进一步工作的展开。关键字: TCP/IP,Winsock,原始套接字,NetBios Abstract: For convenience of network programming, in the early 1990s, a new set of network programming interface using under WINDOWS was established by some companies united by Microsoft. It is known as Windows Socket Norm. It isn't a kind of network protocol, but an open network programming interface support multiple protocols under WINDOWS. The main purpose of the thesis is to introduce how to use Winsock2 program on network adapter under the protocol of TCP/IP. This is for the purpose of measure the network discharge. At the beginning of the thesis, we introduce all important protocols of TCP/IP, like IP, TCP, and UDP. We introduce IP header, TCP header and UDP header for the most important because we need acquire the information of source address, destination address, ...