[Winpcap-users] How to combine pcap_next_ex with poll/select incygwin

Gianluca Varenni gianluca.varenni at cacetech.com
Wed Dec 12 21:44:44 GMT 2007


Unfortunately you cannot obtain a file descriptor you can wait on with WinPcap. There's simply no file descriptor. As far as WinPcap is concerned, you can only obtain a win32 HANDLE with pcap_getevent() and wait on it with WaitForSingleObject/MultipleObjects(Ex). Can you obtain a wait HANDLE from a socket handle?

Have a nice day
GV

  ----- Original Message ----- 
  From: S A 
  To: winpcap-users at winpcap.org 
  Sent: Wednesday, December 12, 2007 11:18 AM
  Subject: [Winpcap-users] How to combine pcap_next_ex with poll/select incygwin


  Hi all
     
  My question is about trying to figure out how to use winpcap and poll ()/select () together                                                                            in a cygwin environment.
      
  The Linux program I'm trying to port, waits for a telnet connection to establish  a connection to a 
  user on a local port number (i.e. localhost). The user can then choose to send/receive raw packets 
  (of any ethernet type - hence the need for raw sockets via winpcap) on any of the network devices 
  on the machine. 

  My dilemma is how to make the poll/select call i use (to wait for an incoming telnet connection
  and further interaction with the user) and combine it with using pcap_next_ex() to receive
  raw packets.

  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. Is there a way
  I can translate a winpcap socket pcap_t handle into an fd that I could pass to the poll/select fd list?
  Or vice versa - translate cygwin fd's into pcap handles?

  (Although the brief browsing I did in the winpcap sources I only saw a call to WaitForSingleObject() though)

  My only other options (none of which I like) are:

  1. Use threads. Multiple processes won't work because the telnet program and the raw socket
     program would have to interact with each other - and wouldn't that mean more localhost connections
     unless I use some kind of proc or ioctl interface?

  2. Use winpcap to also receive IP packets and thus handle the telnet protocol in my program.
      However this is unnnecessarily complex and I don't even see the pcap_findalldevs
      presenting me with a localhost device (i.e. the equivalent of the "loopback" or "lo" netdev in linux).

  3. Use a maximum wait time on both the poll call and the pcap_next_ex call. I'm afraid my
      program will get sluggish and also eat up a lot of CPU cycles.

  Any recommendations on what to do or more code to look at are greatly welcomed. Thanks!
  And thanks for all the great open source work.



------------------------------------------------------------------------------
  Don't get caught with egg on your face. Play Chicktionary! Check it out! 


------------------------------------------------------------------------------


  _______________________________________________
  Winpcap-users mailing list
  Winpcap-users at winpcap.org
  https://www.winpcap.org/mailman/listinfo/winpcap-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://www.winpcap.org/pipermail/winpcap-users/attachments/20071212/65cb78df/attachment.htm


More information about the Winpcap-users mailing list