Search code examples
perllibpcapwinpcapstrawberry-perlnpcap

Installing Net::Pcap using strawberry perl on windows 10


I am trying to install Net::Pcap (https://metacpan.org/pod/Net::Pcap) using edition of portable strawberry Perl v5.28.1 ,below are my steps :

1.I installed npcap (winpcap for windows 10 ) from https://nmap.org/npcap/#download

2.I downloaded the npcap sdk from https://nmap.org/npcap/#download

3.I extracted the SDK zip folders to c:/WdpPack and verifies Include and Lib folders includes the header files and libraries

4.Then run the following command

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

i get the below error message :

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/
        - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -

any idea how to solve this problem ?


Solution

  • I was able to compile this by moving the SDK folders from C:\WdpPack to my C:\User folder. I am not so familiar with Windows, so I am not sure why this works, maybe something to do with permissions?

    Update:

    After running perl Makefile.PL, running gmake to compile the module fails with errors:

    [...]
    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'
    

    To fix this, edit the file stubs.inc:

    • delete lines 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 */
      };
      
    • delete lines : 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;
      
    • delete lines: 357-361

      struct pcap_rmtauth {
          int type;
          char *username;
          char *password;
      };
      
    • delete lines lines 438-442:

      struct pcap_send_queue{
          u_int maxlen;
          u_int len;
          char *buffer;
      };
      
    • delete lines 519-521:

      struct pcap_samp {
         int method;
         int value;
      };
      

    Now gmake compiles the files, but the linker fails:

    [...]
    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'
    
    [...]
    

    The problem here was that we linked with the 32-bit library wpcap.lib, see this post. And it turns out that there is a 64-bit version of the library in the SDK in the folder Lib/x64. So we must rerun the Makefile.PL with the correct library path:

    perl Makefile.PL INC=-IC:/Users/Me/Libraries/npcap/Include "LIBS=-LC:/Users/Me/Libraries/npcap/Lib/x64 -lwpcap"
    

    (change the paths in the above command to comply with your installation directory for the SDK) and then rerun gmake.