C Board  

Go Back   C Board > General Programming Boards > Networking/Device Communication

Reply
 
LinkBack Thread Tools Display Modes
Old 12-15-2007, 05:29 PM   #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.
B-Con is offline   Reply With Quote
Old 12-15-2007, 10:57 PM   #2
CSharpener
 
vart's Avatar
 
Join Date: Oct 2006
Posts: 5,242
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
__________________
If I have eight hours for cutting wood, I spend six sharpening my axe.
vart is offline   Reply With Quote
Old 01-17-2008, 10:04 PM   #3
Dogbert
 
B-Con's Avatar
 
Join Date: Mar 2004
Posts: 25
From the link:
Quote:
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.
B-Con is offline   Reply With Quote
Old 01-18-2008, 12:57 AM   #4
Registered User
 
Join Date: Sep 2004
Location: California
Posts: 2,805
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.
bithub is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
TCP TimeOut vishal_askqns Windows Programming 1 04-28-2009 07:02 PM
Function argument assignment between types "unsigned int*" and "unsigned long*" nadeer78 C Programming 8 03-10-2008 11:57 AM
how to setup C# TCPClient timeout George2 C# Programming 1 08-13-2007 12:09 PM
rsh timeout jlai Windows Programming 0 06-03-2005 07:18 AM
connect timeout X PaYnE X Networking/Device Communication 8 05-14-2005 09:30 PM


All times are GMT -6. The time now is 03:00 PM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.0 RC2

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