tcpdump mailing list archives

Re: Exiting pcap_loop


From: "FZS" <fzs () tabeer org>
Date: Wed, 30 Apr 2003 12:24:15 -0700 (PDT)

Hi Darren,

If switching to pcap_dispatch() instead of pcap_loop() is not a bad option
for you, one other way of doing what you want is use select for timing
out. So you can access the pcap file descriptor and select on it for
either reads or timeouts. When select returns, if read fd_set is set, you
can call pcap_dispatch(), otherwise for timeout you can do your other
tasks.

I would generally prefer doing this to using the singal handling approach.
But I agree given pcap_loop is blocking, if you must use pcap_loop, then
select wont work.

--fzs

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


-
This is the TCPDUMP workers list. It is archived at
http://www.tcpdump.org/lists/workers/index.html
To unsubscribe use mailto:tcpdump-workers-request () tcpdump org?body=unsubscribe


Current thread: