perl - 在 Windows 10 上使用草莓 perl 安装 Net::Pcap

标签 perl libpcap winpcap strawberry-perl npcap

我正在尝试使用可移植草莓 Perl v5.28.1 版本安装 Net::Pcap (https://metacpan.org/pod/Net::Pcap),以下是我的步骤:

1.我从 https://nmap.org/npcap/#download 安装了 npcap (winpcap for windows 10 )

2.我从https://nmap.org/npcap/#download下载了npcap sdk

3.我将 SDK zip 文件夹解压缩到 c:/WdpPack 并验证 Include 和 Lib 文件夹是否包含头文件和库

4.然后运行以下命令

perl Makefile.PL INC=-IC:/WpdPack/Include "LIBS=-LC:/WpdPack/Lib -lwpcap"

我收到以下错误消息:
socket.h patched... ok
looking for -lwpcap... yes
checking for pcap_lib_version() in -lwpcap... no
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
You appear to lack the WinPcap developer pack.

If it is installed in a non-standard location, please try setting the LIBS
and INC values on the command line.  For instance, if you have unzipped the
developer's pack in C:\WpdPack, you should execute:

    perl Makefile.PL INC=-IC:/WpdPack/Include "LIBS=-LC:/WpdPack/Lib -lwpcap"

Or get and install the WinPcap developer's pack from
  http://www.winpcap.org/install/
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

知道如何解决这个问题吗?

最佳答案

我可以通过从 C:\WdpPack 移动 SDK 文件夹来编译它。给我的C:\User文件夹。我对 Windows 不太熟悉,所以我不确定为什么会这样,也许与权限有关?

更新 :

运行后perl Makefile.PL , 运行 gmake编译模块失败并出现错误:

[...]
stubs.inc:91:8: error: redefinition of 'struct pcap_if'
[...]
stubs.inc:267:5: error: conflicting types for 'pcap_compile_nopcap'
[...]
stubs.inc:357:8: error: redefinition of 'struct pcap_rmtauth'
[...]
stubs.inc:363:10: error: conflicting types for 'pcap_open'
[...]
stubs.inc:438:8: error: redefinition of 'struct pcap_send_queue'
[...]
stubs.inc:497:8: error: redefinition of 'struct pcap_samp'

要解决此问题,请编辑文件 stubs.inc :
  • 删除第 91-97 行
    struct pcap_if {
        struct pcap_if *next;
        char *name;     /* name to hand to "pcap_open_live()" */
        char *description;  /* textual description of interface, or NULL */
        struct pcap_addr *addresses;
        bpf_u_int32 flags;  /* PCAP_IF_ interface flags */
    };
    
  • 删除行:267-271
    int pcap_compile_nopcap(int snaplen, int linktype, struct bpf_program *fp, char *str, int optimize, bpf_u_int32 netmask);
    int pcap_compile_nopcap(int snaplen, int linktype, struct bpf_program *fp, char *str, int optimize, bpf_u_int32 netmask) {
        FUNCTION_NOT_IMPLEMENTED_ERROR(pcap_compile_nopcap)
        return -1;
    
  • 删除行:357-361
    struct pcap_rmtauth {
        int type;
        char *username;
        char *password;
    };
    
  • 删除第 438-442 行:
    struct pcap_send_queue{
        u_int maxlen;
        u_int len;
        char *buffer;
    };
    
  • 删除第 519-521 行:
    struct pcap_samp {
       int method;
       int value;
    };
    

  • 现在gmake编译文件,但链接器失败:
    [...]
    C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Pcap.o:Pcap.c:(.text+0x23be): undefined reference to `pcap_geterr'
    C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Pcap.o:Pcap.c:(.text+0x2580): undefined reference to `pcap_geterr'
    C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Pcap.o:Pcap.c:(.text+0x2590): undefined reference to `pcap_stats'
    C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Pcap.o:Pcap.c:(.text+0x2820): undefined reference to `pcap_fileno'
    C:/Strawberry/c/bin/../lib/gcc/x86_64-w64-mingw32/8.3.0/../../../../x86_64-w64-mingw32/bin/ld.exe: Pcap.o:Pcap.c:(.text+0x29c4): undefined reference to `pcap_file'
    
    [...]
    

    这里的问题是我们链接到了 32 位库 wpcap.lib ,见 this邮政。事实证明,在文件夹Lib/x64的SDK中有一个64位版本的库。 .所以我们必须重新运行 Makefile.PL使用正确的库路径:
    perl Makefile.PL INC=-IC:/Users/Me/Libraries/npcap/Include "LIBS=-LC:/Users/Me/Libraries/npcap/Lib/x64 -lwpcap"
    

    (更改上述命令中的路径以符合您的 SDK 安装目录)然后重新运行 gmake .

    关于perl - 在 Windows 10 上使用草莓 perl 安装 Net::Pcap,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60086671/

    相关文章:

    c++ - 在 WINPCAP 中如何知道哪些安装的设备有互联网连接?

    c++ - 谁能为 C++ 推荐一个好的数据包嗅探器类?

    perl - 为什么 Perl `printf` 会改变我的 $variable 的值?

    javascript - 类型转换 perl、javascript、JSON.parse JSON::XS - 需要想法

    linux - 如何确定目的MAC地址

    python /dpkt : Find out if packet is a tcp packet or a udp packet ,

    c++ - 读取pcap捕获文件崩溃

    python - 查找已从 pcap 数据传输了多少数据

    perl - 您认为 2010 年 Perl 的哪些新功能最有用?

    regex - 如何在 Perl 替换运算符的替换端使用变量?