Discussion:
Stopping pcap_loop and return to main function
(too old to reply)
l***@yahoo.com
2010-03-04 02:06:48 UTC
Permalink
Hi all,

I have a pcap_loop function in another function, that captures packets
until the user stops it, i.e.
void functionA()
{
pcap_loop(handle, -1, callback, NULL);
...
}

Is it possible to stop the packet capturing process, and return to
functionA()? I've used Ctrl-C but that just terminates the whole
program.

Thank you.

Regards,
Rayne
Barry Margolin
2010-03-04 03:24:35 UTC
Permalink
In article
Post by l***@yahoo.com
Hi all,
I have a pcap_loop function in another function, that captures packets
until the user stops it, i.e.
void functionA()
{
pcap_loop(handle, -1, callback, NULL);
...
}
Is it possible to stop the packet capturing process, and return to
functionA()? I've used Ctrl-C but that just terminates the whole
program.
pcap_breakloop()
--
Barry Margolin, ***@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***
l***@yahoo.com
2010-03-04 03:51:46 UTC
Permalink
Post by Barry Margolin
In article
Post by l***@yahoo.com
Hi all,
I have a pcap_loop function in another function, that captures packets
until the user stops it, i.e.
void functionA()
{
pcap_loop(handle, -1, callback, NULL);
...
}
Is it possible to stop the packet capturing process, and return to
functionA()? I've used Ctrl-C but that just terminates the whole
program.
pcap_breakloop()
--
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***
I have something like

void functionA()
{
signal(SIGINT, terminate_process);
pcap_loop(handle, -1, got_packet, NULL);
...
}

void terminate_process(int signum)
{
pcap_breakloop(handle);
pcap_close(handle);
}

But Ctrl-C still exits the whole program. I should mention that the
program should run on a Windows system, and I'm not very familar with
the signals used to terminate functions.
l***@yahoo.com
2010-03-04 05:59:48 UTC
Permalink
Also, is it possible to set a duration for when packets would be
captured? Something like:

if (time(NULL) - start_time > 100)
pcap_breakloop(handle);

But I don't know where to put this, because so far all the example
I've seen used pcap_breakloop in a signal handler, which requires user
intervention. How will the time condition be checked while pcap_loop
is running?
Jorgen Grahn
2010-03-04 11:46:24 UTC
Permalink
Post by l***@yahoo.com
Also, is it possible to set a duration for when packets would be
if (time(NULL) - start_time > 100)
pcap_breakloop(handle);
But I don't know where to put this, because so far all the example
I've seen used pcap_breakloop in a signal handler, which requires user
intervention. How will the time condition be checked while pcap_loop
is running?
All the examples maybe, but you can surely call pcap_breakloop() from
your pcap_loop callback. It is clearly documented in the pcap(3)
manual page -- I hope you have read that?

(The man page talks a lot about using it in signal handlers, but
that's just because it's a trickier case.)

/Jorgen
--
// Jorgen Grahn <grahn@ Oo o. . .
\X/ snipabacken.se> O o .
l***@yahoo.com
2010-03-05 03:12:05 UTC
Permalink
Post by Jorgen Grahn
Post by l***@yahoo.com
Also, is it possible to set a duration for when packets would be
if (time(NULL) - start_time > 100)
pcap_breakloop(handle);
But I don't know where to put this, because so far all the example
I've seen used pcap_breakloop in a signal handler, which requires user
intervention. How will the time condition be checked while pcap_loop
is running?
All the examples maybe, but you can surely call pcap_breakloop() from
your pcap_loop callback. It is clearly documented in the pcap(3)
manual page -- I hope you have read that?
(The man page talks a lot about using it in signal handlers, but
that's just because it's a trickier case.)
/Jorgen
--
\X/ snipabacken.se> O o .
Thanks! That works. I must have missed that part in the manual.
k***@gmail.com
2014-06-10 11:02:26 UTC
Permalink
hello,

I have libpcap version 0.6 and it has no pcap_breakloop(), and i cannot update, now how can I stop pcap_loop() without using pcap_breakloop?
Kristof Provost
2014-06-10 14:32:26 UTC
Permalink
Post by k***@gmail.com
I have libpcap version 0.6 and it has no pcap_breakloop(), and i
cannot update, now how can I stop pcap_loop() without using
pcap_breakloop?
Are your sure about the 0.6 bit? libpcap 0.6 is 13 years old at this
point, so I don't know how much support you're going to get for such an
old version.

Regards,
Kristof
Jorgen Grahn
2014-06-10 19:32:39 UTC
Permalink
This post might be inappropriate. Click to display it.
Loading...