This is the mail archive of the
mailing list for the Cygwin project.
Re: FW: Combining winpcap packet wait with poll/select in cygwin
- From: Christopher Faylor <cgf-use-the-mailinglist-please at cygwin dot com>
- To: cygwin at cygwin dot com
- Date: Thu, 20 Dec 2007 19:15:30 -0500
- Subject: Re: FW: Combining winpcap packet wait with poll/select in cygwin
- References: <BAY128-W147E0BFF22B2B5B0D232D3D25D0@phx.gbl> <BAY128-W5EB009802E2D5C2A2D722D25E0@phx.gbl>
- Reply-to: cygwin at cygwin dot com
On Thu, Dec 20, 2007 at 04:04:11PM -0800, S A wrote:
>Finally got a change to try this (sorry it tooks so long). It looks like it does NOT work.
>The fd returned from cygwin_attach_handle_to_fd() always returns
>from the poll call with a POLLIN event even though no packets
>are flowing on the network (and hence there should be no pcap
>The code I used is attached below. I tried both blocking and non blocking
>fcntl calls. But the poll awakes immediately all the time. If I try
>to do a read of the fd, read returns a -1.
>I also found another thread:
>I didn't know what exactly to pass as the name (i.e. the first argument
>to cygwin_attach_handle_to_fd()) but I tried NULL, "", "/dev/fd").
>Maybe I need to pass the right type of device for a windows socket. Just can't
>find what it is. I've looked at all the fhandler_base classes & derivatives
>but can't seem to locate the "name" field. But I don't know C++ that well.
>I'd be happy to try any other suggestions. Thanks.
>main (int argc, char *argv)
> pcap_t *adhandle;
> int pcap_fd;
> struct pollfd pcap_pfd;
> int i, ret;
> [initialization for winpcap adhandle]
> pcap_fd = cygwin_attach_handle_to_fd("/dev/fd", -1, pcap_getevent(adhandle),
> O_BINARY, GENERIC_READ);
> fcntl(pcap_fd, F_SETFL, O_NONBLOCK);
> pcap_pfd.fd = pcap_fd;
> pcap_pfd.events = POLLIN;
> pcap_pfd.revents = 0;
I doubt that a random handle will be selectable. Cygwin needs to
know specifically what type of device is attached to a handle in
order to emulate select or poll and a raw windows handle is not
apt to work well.
In other words, it's unlikely that you can successfully use the result
of cygwin_attach_handle_to_fd in a select or poll function.
Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple
Problem reports: http://cygwin.com/problems.html