For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > August 2005 > alarm and pcap::loop









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author alarm and pcap::loop
Michael Gale

2005-08-28, 6:55 pm

Hello,

I am having a problem with the following piece of code:

Current Net::Pcap is setup to have a capture limit of 1. So if 1 packet
is received my script exits and prints the message "time out did not
occure. But if a packet arrives after the timeout it prints "time out
occured".

But with use of the alarm function, should it not be exiting after 10
seconds even if a packet has not been received ??


--snip--
&packet_cap_setup();
eval {
local $SIG{ALRM} = sub { die "alarm\n" };
alarm 10;
Net::Pcap::loop($pcap_t, 1, \&packet_cap_process, 'dhcp');
alarm 0;
} ;
if ($@) {
die unless $@ eq "alarm\n";
print "Time out occured\n";
} else {
print "Time out did not occue\n";
}

&packet_cap_close();
--snip--

Thanks

Michael
Michael Gale

2005-08-28, 6:55 pm

Hello,

This is odd ... if I use Proc::Simple to run the sub routine in the
background the alarm works fine. I then simple shutdown the second
process using Proc::Simple's kill function.

Michael



Michael Gale wrote:
> Hello,
>
> I am having a problem with the following piece of code:
>
> Current Net::Pcap is setup to have a capture limit of 1. So if 1 packet
> is received my script exits and prints the message "time out did not
> occure. But if a packet arrives after the timeout it prints "time out
> occured".
>
> But with use of the alarm function, should it not be exiting after 10
> seconds even if a packet has not been received ??
>
>
> --snip--
> &packet_cap_setup();
> eval {
> local $SIG{ALRM} = sub { die "alarm\n" };
> alarm 10;
> Net::Pcap::loop($pcap_t, 1, \&packet_cap_process, 'dhcp');
> alarm 0;
> } ;
> if ($@) {
> die unless $@ eq "alarm\n";
> print "Time out occured\n";
> } else {
> print "Time out did not occue\n";
> }
>
> &packet_cap_close();
> --snip--
>
> Thanks
>
> Michael
>

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com