3

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 ?

Matt Davis
  • 45,297
  • 16
  • 93
  • 124
jsor
  • 97
  • 5
  • I enabled the `$DEBUG` flag in `Makefile.PL` and from the output it seems like the compiler cannot find the header `pcap.h`. It is strange since the compiler is given the `-IC:/WpdPack/Include` flag – Håkon Hægland Feb 06 '20 at 06:18

1 Answers1

3

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.

Håkon Hægland
  • 39,012
  • 21
  • 81
  • 174
  • Thanks , now when i run perl Makefile it finished with success , but when i run gmake i get the below error : PCAP_API char *pcap_lookupdev(char *) ^~~~~~~~~~~~~~ Pcap.c: In function 'XS_Net__Pcap_strerror': Pcap.c:1703:9: warning: assignment discards 'const' qualifier from pointer target type [-Wdiscarded-qualifiers] RETVAL = pcap_strerror(error); ^ Pcap.xs: In function 'XS_Net__Pcap_getevent': Pcap.xs:1038:13: warning: cast from pointer to integer of different size [-Wpointer-to-int-cast] h = (unsigned int) pcap_getevent(p); ^ – jsor Feb 06 '20 at 13:17
  • Yes I also get errors when I run `gmake`, maybe you should report it as a bug at the GitHub [issue tracker](https://github.com/maddingue/Net-Pcap/issues)? – Håkon Hægland Feb 06 '20 at 13:31
  • See also [this blog](https://neil.tappsville.com/index.php/Perl#Net::PCAP_.3D) for a previous attempt (that seemed to work with `dmake`) – Håkon Hægland Feb 06 '20 at 13:53
  • Another idea is to try install using `cygwin` ? – Håkon Hægland Feb 06 '20 at 14:04
  • I was able to compile it now, see my updated answer! – Håkon Hægland Feb 06 '20 at 15:30
  • 1
    Thanks I was able to compile it based on your answer ! ,now let's see how it working under windows 10 :) – jsor Feb 06 '20 at 22:17