I am trying to make a program, that will parse pcap file until the timer expires. I use alarm
function for that, found here, which really stops the pcap_loop
, but definitely not after given time.
Important parts of code:
pcap_t *handle;
void end_loop(int signum)
{
pcap_breakloop(handle);
}
int main(...){
...
handle = pcap_open_live(argv[2], BUFSIZ, 1, 100, errbuf);
....
signal(SIGALRM, end_loop);
alarm(5);
pcap_loop(handle, num_packets, got_packet, NULL);
pcap_close(handle);
send_syslog_message(hostname, list_of_parsed_packets));
return 0;
}
I have tried running the program many times and it always stops, but as the title says, the time it takes is just random. Am I doing something wrong?