Wiggins has asked for the wisdom of the Perl Monks concerning the following question:
Since the interface was eth3, I thought there might be some assumptions that were failing or other defaults in selecting the device. I had installed Net::Pcap through apt-get because it had hung in the very same test. So I used the sample code from the Net::Pcap manual page and added printouts of all of the possible devices:
The surprising result was:use Net::Pcap; my $err = '';# storsge string fille by sub error my %devinfo; my @devs = Net::Pcap::pcap_findalldevs(\%devinfo, \$err); for my $dev (@devs) { print "$dev : $devinfo{$dev}\n"; } exit;
The '01-loop' test program simply does:tuser@desktop:~/Pcap$ sudo perl testNetPcap-2.pl usbmon1 : USB bus number 1 usbmon2 : USB bus number 2 eth3 : No description available any : Pseudo-device that captures on all interfaces lo : Loopback device tuser@desktop:~/Pcap$
Net::PcapUtils::loop calls Net::Pcap::lookupdev, which, in the absence of a specific device returns the first entry in the list ('usbmon1'). If This means it was reading the 'Uusbon1' interface, and not the Ethernet interface.my $result = Net::PcapUtils::loop(\&process_pkt); if (!$result eq "") { print("$result\n"); }
This may be a reason that both of these packages install failed. They weren't accessing the correct interface. Why the USB interfaces are on the list is a deeper problem that I can handle. I am dropping PcapUtils because it won't pass it's test, and have installed Pcap through the 'apt-get' packages. Then I modified the test program:
And it ran fine.my $eth; my @devs = Net::Pcap::pcap_findalldevs(\%devinfo, \$err); for my $dev (@devs) { print "$dev : $devinfo{$dev}\n"; if ( ! $eth && $dev=~/eth/){ $eth=$dev;} } print " eth=<$eth>\n";
It is always better to have seen your target for yourself, rather than depend upon someone else's description.
|
|---|