tcpdump mailing list archives
pcap_dispatch() using non-blocking I/O
From: "TCPdump" <tcpdump () intrusense com>
Date: Tue, 6 May 2003 23:00:35 -0400
Hello,
I'm having some portability problems with pcap_dispatch() on FreeBSD
4.8-STABLE. I doubt the problem is specific to FreeBSD, however, at the
moment I only have Redhat 9 and FreeBSD 4.8 environments to test on.
The problem is simply that I can't seem to get pcap_dispatch() to block
and based on the pcap man page and from what I've read on Google, it
should be the default (even on FreeBSD).
As a side note: When I use pcap_setnonblock() to force blocking I/O,
pcap_dispatch() still returns without any delay.
The code I'm working with runs flawlessly on my Redhat 9 machine.
Here's an example of what I'm doing:
--- START SNIPPET ---
void
response_timeout()
{
fprintf(stdout, "-- timeout --\n");
if(pcap_setnonblock(pkt, 1, error_buf) < 0)
fatal_error("bad\n");
return;
}
void
my_example_func(pcap_t *pkt);
{
struct bpf_program bpf;
struct itimerval timeout;
signal(SIGALRM, response_timeout);
/* setup pcap with very specific filter */
if(pcap_setnonblock(pkt, 0, error_buf) < 0)
fatal_error("bad\n");
timeout.it_value.tv_sec = 2;
setitimer(ITIMER_REAL, &timeout, NULL);
if(pcap_dispatch(pkt, 1, (pcap_handler)process_packets, NULL) < 0)
fatal_error("bad\n"):
/* I've also used pcap_dispatch(pkt, -1,
(pcap_handler)process_packets, NULL); */
timeout.it_value.tv_sec = 0;
setitimer(ITIMER_REAL, &timeout, NULL);
/* do other stuff */
return;
}
--- END SNIPPET ---
The goal here (and it works in Linux) is to have pcap_dispatch() wait
for a packet until setitimer() sends SIGALRM. response_timeout() will
then put pcap_dispatch() into non-blocking mode, which will then return
and continue, disabling the setitimer() in the process.
Any help would be greatly appreciated,
Darren Bounds
-
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:
- pcap_dispatch() using non-blocking I/O TCPdump (May 06)
- Re: pcap_dispatch() using non-blocking I/O Guy Harris (May 07)
