Subject: | A possible fix for 24531 |
I think this will fix the issues with options not being properly passed
into the Pcap functions.
Subject: | PcapPatch.patch |
--- /home/jules/PcapUtils.pm 2008-02-07 13:04:06.000000000 -0600
+++ ./PcapUtils.pm 2008-02-07 13:32:42.000000000 -0600
@@ -76,28 +76,33 @@
# Default arguments
my %args = (
- SNAPLEN => 100, # Num bytes to capture from packet
- PROMISC => 1, # Operate in promiscuous mode?
- TIMEOUT => 1000, # Read timeout (ms)
- NUMPACKETS => -1, # Pkts to read (-1 = loop forever)
- FILTER => '', # Filter string
- USERDATA => '', # Passed as first arg to callback fn
- SAVEFILE => '', # Default save file
- DEV => '', # Network interface to open
- mode => '', # Internal variable
- @rest);
+ 'SNAPLEN' => 100, # Num bytes to capture from packet
+ 'PROMISC' => 1, # Operate in promiscuous mode?
+ 'TIMEOUT' => 1000, # Read timeout (ms)
+ 'NUMPACKETS' => -1, # Pkts to read (-1 = loop forever)
+ 'FILTER' => '', # Filter string
+ 'USERDATA' => '', # Passed as first arg to callback fn
+ 'SAVEFILE' => '', # Default save file
+ 'DEV' => '', # Network interface to open
+ mode => ''); # Internal variable
+
+ my %hash = @rest;
+
+ for my $key ( keys %hash ) {
+ $args{$key}=$hash{$key};
+ }
# Get pcap device if not specified
- if ($args{DEV} eq '') {
- $args{DEV} = Net::Pcap::lookupdev(\$errbuf);
- return $errbuf, unless $args{DEV};
+ if ($args{'DEV'} eq '') {
+ $args{'DEV'} = Net::Pcap::lookupdev(\$errbuf);
+ return $errbuf, unless $args{'DEV'};
}
# Get pcap network/netmask
my($net, $mask);
- return $errbuf, if (Net::Pcap::lookupnet($args{DEV}, \$net, \$mask,
+ return $errbuf, if (Net::Pcap::lookupnet($args{'DEV'}, \$net, \$mask,
\$errbuf) == -1);
#
# Open in specified mode
@@ -105,13 +110,13 @@
my $pcap_desc;
- if ($args{SAVEFILE} eq '') {
+ if ($args{'SAVEFILE'} eq '') {
# Open interface "live"
- $pcap_desc = Net::Pcap::open_live($args{DEV}, $args{SNAPLEN},
- $args{PROMISC},
- $args{TIMEOUT},
+ $pcap_desc = Net::Pcap::open_live($args{'DEV'}, $args{'SNAPLEN'},
+ $args{'PROMISC'},
+ $args{'TIMEOUT'},
\$errbuf);
return $errbuf, unless $pcap_desc;
@@ -120,7 +125,7 @@
# Open saved file
- $pcap_desc = Net::Pcap::open_offline($args{SAVEFILE}, \$errbuf);
+ $pcap_desc = Net::Pcap::open_offline($args{'SAVEFILE'}, \$errbuf);
return $errbuf, unless $pcap_desc;
@@ -128,10 +133,10 @@
# Set up filter, if defined
- if ($args{FILTER} ne '') {
+ if ($args{'FILTER'} ne '') {
return(Net::Pcap::geterr($pcap_desc)),
if ((Net::Pcap::compile($pcap_desc, \$bpf_prog,
- $args{FILTER}, 0, $mask) == -1) ||
+ $args{'FILTER'}, 0, $mask) == -1) ||
(Net::Pcap::setfilter($pcap_desc, $bpf_prog) == -1));
}
@@ -141,8 +146,8 @@
# Call loop function
- my $result = Net::Pcap::loop($pcap_desc, $args{NUMPACKETS},
- \&$callback, $args{USERDATA});
+ my $result = Net::Pcap::loop($pcap_desc, $args{'NUMPACKETS'},
+ \&$callback, $args{'USERDATA'});
Net::Pcap::close($pcap_desc);
if ($result == 0) {
@@ -234,9 +239,9 @@
Given a callback function and a list of optional named parameterss,
open a network interface, configure it, and execute the callback
-function for each packet received on the interface. If the SAVEFILE
+function for each packet received on the interface. If the 'SAVEFILE'
parameter is present, a saved file of that name will be opened for
-reading, else the network interface specified by the DEV parameter
+reading, else the network interface specified by the 'DEV' parameter
will be opened. If no saved file or device is specified, the
interface returned by Net::Pcap::lookupdev() is opened.
@@ -245,14 +250,14 @@
are given below.
my %args = (
- SNAPLEN => 100, # Num bytes to capture from packet
- PROMISC => 1, # Operate in promiscuous mode?
- TIMEOUT => 1000, # Read timeout (ms)
- NUMPACKETS => -1, # Pkts to read (-1 = loop forever)
- FILTER => '', # Filter string
- USERDATA => '', # Passed as first arg to callback fn
- SAVEFILE => '', # Default save file
- DEV => '', # Network interface to open
+ 'SNAPLEN' => 100, # Num bytes to capture from packet
+ 'PROMISC' => 1, # Operate in promiscuous mode?
+ 'TIMEOUT' => 1000, # Read timeout (ms)
+ 'NUMPACKETS' => -1, # Pkts to read (-1 = loop forever)
+ 'FILTER' => '', # Filter string
+ 'USERDATA' => '', # Passed as first arg to callback fn
+ 'SAVEFILE' => '', # Default save file
+ 'DEV' => '', # Network interface to open
);
Consult the documentation for the pcap(3) library for more details on
@@ -292,7 +297,7 @@
print("packet\n");
}
- Net::PcapUtils::loop(\&process_pkt, FILTER => 'ip');
+ Net::PcapUtils::loop(\&process_pkt, 'FILTER' => 'ip');
=head1 SEE ALSO