无法在 Linux 上使用 cpan/cpanm 安装 Net::Pcap

Cant install Net::Pcap with cpan/cpanm on Linux

我正在尝试安装模块 Net::Pcap。这是我所做的:

[nick@void ~]$ cpanm Net::Pcap
--> Working on Net::Pcap
Fetching http://www.cpan.org/authors/id/S/SA/SAPER/Net-Pcap-0.18.tar.gz ... OK
Configuring Net-Pcap-0.18 ... OK
Building and testing Net-Pcap-0.18 ... FAIL
! Installing Net::Pcap failed. See /home/nick/.cpanm/work/1612889779.12603/build.log for details. Retry with --force to force install it. 

这是 build.log 文件:

[nick@void ~]$ cat /home/nick/.cpanm/work/1612889779.12603/build.log 
cpanm (App::cpanminus) 1.7044 on perl 5.032001 built for x86_64-linux
Work directory is /home/nick/.cpanm/work/1612889779.12603
You have make /usr/bin/make
You have /usr/bin/curl
You have /usr/bin/tar: tar (GNU tar) 1.32
Copyright (C) 2019 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <https://gnu.org/licenses/gpl.html>.
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law.

Written by John Gilmore and Jay Fenlason.
You have /usr/bin/unzip
Searching Net::Pcap () on cpanmetadb ...
--> Working on Net::Pcap
Fetching http://www.cpan.org/authors/id/S/SA/SAPER/Net-Pcap-0.18.tar.gz
-> OK
Unpacking Net-Pcap-0.18.tar.gz
Entering Net-Pcap-0.18
Checking configure dependencies from META.json
Checking if you have ExtUtils::MakeMaker 6.58 ... Yes (7.44)
Configuring Net-Pcap-0.18
Running Makefile.PL
looking for -lpcap... yes
checking for pcap_lib_version() in -lpcap... yes
detecting available functions... ok
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Net::Pcap
Writing MYMETA.yml and MYMETA.json
-> OK
Checking dependencies from MYMETA.json ...
Checking if you have ExtUtils::MakeMaker 0 ... Yes (7.44)
Checking if you have Test::More 0.45 ... Yes (1.302175)
Checking if you have Socket 0 ... Yes (2.029)
Checking if you have XSLoader 0 ... Yes (0.30)
Checking if you have Carp 0 ... Yes (1.50)
Checking if you have Sys::Hostname 0 ... Yes (1.23)
Building and testing Net-Pcap-0.18
cp Pcap.pm blib/lib/Net/Pcap.pm
Running Mkbootstrap for Pcap ()
chmod 644 "Pcap.bs"
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Pcap.bs blib/arch/auto/Net/Pcap/Pcap.bs 644
"/usr/bin/perl" "/usr/share/perl5/core_perl/ExtUtils/xsubpp"  -typemap '/usr/share/perl5/core_perl/ExtUtils/typemap' -typemap '/home/nick/.cpanm/work/1612889779.12603/Net-Pcap-0.18/typemap'  Pcap.xs > Pcap.xsc
mv Pcap.xsc Pcap.c
cc -c   -fstack-clash-protection -D_FORTIFY_SOURCE=2 -mtune=generic -O2 -pipe -g -D_FILE_OFFSET_BITS=64 -DLARGE_FILE_SUPPORT64 -Wall -fstack-clash-protection -D_FORTIFY_SOURCE=2 -mtune=generic -O2 -pipe -g -D_FILE_OFFSET_BITS=64 -DLARGE_FILE_SUPPORT64   -DVERSION=\"0.18\" -DXS_VERSION=\"0.18\" -fPIC "-I/usr/lib/perl5/core_perl/CORE"  -DHAVE_BLANK -DHAVE_PCAP_LIB_VERSION -DHAVE_PCAP_BREAKLOOP -DHAVE_PCAP_COMPILE_NOPCAP -DHAVE_PCAP_DATALINK_NAME_TO_VAL -DHAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION -DHAVE_PCAP_DATALINK_VAL_TO_NAME -DHAVE_PCAP_DUMP_FILE -DHAVE_PCAP_DUMP_FLUSH -DHAVE_PCAP_FINDALLDEVS -DHAVE_PCAP_GETNONBLOCK -DHAVE_PCAP_GET_SELECTABLE_FD -DHAVE_PCAP_LIB_VERSION -DHAVE_PCAP_NEXT_EX -DHAVE_PCAP_OFFLINE_FILTER -DHAVE_PCAP_OPEN_DEAD -DHAVE_PCAP_SENDPACKET -DHAVE_PCAP_SETNONBLOCK -DHAVE_PCAP_SET_DATALINK Pcap.c
In file included from Pcap.xs:43:
stubs.inc:187:2: warning: #warning "the function pcap_list_datalinks() is not available" [-Wcpp]
  187 | #warning "the function pcap_list_datalinks() is not available"
      |  ^~~~~~~
