好消息,超酷的在线虚拟网络实验室上线了!点击开始实验

为获得更好的浏览效果,建议您使用 Firefox 或者 Chrome 浏览器



如何编译WinPcap
[WinPcap核心资料]

这部分内容将告诉你,在不同的win32平台上,如何编译WinPcap。源代码可以在 WinPcap 官网上获得.

编译驱动

编译NPF时,有两个主要的路径:Windows NTx和Windows 9x。注意,因为NPF驱动是与平台相关的,所以,为了连接正确的DDK库,我们强烈建议编译的时候,要选择将来会被使用的那个操作系统。比如,如果你使用Windows NT 4 DDK库赖编译驱动,那么在Windows2000或其他操作系统上运行,将不会那么顺利了。

在Windows NT4平台上编译驱动

软件需求:

  • Microsoft Driver Developer Kit (DDK) for Windows NT4
  • 能在Visual Studio 6上编译的Microsoft Platform Software Development Kit (SDK)的较新的版本(最新的平台发布于2003年2月)。这个版本的PSDK在Microsoft的网站上提供,参见:http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm. 同时,它也可以在线订阅:http://www.qmedia.ca/launch/psdk.htm, 同时,在微软的用户下载网站里,也为微软MSDN用户提供了订阅。
  • Microsoft Visual C++ 6.0 with Service Pack 5 or 6 (这两个版本在微软的网站上都有提供).
  • >

如果你的系统符合上面的三个要求,那么请按照下列步骤:

  1. 从Windows NT 开始 菜单,选择 程序 然后选择 Development Kits, 然后选择 Windows NT4 DDK. 在这里,如果你想建立一个调试版本,你可以选择Checked Build Environment ,如果你想建立一个发布版本,你可以选择 Free Build Environment
  2. 一个命令提示框将被打开。用cd命令移到WinPcap文件夹下的PacketNTx文件夹,输入命令:
    CompileDriver
    这个脚本会产生一个驱动 (npf.sys),然后,二进制数据会被放入下列文件夹中的一个:
    • Free Build Environment: winpcap\PacketNTx\driver\bin\NT4\i386\free
    • Checked Build Environment: winpcap\PacketNTx\driver\bin\NT4\i386\checked

警告: 有时,在编译驱动的过程中,会产生很多'last line incomplete'错误提示。忽略这些错误,并且让编译过程继续进行。它们的产生是由于某些版本的DDK的bug所引起的。

在Windows 2000/XP/2003/Vista(32位和64位AMD64)平台上编译驱动

软件需求:

  • Microsoft Driver Developer Kit (DDK) for Windows Windows XP or Windows Server 2003. 对于 WinPcap 4.0, 最合适的 DDK environment 是 "DDK for Windows Server 2003SP1", 也可以称作 DDK 3790.1830.

注意: 在Windows 2000下使用旧的DDK是可以的,但是,你需要手动地修改编译脚本来禁用PREfast。(PREfast是一个静态代码分析工具,捆绑在较新的DDK中)

如果你的系统满足以上需求,那么请按下列步骤进行:

  1. 从Windows NT 开始 菜单,选择 程序 然后选择 Development Kits, 然后选择 Windows XXX DDK., XXX 就是你的目的系统,然后选择 Build Environments.
    • 32bit 驱动: 选择 Windows 2000 ,然后,如果你想建立一个发布版本的程序,请选择 Windows 2000 Free Build Environment,如果你想建立一个调试版本的程序,请选择 Windows 2000 Checked Build Environment
    • 64bit AMD64 驱动: 选择 Windows Server 2003 然后,如果你想建立一个发布版本的程序,请选择 Windows Server 2003 Free x64 Build Environment 如果你想建立一个调试版本的程序,请选择 Windows Server 2003 Checked x64 Build Environment
  2. 2. 一个命令提示框将被打开。用cd命令移到WinPcap文件夹下的PacketNTx文件夹,输入命令:
    CompileDriver
    这个脚本会产生一个驱动 (npf.sys),然后,二进制数据会被放入下列文件夹中的一个:
    • x86 driver (both Free and Checked Build): winpcap\PacketNTx\driver\bin\i386
    • x64 driver (both Free and Checked Build): winpcap\PacketNTx\driver\bin\amd64

在Windows 9x平台上编译驱动

注意: WinPcap已经不再支持这个Windows平台。然而,一些在代码包中,基于这些操作系统的源代码还是可用的。

