stevehicks has asked for the wisdom of the Perl Monks concerning the following question:

Hi Guys I'm having a real issue understanding what I'm doing wrong here. I'm trying to use "Net::PCap" on a solaris x86 machine :
[mddev@mdsaln01:~/mdscripts/bin] $ uname -a SunOS mdsaln01 5.10 Generic_127127-11 sun4u sparc SUNW,Sun-Fire-V440 [mddev@mdsaln01:~/mdscripts/bin] $
I have install libpcap 0.9.7 :
[mddev@mdsaln01:~/mdscripts/Binaries] $ find . -name \*pcap\* ./lib/libpcap.a ./include/pcap.h ./include/pcap-bpf.h ./include/pcap-namedb.h ./man/man3/pcap.3 [mddev@mdsaln01:~/mdscripts/Binaries] $
and have gone thru the steps of installing Net::Pcap :
[mddev@mdsaln01:/var/tmp/Net-Pcap-0.14] $ make clean;perl Makefile.PL +INC=-I/opt/devel/mdscripts/Binaries/include LIBS=-'L/opt/devel/mdscr +ipts/Binaries/lib -lpcap' PREFIX=/opt/devel/mdscripts/PerlModules make: Fatal error: Don't know how to make target `clean' Set up gcc environment - 3.4.3 (csl-sol210-3_4-branch+sol_rpath) looking for -lpcap... yes checking for pcap_lib_version() in -lpcap... yes trying to detect actually available functions... ok Checking if your kit is complete... Looks good Writing Makefile for Net::Pcap [mddev@mdsaln01:/var/tmp/Net-Pcap-0.14] $ [mddev@mdsaln01:/var/tmp/Net-Pcap-0.14] $ make cp Pcap.pm blib/lib/Net/Pcap.pm AutoSplitting blib/lib/Net/Pcap.pm (blib/lib/auto/Net/Pcap) /usr/bin/perl /opt/ActivePerl-5.10/lib/ExtUtils/xsubpp -typemap /opt/ +ActivePerl-5.10/lib/ExtUtils/typemap -typemap typemap Pcap.xs > Pcap +.xsc && mv Pcap.xsc Pcap.c gcc -c -I/opt/devel/mdscripts/Binaries/include -Wall -O -DVERSION +=\"0.14\" -DXS_VERSION=\"0.14\" -fPIC "-I/opt/ActivePerl-5.10/lib/CO +RE" -DHAVE_BLANK -DHAVE_PCAP_LIB_VERSION -DHAVE_PCAP_BREAKLOOP -DHAV +E_PCAP_COMPILE_NOPCAP -DHAVE_PCAP_DATALINK_NAME_TO_VAL -DHAVE_PCAP_DA +TALINK_VAL_TO_DESCRIPTION -DHAVE_PCAP_DATALINK_VAL_TO_NAME -DHAVE_PCA +P_DUMP_FILE -DHAVE_PCAP_DUMP_FLUSH -DHAVE_PCAP_DUMP_FOPEN -DHAVE_PCAP +_DUMP_FTELL -DHAVE_PCAP_FINDALLDEVS -DHAVE_PCAP_FOPEN_OFFLINE -DHAVE_ +PCAP_FREEALLDEVS -DHAVE_PCAP_GETNONBLOCK -DHAVE_PCAP_GET_SELECTABLE_F +D -DHAVE_PCAP_INJECT -DHAVE_PCAP_LIB_VERSION -DHAVE_PCAP_LIST_DATALIN +KS -DHAVE_PCAP_NEXT_EX -DHAVE_PCAP_OPEN_DEAD -DHAVE_PCAP_SENDPACKET - +DHAVE_PCAP_SETDIRECTION -DHAVE_PCAP_SETNONBLOCK -DHAVE_PCAP_SET_DATAL +INK Pcap.c In file included from Pcap.xs:43: stubs.inc:322:2: warning: #warning "the function pcap_createsrcstr() i +s not available" stubs.inc:337:2: warning: #warning "the function pcap_parsesrcstr() is + not available" stubs.inc:352:2: warning: #warning "the function pcap_open() is not av +ailable" stubs.inc:373:2: warning: #warning "the function pcap_setbuff() is not + available" stubs.inc:388:2: warning: #warning "the function pcap_setuserbuffer() +is not available" stubs.inc:403:2: warning: #warning "the function pcap_setmode() is not + available" stubs.inc:418:2: warning: #warning "the function pcap_setmintocopy() i +s not available" stubs.inc:433:2: warning: #warning "the function pcap_sendqueue_alloc( +) is not available" stubs.inc:455:2: warning: #warning "the function pcap_sendqueue_destro +y() is not available" stubs.inc:469:2: warning: #warning "the function pcap_sendqueue_queue( +) is not available" stubs.inc:484:2: warning: #warning "the function pcap_sendqueue_transm +it() is not available" stubs.inc:499:2: warning: #warning "the function pcap_event() is not a +vailable" stubs.inc:514:2: warning: #warning "the function pcap_setsampling() is + not available" Pcap.c: In function `XS_Net__Pcap_constant': Pcap.c:108: warning: unused variable `Perl___notused' Pcap.c: In function `XS_Net__Pcap_lookupdev': ... Pcap.c:2333: warning: unused variable `Perl___notused' Running Mkbootstrap for Net::Pcap () chmod 644 Pcap.bs rm -f blib/arch/auto/Net/Pcap/Pcap.so gcc -G -L/usr/lib -L/usr/ccs/lib -L/opt/SUNWspro/prod/lib Pcap.o -o +blib/arch/auto/Net/Pcap/Pcap.so \ -L/opt/devel/mdscripts/Binaries/lib -lpcap \ chmod 755 blib/arch/auto/Net/Pcap/Pcap.so cp Pcap.bs blib/arch/auto/Net/Pcap/Pcap.bs chmod 644 blib/arch/auto/Net/Pcap/Pcap.bs cp bin/pcapinfo blib/script/pcapinfo /usr/bin/perl "-MExtUtils::MY" -e "MY->fixin(shift)" blib/script/pcapi +nfo Set up gcc environment - 3.4.3 (csl-sol210-3_4-branch+sol_rpath) Manifying blib/man1/pcapinfo.1 Manifying blib/man3/Net::Pcap.3 [mddev@mdsaln01:/var/tmp/Net-Pcap-0.14] $ echo $? 0 [mddev@mdsaln01:/var/tmp/Net-Pcap-0.14] $ [mddev@mdsaln01:/var/tmp/Net-Pcap-0.14] $ make install Files found in blib/arch: installing files in blib/lib into architectu +re dependent library tree Installing /opt/devel/mdscripts/PerlModules/lib/auto/Net/Pcap/Pcap.so Installing /opt/devel/mdscripts/PerlModules/lib/auto/Net/Pcap/Pcap.bs Installing /opt/devel/mdscripts/PerlModules/html/site/lib/Net/Pcap.htm +l Installing /opt/devel/mdscripts/PerlModules/lib/Net/Pcap.pm Installing /opt/devel/mdscripts/PerlModules/lib/auto/Net/Pcap/autospli +t.ix Installing /opt/devel/mdscripts/PerlModules/man/man3/Net::Pcap.3 Appending installation info to /opt/devel/mdscripts/PerlModules/lib/pe +rllocal.pod [mddev@mdsaln01:/var/tmp/Net-Pcap-0.14] $
The module is definitely installed :
[mddev@mdsaln01:~/mdscripts] $ find . -name \*Pcap\* ./PerlModules/lib/auto/Net/Pcap ./PerlModules/lib/auto/Net/Pcap/Pcap.so ./PerlModules/lib/auto/Net/Pcap/Pcap.bs ./PerlModules/lib/Net/Pcap.pm ./PerlModules/html/site/lib/Net/Pcap.html ./PerlModules/man/man3/Net::Pcap.3 [mddev@mdsaln01:~/mdscripts] $
and I have my PERL5LIB set right :
[mddev@mdsaln01:~/mdscripts] $ echo $PERL5LIB /opt/devel/mdscripts/PerlModules/lib [mddev@mdsaln01:~/mdscripts] $
However when I run this sample code(which is directly out of the module !!) :
#!/usr/bin/perl use Net::Pcap; my $err = ''; my $dev = pcap_lookupdev(\$err); # find a device # open the device for live listening my $pcap = pcap_open_live($dev, 1024, 1, 0, \$err); # loop over next 10 packets pcap_loop($pcap, 10, \&process_packet, "just for the demo"); # close the device pcap_close($pcap); sub process_packet { my($user_data, $header, $packet) = @_; # do something ... }
it fails with :
[mddev@mdsaln01:~/mdscripts/bin] $ ./pcapTest.pl Undefined subroutine &main::pcap_lookupdev called at ./pcapTest.pl lin +e 6. [mddev@mdsaln01:~/mdscripts/bin] $
I'm not a complete n00b and I use modules all the time and I can't see that I'm doing anything wrong but it doesn't work and I don't know what to do. I've already burned 4 hours on this and I'm way behind where I should be. Any pointers would be really really appreciated !!
  • Comment on "Undefined subroutine &main::pcap_lookupdev called" yet module installed and PERL5LIB is set correctly : *(
  • Select or Download Code

Replies are listed 'Best First'.
Re: "Undefined subroutine &main::pcap_lookupdev called" yet module installed and PERL5LIB is set correctly : *(
by ikegami (Patriarch) on Jun 10, 2009 at 14:25 UTC

    The Synopsis is misleading. Net::Pcap only exports some constants by default, no functions. Try

    use Net::Pcap qw( :functions );
      Hi Thanks for your help. I tried "use Net::Pcap qw( :all );" and got :
      [mddev@mdsaln01:~/mdscripts/bin] $ ./pcapTest.pl "all" is not defined in %Net::Pcap::EXPORT_TAGS at ./pcapTest.pl line +3 main::BEGIN() called at /opt/devel/mdscripts/PerlModules/lib/N +et/Pcap.pm line 3 eval {...} called at /opt/devel/mdscripts/PerlModules/lib/Net/ +Pcap.pm line 3 Can't continue after import errors at ./pcapTest.pl line 3 BEGIN failed--compilation aborted at ./pcapTest.pl line 3. [mddev@mdsaln01:~/mdscripts/bin] $ </code ..and I tried :functions instead and got the same as at the beginning +: <code> [mddev@mdsaln01:~/mdscripts/bin] $ ./pcapTest.pl Undefined subroutine &main::pcap_lookupdev called at ./pcapTest.pl lin +e 7. [mddev@mdsaln01:~/mdscripts/bin] $
      : ((
        oops, should be :functions, not :all. Fixed
Re: "Undefined subroutine &main::pcap_lookupdev called" yet module installed and PERL5LIB is set correctly : *(
by Anonymous Monk on Jun 10, 2009 at 14:24 UTC
    Try Net::Pcap::pcap_lookupdev()
      Hi Thanks. When I try that though I get :
      [mddev@mdsaln01:~/mdscripts/bin] $ ./pcapTest.pl pcap_lookupdev is not a valid pcap macro at ./pcapTest.pl line 7 [mddev@mdsaln01:~/mdscripts/bin] $
Re: "Undefined subroutine &main::pcap_lookupdev called" yet module installed and PERL5LIB is set correctly : *(
by ikegami (Patriarch) on Jun 10, 2009 at 19:47 UTC
    What about make test?