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

Fellow monks, I've just started using Net::Pcap. I read the tutorial and the CPAN documentation. My syntax and usage of the lookupdev() and findalldevs() methods seems normal. However, when I run this script under linux, my script does not find any devices! At the same time, the exact same script running in Windows works just fine (except that lib_version() method seems to not be implemented). I can't help but wonder if this has anything to do with the pcap library on my linux installation (version 0.9.1). Does anyone have any ideas?

use strict; use Net::Pcap; $|++; my $err; print "pcap version " . Net::Pcap::lib_version() . "\n"; my %devinfo; my @devs = Net::Pcap::findalldevs(\$err, \%devinfo); if (defined $err) { die 'Unable to determine network device for monitoring - ', $err; } my $choice; do { print "Please choose a device to monitor:\n"; my $i = 0; for my $dev (@devs) { print ++$i . " - $dev : $devinfo{$dev}\n" } print "Choice: "; $choice = <>; } while ($choice<1 or $choice>scalar(@devs));

Replies are listed 'Best First'.
Re: Net::Pcap lookupdev problem
by Anonymous Monk on Apr 12, 2006 at 13:40 UTC

    I haven't run your code, but wish to comment something anyway. When I run the Ethereal desktop app in Linux, it also doesn't list the network interfaces/devices, unless running with superuser privileges.

      Thanks. That was exactly it. Silly me, I forgot about privileges.
        I am running the below program x0004276@wipultra361 /cygdrive/T/gen/perl/activestate/5_8_6_811/site/lib/Net-Pca p-0.04 $ perl pktdump.pl "functions" is not defined in %Net::Pcap::EXPORT_TAGS at pktdump.pl line 4 main::BEGIN() called at /usr/lib/perl5/site_perl/5.8/cygwin/Net/Pcap.pm line 4 eval {...} called at /usr/lib/perl5/site_perl/5.8/cygwin/Net/Pcap.pm lin e 4 Can't continue after import errors at pktdump.pl line 4 BEGIN failed--compilation aborted at pktdump.pl line 4. I have installed the Net::Pcap recently. But when i run the above program it fails. please let me know if this is a privilage problem or the installation is not complete. please help. I have used cygwin