要在Windows 9x上编译驱动,你需要:

  • Driver Developer Kit (DDK) for Windows 95/98/ME
  • 能在Visual Studio 6上编译的Microsoft Platform Software Development Kit (SDK)的较新的版本(最新的平台发布于2003年2月)。这个版本的PSDK在Microsoft的网站上提供,参见: http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm. 同时,它也可以在线订阅:http://www.qmedia.ca/launch/psdk.htm, and it's also available to Microsoft MSDN subscribers on the Subscribers Downloads web site.
  • Microsoft Visual C++ 6.0 with Service Pack 5 or 6 (这两个版本在微软的网站上都有提供).

然后,按下列步骤进行:

  1. 打开DOS
  2. 进入 VisualC++ BIN 目录 (比如 C:\DEVSTUDIO\VC\BIN) 并执行命令:

    Vcvars32
  3. 进入 SDK 目录 (比如 C:\MSSDK) 并执行命令:

    Setenv sdk_path

    sdk_path 是 SDK 目录(比如 Setenv C:\MSSDK)
  4. 进入 DDK 目录 (比如 C:\DDK) 并执行命令:

    Ddkenv 32 net
  5. 进入驱动源代码所在目录,并执行命令:

    nmake rtl

    来获得发布版本,或者执行:

    nmake来获得调试版本

    发布版本的 packet.vxd 将会出现在 retail 目录下, 调试版本将会出现在 debug 目录下

警告: 在一些系统中, NMAKE 使用工具并不能启动 ADRC2VXD, 这一位着驱动二进制数据的产生是正确的,不过没有版本信息。我们还不知道引起这个问题的原因。

编译 packet.dll

这个DLL的源路径在 PacketNTx\dll\

注意: WinPcap 已经不再支持这个 Windows9x 平台。然而,一些在代码包中,基于这些操作系统的源代码还是可用的。

软件需求:

  • 能在Visual Studio 6上编译的Microsoft Platform Software Development Kit (SDK)的较新的版本(最新的平台发布于2003年2月)。这个版本的PSDK在Microsoft的网站上提供,参见:http://www.microsoft.com/msdownload/platformsdk/sdkupdate/psdk-full.htm. 同时,它也可以在线订阅:http://www.qmedia.ca/launch/psdk.htm, 同时,在微软的用户下载网站里,也为微软MSDN用户提供了订阅。
    注意: 如果你使用 Microsoft Visual Studio .NET ,那么平台SDK是不需要编译packet.dll的。
  • Microsoft Visual C++ 6.0 with Service Pack 5 or 6 (这两个版本在微软的网站上都有提供).
  • 如果你想用WinPcap建立一个支持CACE无线包捕获技术的程序,你需要从http://www.cacetech.com/products/airpcap.htm下载AirPcap developer's pack。The AirPcap developer's pack需要被解压到和WinPcap同一个目录下。

要编译 PACKET.DLL, 在Visual C++平台下,加载一个包含了目录 PacketNTx\dll\project 的工程。 以下是一些工程的配置:

  • Release: standard release configuration
  • Debug: standard debug configuration
  • Release NT4: release configuration able to run on NT4. It does not include Wan and IP helper API support.
  • Debug NT4: debug configuration able to run on NT4. It does not include Wan and IP helper API support.
  • Release No NetMon: release configuration able to run on Vista. It does not include Wan support (with the NetMon API).
  • Debug No NetMon: debug configuration able to run on Vista. It does not include Wan support (with the NetMon API).
  • Release LOG_TO_FILE: standard release configuration with tracing to file enabled.
  • Release NT4 LOG_TO_FILE: release configuration able to run on NT4 with tracing to file enabled. It does not include Wan and IP helper API support.
  • Release No NetMon LOG_TO_FILE: release configuration able to run on Vista with tracing to file enabled. It does not include Wan support (with the NetMon API).

选择一种需要的配置,并建立工程来获取二进制文件.

编译 wpcap.dll

wpcap.dll 可以在任何 Win32 平台下编译,产生的dll是平台相关的。

Choose the desired configuration and build the project to obtain the binary files.

注意: wpcap.dll 包含了来自 www.tcpdump.org, 的libpcap的源代码,对于远程捕获有一些修改。 你能包含和构建一个不同版本的libpcap,只需要简单地把它拷贝到winpcap\wpcap\prj下的 WinPcap 源代码中即可,但是,你必须使用"Debug(调试)"或"Release(发行)"进行配置