tcpdump mailing list archives

Exiting pcap_loop


From: TCPDump <tcpdump () intrusense com>
Date: 30 Apr 2003 11:44:53 -0400

Hello,

I'm looking for a portable way to tell pcap_loop to return when it
hasn't received a packet.  I'm using setitimer() to trigger SIGALRM and
execute a function. 
I know there's a timeout value for pcap_open_live() but it's unreliable.


Here's an short example of what I'm doing:


void 
response_timeout()
{
    fprintf(stdout, "No response from peer\n");

    return;
}

main()
{
    struct itimerval timeout;   
   
    memset(&timeout, 0, sizeof(struct itimerval));
 
    /* SET UP PCAP DESCRIPTOR */
    /* SET UP VERY SPECIFIC PCAP FILTER */

    signal(SIGARLM, response_timeout);

    for(;;)
    {
        /* DO STUFF */

       timeout.it_value.tv_sec = 1;
       setitimer(ITIMER_REAL, &timeout, NULL);

        if(pcap_loop(pcap_d, 1, (pcap_handler)process_packets, NULL))
            fatal_error("Problem");
   
        timeout.it_value.tv_sec = 0;
        setitimer(ITIMER_REAL, &timeout, NULL);

        /* DO MORE STUFF */
    }

    return;
}


(I just whipped that up from scratch so please ignore any typos)

Any help would be appreciated. 


Thank you,

Darren

Current thread: