Guy,
I decided to test my luck today, and after your advice
I did this:
$psize = 100; # nasty assumption, but it should work...
$timeout = 0;
$last_seq = 0;
my $a = new Net::RawIP;
my $pcap = $a->pcapinit($dev, $filter, $psize, $timeout);
my $pcap_fd = fileno($pcap);
fcntl($pcap_fd, F_SETFL, O_NONBLOCK);
my $pcap_pkthdr = "x" x 16; # sizeof(struct pcap_stat)
my $pkt;
while(1) {
$pkt = &next($pcap, $pcap_pkthdr);
print "!";
cb("", $pcap_pkthdr, $pkt);
}
-----
Unfortunatelly, it is blocking....
strace is showing:
recvfrom(3,
and stops here......
Any suggestions?
I would like to upgrade to libpcap 0.7, but then I would have
to modify Net::RawIP to use pcap_setnonblock(), and I don't really
know, how to modify .xs files.....
Thanks,
Przemek
On Tue, 2002-07-16 at 14:21, Guy Harris wrote:
> On Tue, Jul 16, 2002 at 11:29:42AM -0400, Przemyslaw Karwasiecki wrote:
> > My major problem is, how (if at all possible) use pcap in nonblocking
> > mode,
>
> In libpcap 0.7 and later, there are "pcap_setnonblock()" and
> "pcap_getnonblock()" calls, to turn non-blocking mode on and off on a
> live-capture pcap_t.
>
> In earlier versions, on UNIX, you can probably just set the O_NONBLOCK
> flag on the file descriptor for the pcap_t - use "pcap_fileno()" to get
> the file descriptor. (That is not guaranteed to work in the future -
> for example, it won't work if libpcap is using the memory-mapped capture
> buffer feature from Linux 2.4, as reads aren't done on the file
> descriptor - so, for UNIX, you should use autoconf to determine whether
> the libpcap you're using has "pcap_setnonblock()" and
> "pcap_getnonblock()" and, if it doesn't, supply your own routines that
> use the O_NONBLOCK stuff.)
>
> In non-blocking mode, reads from a live-capture "pcap_t" will be
> non-blocking.
>
> > so my application will have main event loop processing
> > in non-blocking mode, both pcap_next packets, and SNMP requests?
>
> On UNIX, you'd do a "select()" or "poll()" on the file descriptor from
> "pcap_fileno()" and the file descriptor of the socket on which the SNMP
> requests arrive.
>
> Note, however, that "select()" and "poll()" don't necessarily work on
> BPF devices in BSD. A workaround is to have a timeout on the "select()"
> or "poll()", equal to the timeout you supplied to "pcap_open_live()",
> and attempt to read from the pcap_t if either
>
> 1) its file descriptor can be read, according to "select()" or
> "poll()"
>
> or
>
> 2) the timeout expired.
>
> Note also that this might not work on FreeBSD 4.5 - I've yet to figure
> out whether it's possible to make that type of non-blocking I/O work
> there.
> -
> This is the TCPDUMP workers list. It is archived at
> http://www.tcpdump.org/lists/workers/index.html
> To unsubscribe use mailto:[EMAIL PROTECTED]?body=unsubscribe
-
This is the TCPDUMP workers list. It is archived at
http://www.tcpdump.org/lists/workers/index.html
To unsubscribe use mailto:[EMAIL PROTECTED]?body=unsubscribe