概述
目前有许多不同的成熟的 协议的实现版本,其中大部分都在操作系统的核心
实现,这种方案固然是提高 协议软件的效率的必然所选,但却给 协议的学
习、研究和调试带来了很大的困难。于是,如果不考虑 协议软件实现的效率问题,
在应用进程中实现一个 协议软件,是具有一定的意义和价值的。
本 文 作 者 构 造 了 一 个 单 进 程 的 协 议 软 件 : , 并 提 供 了 一 个
接口函数库: 。在实现这个协议软件函数库时,作者选择采用了
的方式在用户态下实现这个软件,不仅是因为这样可以避开一些操作系统
对底层网络开发的种种限制带来的不便,将精力集中在对协议软件本身的理解上;另外一
个原因,则是为大家学习和综合使用 和 提供一个范例。
下文首先介绍了 和 函数库及其使用,并给出了一个利用其实现
协议的例程该协议的实现也包括在 软件之中,然后给出了本文的协议软件和
函数库实现的方案,并围绕本文主题,对涉及到的一些关键技术问题进行了分析 ,
最后,对这种实现方法做了一个简单的总结,指出了这种实现方法的一些局限。
何谓 libnet、libpcap
目前众多的网络安全程序、工具和软件都是基于 设计和开发的。由于在安全
程序中通常需要对网络通讯的细节如连接双方地址端口、服务类型、传输控制等进行检
查、处理或控制,象数据包截获、数据包头分析、数据包重写、甚至截断连接等,都几乎
在每个网络安全程序中必须实现。为了简化网络安全程序的编写过程,提高网络安全程序
的性能和健壮性,同时使代码更易重用与移植,最好的方法就是将最常用和最繁复的过程
函数,如监听套接口的打开关闭、数据包截获、数据包构造发送接收等,封装起来,以
的方式提供给开发人员使用。
在众多的 中,对于类 ! 系统平台上的网络安全工具开发而言,目前最
为流行的 有 、、" 和 等。它们分别从不同层
次和角度提供了不同的功能函数。使网络开发人员能够忽略网络底层细节的实现,从而专
注于程序本身具体功能的设计与开发。其中,
提供的接口函数主要实现和封装了数据包的构造和发送过程。
提供的接口函数主要实现和封装了与数据包截获有关的过程。
利用这些 函数库的接口,网络安全工具开发人员可以很方便地编写出具有结构化强 、
健壮性好、可移植性高等特点的程序。因此,这些函数库在网络安全工具的开发中具有很
大的价值,在 、#、$%、& 等领域都获得了极其广泛的应用,著名
的 "' 软件、( 软件等就是在 的基础上开发的。
另外也应该指出:由于其功能强大,这些函数库也被黑客用来构造 网络程序
对目标主机进行攻击。然而, 网络的安全不可能也不应该建立在禁止大家使用工
具的基础上,一个理想的网络,首先必须是一个开放的网络,这个网络应该在使用任何工