Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re: no timeout in Net::Pcap::Easy

by VinsWorldcom (Parson)
on Mar 27, 2014 at 17:24 UTC ( #1079966=note: print w/replies, xml ) Need Help??


in reply to no timeout in Net::Pcap::Easy

Check the man page for 'pcap'. It specifies that the 'timeout' should not be relied upon as it is not supported on all platforms.

To get around this and capture with a timeout, I've done the following with some success:

use Net::Pcap; my $device = ... my $snaplen = ... my $timeout = ... * 1000 # in milliseconds * 1000 = seconds my $err; my $pcaprecv = Net::Pcap::pcap_open_live($device, $snaplen, 1, $timeou +t, \$err); my $recv_r; my %header; my $starttime = time; while (1) { my $ret = Net::Pcap::pcap_next_ex($pcaprecv, \%header, \$recv_r); if ($ret == 1) { # Found packet - do stuff } elsif ($ret == 0) { print "[Receive Timeout] "; last } else { print "[Receive Error] "; last } if ((time - $starttime) >= $timeout) { print "[Receive Timeout] "; last } }

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1079966]
help
Chatterbox?
and a log crumbles through the grate...

How do I use this? | Other CB clients
Other Users?
Others cooling their heels in the Monastery: (4)
As of 2017-11-18 07:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    In order to be able to say "I know Perl", you must have:













    Results (277 votes). Check out past polls.

    Notices?