How to use pcap_breakloop?

I have a pcap_loop function in another function that captures packets until the user stops it, i.e.

void functionA()
{
   signal(SIGINT, terminate_process); 
   pcap_loop(handle, -1, callback, NULL);
   ...

}

void terminate_process(int signum)
{
   pcap_breakloop(handle);
   pcap_close(handle);
} 

      

Is it possible to set the duration when the packets will be captured? Something like:

if (time(NULL) - start_time > 100)
   pcap_breakloop(handle);

      

But I don't know where to put this, because so far all the examples I've seen have used pcap_breakloop in a signal handler, which requires user intervention. How will the time be checked while pcap_loop is running?

Thank.

Regards, Rayne

+2


source to share


1 answer


You can use alarm to generate an alarm after a certain number of seconds:



void functionA()
{
    signal(SIGALRM, terminate_process); 
    alarm(100);
}

      

+2


source







All Articles