Winpcap开发者使用Cygwin C ++& Netbeans IDE [英] Winpcap Developer Usage with Cygwin C++ & Netbeans IDE

查看:524
本文介绍了Winpcap开发者使用Cygwin C ++& Netbeans IDE的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

希望获得在Windows 7 64位上运行的Winpcap开发人员包(4.1.2)。我在C / C ++在Netbeans IDE中使用Cygwin(4.1.10)编译器进行编程。我想直接从UDP包中取出一些GPS数据,而不是使用另一个程序,我经历一个中间步骤,并从一个文本文件中拉。如果我不能排序,我会在Ubuntu下尝试,看看我是否可以得到libpcap在那里工作(即使Windows是首选,因为我使用的其他设备)。这里是我在哪里(我的主要资源从 WinPcap网络库简介在程序中使用WinPcap (注意:我不能发布第三个链接,因为它说我的声誉需要更高)):

Looking to get the Winpcap developer pack (4.1.2) running on Windows 7 64-bit. I'm programming in C/C++ in the Netbeans IDE with the Cygwin (4.1.10) compiler. I'd like to directly pull some GPS data from UDP packets instead of using another program where I go through an intermediate step and pull them from a text file. If I can't sort this out I'm gonna try in Ubuntu next and see if I can get libpcap working there (even though Windows is preferred because of other equipment I am using). Here's where I'm at (my main resources have been gathered from Introduction to the WinPcap Networking Libraries, Using WinPcap in your programs, and Programming with pcap at tcpdump.org (note: I can't post the third link because it says my reputation needs to be higher)):


  1. 我已经安装了winpcap开发包到C:\Users \\Documents

  2. 我安装了winpcap dll确定为什么这是必要的,因为所有的文档,我看到只是似乎只使用.lib文件)

  3. 根据上述链接的指示,我在我的项目中添加了以下设置:

    • 对于包含目录和标题,我将路径指向开发人员包中的winpcap Include 文件夹

    • 对于预处理程序定义,我已添加 HAVE_REMOTE WPCAP


  1. I've installed the winpcap developers pack to C:\Users\\Documents
  2. I've installed the winpcap dll (though I'm not actually sure why this is necessary since all of the documentation I've seen only seems to use the .lib files)
  3. As instructed from the above links I've added the following settings in my project:
    • For the "Include Directories and Headers" I put the path to the winpcap Include folder from the developer pack
    • For "Preprocessor Definitions" I've added HAVE_REMOTE and WPCAP
    • For "Additional Library Directories" I put the path to the winpcap Lib folder from the developer pack



p>通过做所有上述和包括 pcap.h 头没有额外的代码,我可以编译我的程序。但是,我一直在引用的安装说明还声明了添加以下两个附加依赖关系: winpcap.lib Packet.lib

By doing all of the above and including the pcap.h header with no additional code I can compile my program. However, the install instructions I've been referencing also state to add the following two "Additional Dependencies": winpcap.lib and Packet.lib

一旦我这样做,我就无法编译并获得以下内容:

As soon as I do that I can't compile and get the following:

make[2]: Entering directory '/cygdrive/c/Users/<user>/Documents/NetBeansProjects/GPS_Parcer'
make[2]: *** No rule to make target 'winpcap.lib', needed by 'dist/Debug/Cygwin_4.x-Windows/gps_parcer.exe'.  Stop.
make[2]: Leaving directory '/cygdrive/c/Users/<user>/Documents/NetBeansProjects/GPS_Parcer'
nbproject/Makefile-Debug.mk:61: recipe for target '.build-conf' failed
make[1]: *** [.build-conf] Error 2
make[1]: Leaving directory '/cygdrive/c/Users/<user>/Documents/NetBeansProjects/GPS_Parcer'
nbproject/Makefile-impl.mk:39: recipe for target '.build-impl' failed
make: *** [.build-impl] Error 2

出于好奇,看看这些依赖关系是否真正重要我删除它们,然后添加一些基本代码我从tcpdump.org:

Out of curiosity to see if those dependencies actually mattered I removed them and then added some basic code I copied from tcpdump.org:

#include <stdio.h>
#include <pcap.h>

int main(int argc, char *argv[])
{
    char *dev, errbuf[PCAP_ERRBUF_SIZE];

    dev = pcap_lookupdev(errbuf);  //error is here!

    if (dev == NULL) {
        fprintf(stderr, "Couldn't find default device: %s\n", errbuf);
        return(2);
    }
    printf("Device: %s\n", dev);
    return(0);
}



我得到一个未定义的引用'pcap_lookupdev' / code>错误。

I get an undefined reference to 'pcap_lookupdev' error.

我也读过,可能Winpcap只能使用MS Visual Studio的东西,所以我实际上不知道这是真的。

I've also read that possibly Winpcap will only work with MS Visual Studio stuff so I actually don't know if that's true.

对不起,很长的写作,但如果任何人有一些洞察或经验,这将非常感激。

Sorry for the long write-up, but if anybody has some insights or experience with this it would be much appreciated.

推荐答案

我对同一套乐器有类似的问题。今天我的经验成功,我找到了解决方案!

I had similar problems with the same set of instruments. Today my experiences became successful and i found solution!


  1. (最重要的)。由于您使用cygwin(即GNU Linux)工具链编译代码,因此您需要向项目中添加直接的库: libwpcap.a libpacket.a winpcap:项目属性 - >链接器选项卡 - >库 - > add library(这只是在编译行中提供了一个正确的库名称,你可以看到: -lwpcap -lpacket )。不幸的是,这些库只有x32版本...

  1. (most important). Because of you compile your code with cygwin (i.e. GNU Linux) toolchain, you need to add to your project straight libraries: libwpcap.a and libpacket.a from developer package of winpcap: project properties -> linker tab -> libraries -> "add library" (this just provide a correct names of that libraries in compilation line as you can see: -lwpcap -lpacket). unfortunately, there are only x32 version of these libraries...

所以,如果你使用x64版本的cygwin那么:

so, if you use x64 version of cygwin (as I), then:


  1. 您需要下载并安装x32版本的 cygwin 。确保在安装过程中选择编译器和其他必要的软件包。然后,在NetBeans的属性中,在C / C ++选项卡上,从 x32 cygwin 添加工具链,并将其命名为 cygwin_32 接下来,在您的项目的属性中选择此( cygwin_32 )工具包并验证您提供的路径到正确的目录 / lib / include WinPcap
    尝试构建它。在这一点上,您的项目应该成功构建。接下来,要能够运行您的程序,您必须提供位于 / bin 目录中的 cygwin1.dll 的正确版本(x32) em> cygwin 。 (只需将其复制到可执行文件的目录)。

  1. You need download and install x32 version of cygwin. Be sure to select compilers and other necessary packages in process of installation. then, in properties of NetBeans on tab C/C++ add toolchain from x32 cygwin and name it cygwin_32 for example. Next, in properties of your project select this (cygwin_32) tool kit and verify, that you supply path to the correct directories /lib and /include of WinPcap. try to build it. at this point, your project should be successfully built. Next, to be able to run your program, you must supply the proper (x32) version of cygwin1.dll located in /bin directory of cygwin. (simply copy it to directory of your executable).

这样获得的可执行文件在WinXP sp2 ,当然还有我的 Win7 x64 。 (对于测试我使用 WpdPack\Examples-pcap\basic_dump\basic_dump.c WpdPack_4_1_2.zip 归档,as is)。

Thus obtained executable file i succesfully tested at WinXP (x32) with sp2 and of course on my Win7 x64. (For tests i used WpdPack\Examples-pcap\basic_dump\basic_dump.c from WpdPack_4_1_2.zip archive, as is).

希望这对某人有帮助。

这篇关于Winpcap开发者使用Cygwin C ++&amp; Netbeans IDE的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