libpcap: How to timeout pcap_loop() ?

This is a discussion on libpcap: How to timeout pcap_loop() ? within the Networking/Device Communication forums, part of the General Programming Boards category; I'm using the libpcap library to sniff packets on an interface. (My target OS is Linux, but I don't think ...

  1. #1
    Dogbert B-Con's Avatar
    Join Date
    Mar 2004
    Posts
    25

    libpcap: How to timeout pcap_loop() ?

    I'm using the libpcap library to sniff packets on an interface. (My target OS is Linux, but I don't think that helps here.)

    I'm using pcap_loop() to capture packets, but pcap_loop() waits until a packet is captured before returning to the calling function. Is there any way to force it to only listen for a specified amount of time? I'd like to loop the main program while just checking each loop for new packets, rather than having to wait for a new packet to arrive before doing anything. I've looked around and am pretty sure there's no built-in feature for this (that works on Linux) so might there exist some type of work-around?
    "Cryptographically secure linear feedback shift register based stream ciphers" -- a phrase that'll get any party started.

  2. #2
    CSharpener vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,484
    probably you want to look something in inet like
    http://www.tcpdump.org/lists/workers.../msg00178.html

    Haven't read it throughoutly but seems to me they are talking about same type of problems
    The first 90% of a project takes 90% of the time,
    the last 10% takes the other 90% of the time.

  3. #3
    Dogbert B-Con's Avatar
    Join Date
    Mar 2004
    Posts
    25
    From the link:
    If switching to pcap_dispatch() instead of pcap_loop() is not a bad option
    for you, one other way of doing what you want is use select for timing
    out. So you can access the pcap file descriptor and select on it for
    either reads or timeouts. When select returns, if read fd_set is set, you
    can call pcap_dispatch(), otherwise for timeout you can do your other
    tasks.
    What's this "select" he's talking about?

    (BTW, sorry for taking so long to return, holidays+travel+start of school kept me busy. :P )
    "Cryptographically secure linear feedback shift register based stream ciphers" -- a phrase that'll get any party started.

  4. #4
    Registered User
    Join Date
    Sep 2004
    Location
    California
    Posts
    3,265
    select() is a function which allows you to wait on I/O. It would allow you to check if there is data to be read on a socket, and then time out if there is nothing to receive.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. TCP TimeOut
    By vishal_askqns in forum Windows Programming
    Replies: 1
    Last Post: 04-28-2009, 08:02 PM
  2. Replies: 8
    Last Post: 03-10-2008, 12:57 PM
  3. how to setup C# TCPClient timeout
    By George2 in forum C# Programming
    Replies: 1
    Last Post: 08-13-2007, 01:09 PM
  4. rsh timeout
    By jlai in forum Windows Programming
    Replies: 0
    Last Post: 06-03-2005, 08:18 AM
  5. connect timeout
    By X PaYnE X in forum Networking/Device Communication
    Replies: 8
    Last Post: 05-14-2005, 10:30 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21