X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Date: Thu, 20 Dec 2007 19:15:30 -0500 From: Christopher Faylor To: cygwin AT cygwin DOT com Subject: Re: FW: Combining winpcap packet wait with poll/select in cygwin Message-ID: <20071221001530.GA28930@ednor.casa.cgf.cx> Reply-To: cygwin AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com References: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.16 (2007-06-09) Mailing-List: contact cygwin-help AT cygwin DOT com; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Subscribe: List-Archive: List-Post: List-Help: , Sender: cygwin-owner AT cygwin DOT com Mail-Followup-To: cygwin AT cygwin DOT com Delivered-To: mailing list cygwin AT cygwin DOT com 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: >http://cygwin.com/ml/cygwin/2006-10/msg00338.html > >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. cgf -- Unsubscribe info: http://cygwin.com/ml/#unsubscribe-simple Problem reports: http://cygwin.com/problems.html Documentation: http://cygwin.com/docs.html FAQ: http://cygwin.com/faq/