stubs.inc:322:2: warning: #warning "the function pcap_createsrcstr() is not available" [-Wcpp]
  322 | #warning "the function pcap_createsrcstr() is not available"
      |  ^~~~~~~
stubs.inc:337:2: warning: #warning "the function pcap_parsesrcstr() is not available" [-Wcpp]
  337 | #warning "the function pcap_parsesrcstr() is not available"
      |  ^~~~~~~
stubs.inc:352:2: warning: #warning "the function pcap_open() is not available" [-Wcpp]
  352 | #warning "the function pcap_open() is not available"
      |  ^~~~~~~
stubs.inc:357:8: error: redefinition of 'struct pcap_rmtauth'
  357 | struct pcap_rmtauth {
      |        ^~~~~~~~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:1036:8: note: originally defined here
 1036 | struct pcap_rmtauth
      |        ^~~~~~~~~~~~
In file included from Pcap.xs:43:
stubs.inc:363:10: error: conflicting types for 'pcap_open'
  363 | pcap_t * pcap_open(const char *source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth *auth, char *err);
      |          ^~~~~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:1084:18: note: previous declaration of 'pcap_open' was here
 1084 | PCAP_API pcap_t *pcap_open(const char *source, int snaplen, int flags,
      |                  ^~~~~~~~~
In file included from Pcap.xs:43:
stubs.inc:364:10: error: conflicting types for 'pcap_open'
  364 | pcap_t * pcap_open(const char *source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth *auth, char *err) {
      |          ^~~~~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:1084:18: note: previous declaration of 'pcap_open' was here
 1084 | PCAP_API pcap_t *pcap_open(const char *source, int snaplen, int flags,
      |                  ^~~~~~~~~
In file included from Pcap.xs:43:
stubs.inc:373:2: warning: #warning "the function pcap_setbuff() is not available" [-Wcpp]
  373 | #warning "the function pcap_setbuff() is not available"
      |  ^~~~~~~
stubs.inc:388:2: warning: #warning "the function pcap_setuserbuffer() is not available" [-Wcpp]
  388 | #warning "the function pcap_setuserbuffer() is not available"
      |  ^~~~~~~
stubs.inc:403:2: warning: #warning "the function pcap_setmode() is not available" [-Wcpp]
  403 | #warning "the function pcap_setmode() is not available"
      |  ^~~~~~~
stubs.inc:418:2: warning: #warning "the function pcap_setmintocopy() is not available" [-Wcpp]
  418 | #warning "the function pcap_setmintocopy() is not available"
      |  ^~~~~~~
stubs.inc:433:2: warning: #warning "the function pcap_sendqueue_alloc() is not available" [-Wcpp]
  433 | #warning "the function pcap_sendqueue_alloc() is not available"
      |  ^~~~~~~
stubs.inc:455:2: warning: #warning "the function pcap_sendqueue_destroy() is not available" [-Wcpp]
  455 | #warning "the function pcap_sendqueue_destroy() is not available"
      |  ^~~~~~~
stubs.inc:469:2: warning: #warning "the function pcap_sendqueue_queue() is not available" [-Wcpp]
  469 | #warning "the function pcap_sendqueue_queue() is not available"
      |  ^~~~~~~
stubs.inc:484:2: warning: #warning "the function pcap_sendqueue_transmit() is not available" [-Wcpp]
  484 | #warning "the function pcap_sendqueue_transmit() is not available"
      |  ^~~~~~~
stubs.inc:499:2: warning: #warning "the function pcap_event() is not available" [-Wcpp]
  499 | #warning "the function pcap_event() is not available"
      |  ^~~~~~~
stubs.inc:514:2: warning: #warning "the function pcap_setsampling() is not available" [-Wcpp]
  514 | #warning "the function pcap_setsampling() is not available"
      |  ^~~~~~~
stubs.inc:519:8: error: redefinition of 'struct pcap_samp'
  519 | struct pcap_samp {
      |        ^~~~~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:1168:8: note: originally defined here
 1168 | struct pcap_samp
      |        ^~~~~~~~~
In file included from Pcap.xs:43:
stubs.inc:524:19: error: conflicting types for 'pcap_setsampling'
  524 | struct pcap_samp *pcap_setsampling(pcap_t *p);
      |                   ^~~~~~~~~~~~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:1186:28: note: previous declaration of 'pcap_setsampling' was here
 1186 | PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p);
      |                            ^~~~~~~~~~~~~~~~
In file included from Pcap.xs:43:
stubs.inc:525:19: error: conflicting types for 'pcap_setsampling'
  525 | struct pcap_samp *pcap_setsampling(pcap_t *p) {
      |                   ^~~~~~~~~~~~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:1186:28: note: previous declaration of 'pcap_setsampling' was here
 1186 | PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p);
      |                            ^~~~~~~~~~~~~~~~
Pcap.xs: In function 'XS_Net__Pcap_lookupdev':
Pcap.xs:108:4: warning: 'pcap_lookupdev' is deprecated: use 'pcap_findalldevs' and use the first device [-Wdeprecated-declarations]
  108 |    RETVAL = pcap_lookupdev(errbuf);
      |    ^~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:394:16: note: declared here
  394 | PCAP_API char *pcap_lookupdev(char *)
      |                ^~~~~~~~~~~~~~
Pcap.xs: In function 'XS_Net__Pcap_findalldevs_xs':
Pcap.xs:222:21: warning: 'pcap_lookupdev' is deprecated: use 'pcap_findalldevs' and use the first device [-Wdeprecated-declarations]
  222 |                     char *dev = pcap_lookupdev(errbuf);
      |                     ^~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:394:16: note: declared here
  394 | 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]
 1703 |  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]
 1038 |         h = (unsigned int) pcap_getevent(p);
      |             ^
make: *** [Makefile:344: Pcap.o] Error 1
-> FAIL Installing Net::Pcap failed. See /home/nick/.cpanm/work/1612889779.12603/build.log for details. Retry with --force to force install it.

好的,也许常规 cpan 会起作用。

[nick@void ~]$ cpan Net::Pcap
Loading internal logger. Log::Log4perl recommended for better logging
Reading '/home/nick/.cpan/Metadata'
  Database was generated on Tue, 09 Feb 2021 14:56:08 GMT
Running install for module 'Net::Pcap'
Checksum for /home/nick/.cpan/sources/authors/id/S/SA/SAPER/Net-Pcap-0.18.tar.gz ok
'YAML' not installed, will not store persistent state
Configuring S/SA/SAPER/Net-Pcap-0.18.tar.gz with Makefile.PL
looking for -lpcap... yes
checking for pcap_lib_version() in -lpcap... yes
detecting available functions... ok
Checking if your kit is complete...
Looks good
Generating a Unix-style Makefile
Writing Makefile for Net::Pcap
Writing MYMETA.yml and MYMETA.json
  SAPER/Net-Pcap-0.18.tar.gz
  /usr/bin/perl Makefile.PL INSTALLDIRS=site -- OK
Running make for S/SA/SAPER/Net-Pcap-0.18.tar.gz
cp Pcap.pm blib/lib/Net/Pcap.pm
Running Mkbootstrap for Pcap ()
chmod 644 "Pcap.bs"
"/usr/bin/perl" -MExtUtils::Command::MM -e 'cp_nonempty' -- Pcap.bs blib/arch/auto/Net/Pcap/Pcap.bs 644
"/usr/bin/perl" "/usr/share/perl5/core_perl/ExtUtils/xsubpp"  -typemap '/usr/share/perl5/core_perl/ExtUtils/typemap' -typemap '/home/nick/.cpan/build/Net-Pcap-0.18-7/typemap'  Pcap.xs > Pcap.xsc
mv Pcap.xsc Pcap.c
cc -c   -fstack-clash-protection -D_FORTIFY_SOURCE=2 -mtune=generic -O2 -pipe -g -D_FILE_OFFSET_BITS=64 -DLARGE_FILE_SUPPORT64 -Wall -fstack-clash-protection -D_FORTIFY_SOURCE=2 -mtune=generic -O2 -pipe -g -D_FILE_OFFSET_BITS=64 -DLARGE_FILE_SUPPORT64   -DVERSION=\"0.18\" -DXS_VERSION=\"0.18\" -fPIC "-I/usr/lib/perl5/core_perl/CORE"  -DHAVE_BLANK -DHAVE_PCAP_LIB_VERSION -DHAVE_PCAP_BREAKLOOP -DHAVE_PCAP_COMPILE_NOPCAP -DHAVE_PCAP_DATALINK_NAME_TO_VAL -DHAVE_PCAP_DATALINK_VAL_TO_DESCRIPTION -DHAVE_PCAP_DATALINK_VAL_TO_NAME -DHAVE_PCAP_DUMP_FILE -DHAVE_PCAP_DUMP_FLUSH -DHAVE_PCAP_FINDALLDEVS -DHAVE_PCAP_GETNONBLOCK -DHAVE_PCAP_GET_SELECTABLE_FD -DHAVE_PCAP_LIB_VERSION -DHAVE_PCAP_NEXT_EX -DHAVE_PCAP_OFFLINE_FILTER -DHAVE_PCAP_OPEN_DEAD -DHAVE_PCAP_SENDPACKET -DHAVE_PCAP_SETNONBLOCK -DHAVE_PCAP_SET_DATALINK Pcap.c
In file included from Pcap.xs:43:
stubs.inc:187:2: warning: #warning "the function pcap_list_datalinks() is not available" [-Wcpp]
  187 | #warning "the function pcap_list_datalinks() is not available"
      |  ^~~~~~~
stubs.inc:322:2: warning: #warning "the function pcap_createsrcstr() is not available" [-Wcpp]
  322 | #warning "the function pcap_createsrcstr() is not available"
      |  ^~~~~~~
stubs.inc:337:2: warning: #warning "the function pcap_parsesrcstr() is not available" [-Wcpp]
  337 | #warning "the function pcap_parsesrcstr() is not available"
      |  ^~~~~~~
stubs.inc:352:2: warning: #warning "the function pcap_open() is not available" [-Wcpp]
  352 | #warning "the function pcap_open() is not available"
      |  ^~~~~~~
stubs.inc:357:8: error: redefinition of 'struct pcap_rmtauth'
  357 | struct pcap_rmtauth {
      |        ^~~~~~~~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:1036:8: note: originally defined here
 1036 | struct pcap_rmtauth
      |        ^~~~~~~~~~~~
In file included from Pcap.xs:43:
stubs.inc:363:10: error: conflicting types for 'pcap_open'
  363 | pcap_t * pcap_open(const char *source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth *auth, char *err);
      |          ^~~~~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:1084:18: note: previous declaration of 'pcap_open' was here
 1084 | PCAP_API pcap_t *pcap_open(const char *source, int snaplen, int flags,
      |                  ^~~~~~~~~
In file included from Pcap.xs:43:
stubs.inc:364:10: error: conflicting types for 'pcap_open'
  364 | pcap_t * pcap_open(const char *source, int snaplen, int flags, int read_timeout, struct pcap_rmtauth *auth, char *err) {
      |          ^~~~~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:1084:18: note: previous declaration of 'pcap_open' was here
 1084 | PCAP_API pcap_t *pcap_open(const char *source, int snaplen, int flags,
      |                  ^~~~~~~~~
In file included from Pcap.xs:43:
stubs.inc:373:2: warning: #warning "the function pcap_setbuff() is not available" [-Wcpp]
  373 | #warning "the function pcap_setbuff() is not available"
      |  ^~~~~~~
stubs.inc:388:2: warning: #warning "the function pcap_setuserbuffer() is not available" [-Wcpp]
  388 | #warning "the function pcap_setuserbuffer() is not available"
      |  ^~~~~~~
stubs.inc:403:2: warning: #warning "the function pcap_setmode() is not available" [-Wcpp]
  403 | #warning "the function pcap_setmode() is not available"
      |  ^~~~~~~
stubs.inc:418:2: warning: #warning "the function pcap_setmintocopy() is not available" [-Wcpp]
  418 | #warning "the function pcap_setmintocopy() is not available"
      |  ^~~~~~~
stubs.inc:433:2: warning: #warning "the function pcap_sendqueue_alloc() is not available" [-Wcpp]
  433 | #warning "the function pcap_sendqueue_alloc() is not available"
      |  ^~~~~~~
stubs.inc:455:2: warning: #warning "the function pcap_sendqueue_destroy() is not available" [-Wcpp]
  455 | #warning "the function pcap_sendqueue_destroy() is not available"
      |  ^~~~~~~
stubs.inc:469:2: warning: #warning "the function pcap_sendqueue_queue() is not available" [-Wcpp]
  469 | #warning "the function pcap_sendqueue_queue() is not available"
      |  ^~~~~~~
stubs.inc:484:2: warning: #warning "the function pcap_sendqueue_transmit() is not available" [-Wcpp]
  484 | #warning "the function pcap_sendqueue_transmit() is not available"
      |  ^~~~~~~
stubs.inc:499:2: warning: #warning "the function pcap_event() is not available" [-Wcpp]
  499 | #warning "the function pcap_event() is not available"
      |  ^~~~~~~
stubs.inc:514:2: warning: #warning "the function pcap_setsampling() is not available" [-Wcpp]
  514 | #warning "the function pcap_setsampling() is not available"
      |  ^~~~~~~
stubs.inc:519:8: error: redefinition of 'struct pcap_samp'
  519 | struct pcap_samp {
      |        ^~~~~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:1168:8: note: originally defined here
 1168 | struct pcap_samp
      |        ^~~~~~~~~
In file included from Pcap.xs:43:
stubs.inc:524:19: error: conflicting types for 'pcap_setsampling'
  524 | struct pcap_samp *pcap_setsampling(pcap_t *p);
      |                   ^~~~~~~~~~~~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:1186:28: note: previous declaration of 'pcap_setsampling' was here
 1186 | PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p);
      |                            ^~~~~~~~~~~~~~~~
In file included from Pcap.xs:43:
stubs.inc:525:19: error: conflicting types for 'pcap_setsampling'
  525 | struct pcap_samp *pcap_setsampling(pcap_t *p) {
      |                   ^~~~~~~~~~~~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:1186:28: note: previous declaration of 'pcap_setsampling' was here
 1186 | PCAP_API struct pcap_samp *pcap_setsampling(pcap_t *p);
      |                            ^~~~~~~~~~~~~~~~
Pcap.xs: In function 'XS_Net__Pcap_lookupdev':
Pcap.xs:108:4: warning: 'pcap_lookupdev' is deprecated: use 'pcap_findalldevs' and use the first device [-Wdeprecated-declarations]
  108 |    RETVAL = pcap_lookupdev(errbuf);
      |    ^~~~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:394:16: note: declared here
  394 | PCAP_API char *pcap_lookupdev(char *)
      |                ^~~~~~~~~~~~~~
Pcap.xs: In function 'XS_Net__Pcap_findalldevs_xs':
Pcap.xs:222:21: warning: 'pcap_lookupdev' is deprecated: use 'pcap_findalldevs' and use the first device [-Wdeprecated-declarations]
  222 |                     char *dev = pcap_lookupdev(errbuf);
      |                     ^~~~
In file included from /usr/include/pcap.h:43,
                 from Pcap.xs:32:
/usr/include/pcap/pcap.h:394:16: note: declared here
  394 | 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]
 1703 |  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]
 1038 |         h = (unsigned int) pcap_getevent(p);
      |             ^
make: *** [Makefile:345: Pcap.o] Error 1
  SAPER/Net-Pcap-0.18.tar.gz
  /usr/bin/make -- NOT OK

没有。

这是我第一次安装 cpan 模块,所以我尝试安装一个随机模块,但效果很好。

[nick@void ~]$ cpanm Regexp::Debugger
--> Working on Regexp::Debugger
Fetching http://www.cpan.org/authors/id/D/DC/DCONWAY/Regexp-Debugger-0.002006.tar.gz ... OK
Configuring Regexp-Debugger-0.002006 ... OK
Building and testing Regexp-Debugger-0.002006 ... OK
Successfully installed Regexp-Debugger-0.002006
1 distribution installed

libpcap 在这里是一个依赖项是有道理的,但我已经安装了它。

[nick@void ~]$ sudo xbps-install libpcap
Package `libpcap' already installed.

非常感谢帮助。

问题出在我的 libpcap 版本上。这个包似乎在 libpcap 1.10 和 1.9.1 上被破坏了。安装 libpcap 1.8 后,软件包构建正常。