This is the mail archive of the cygwin mailing list for the Cygwin project.

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: FW: Combining winpcap packet wait with poll/select in cygwin

On Thu, Dec 20, 2007 at 04:04:11PM -0800, S A wrote:
>Hi Brian 
>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
>packets received).
>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;
> =  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:
Problem reports:

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]