I am writing a PERL script, which captures packets, and then generate statistics in every second about all the TCP streams, which were online in that second. I am using NET::Pcap, and I want somehow to implement this, and if it's possible without using threads. I've tried with select(), and with pcap_breakloop(), but it doesn't semmed to work.
I was thinking of:
...
$pcap = pcap_open_live($dev, 1024, 1, 0, \$err);
select($pcap, undef, undef, 1)
if 1 sec elapsed print a line with data maintained by the pcap_callback function,
and go back to pcap_loop
Do you have any idea how to solve this problem? I am not sure that I should use select, but I don't have any better idea, I am new to PERL. The reason I have chosen select, that I need to generate statistics even if there is no traffic.
For example I want to print the transmitted bytes in every second, then I need to generate total zero lines as well.
Any help would be appreciated :)