X-Recipient: archive-cygwin AT delorie DOT com X-Spam-Check-By: sourceware.org Message-ID: From: S A To: , Subject: FW: Combining winpcap packet wait with poll/select in cygwin Date: Thu, 20 Dec 2007 16:04:11 -0800 In-Reply-To: References: Content-Type: text/plain; charset="Windows-1252" MIME-Version: 1.0 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 Content-Transfer-Encoding: 8bit X-MIME-Autoconverted: from quoted-printable to 8bit by delorie.com id lBL04Saq027723 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; while (1) { pcap_pfd.fd = pcap_fd; pcap_pfd.events = POLLIN; pcap_pfd.revents = 0; ret = poll(&pcap_pfd, 1, -1); if (ret> 0) { if (pcap_pfd.revents) { fprintf(stdout, "fd %d is awake on events %x\n", pcap_pfd.fd, pcap_pfd.revents); } else if (ret == 0) { printf("poll timeout!\n"); } else if (ret < 0) { printf("poll errno=%d, %s\n", errno, strerror(errno)); } } } ========================================================================= > Summary: Has anyone tried to have events (POLL_IN/POLL_OUT) on regular > fd descriptors combined with winpcap packet receive handles > incorporated into the same sleep event (i.e. poll/select)? No, I haven't tried because it looked too fragile if it even works, and Cygwin's poll/select (or the preamble to read/recv; I'm not sure yet) was causing significant packet reception jitter in my real time application. > I know very little of windows but I understand both winpcap & cygwin > poll (winsup/cygwin/select.cc right?) use a call "WaitForMultipleObjects > ()" to sleep and wait for new receive events. I've seen some of the code > in select.cc but is there an easy way to translate the fd's into the > HANDLE w4 array so I can somehow combine it with the winpcap HANDLE)? You could try get_osfhandle, but I'd suggest going the other way around by using Cygwin's cygwin_attach_handle_to_fd. I don't know if it will work for you, but this might get you an fd that you can use in poll/select for the winpcap handle. > My only other options (none of which I like) are: > > 1. Use threads. I went this route and it worked out well for me, but my application was already threaded, and it didn't have this kind of interaction. > 2. Use winpcap to also receive IP packets and thus handle the telnet > protocol in my program. However this is unnnecessarily complex. Why did you choose this strange localhost telnet IPC to begin with? Couldn't it just be a library? I guess it might be because of privilege issues? > Any recommendations on what to do or more code to look at are greatly > welcomed. Thanks! I would appreciate you letting us know how it turns out. -- Brian Ford Lead Realtime Software Engineer VITAL - Visual Simulation Systems FlightSafety International the best safety device in any aircraft is a well-trained crew... ============================================================================== ________________________________ Get the power of Windows + Web with the new Windows Live. Get it now! _________________________________________________________________ i’m is proud to present Cause Effect, a series about real people making a difference. http://im.live.com/Messenger/IM/MTV/?source=text_Cause_Effect -- 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/