Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Stopping pcap_loop and return to main function

4,090 views
Skip to first unread message

lance...@yahoo.com

unread,
Mar 3, 2010, 9:06:48 PM3/3/10
to
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

unread,
Mar 3, 2010, 10:24:35 PM3/3/10
to
In article
<b371593b-eeee-4f63...@k5g2000pra.googlegroups.com>,
"lance...@yahoo.com" <lance...@yahoo.com> wrote:

pcap_breakloop()

--
Barry Margolin, bar...@alum.mit.edu
Arlington, MA
*** PLEASE don't copy me on replies, I'll read them in the group ***

lance...@yahoo.com

unread,
Mar 3, 2010, 10:51:46 PM3/3/10
to
On Mar 4, 11:24 am, Barry Margolin <bar...@alum.mit.edu> wrote:
> In article
> <b371593b-eeee-4f63-beea-4c69afac1...@k5g2000pra.googlegroups.com>,

>
> "lancer6...@yahoo.com" <lancer6...@yahoo.com> wrote:
> > 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, bar...@alum.mit.edu
> 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.

lance...@yahoo.com

unread,
Mar 4, 2010, 12:59:48 AM3/4/10
to
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

unread,
Mar 4, 2010, 6:46:24 AM3/4/10
to

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 .

lance...@yahoo.com

unread,
Mar 4, 2010, 10:12:05 PM3/4/10
to
On Mar 4, 7:46 pm, Jorgen Grahn <grahn+n...@snipabacken.se> wrote:

Thanks! That works. I must have missed that part in the manual.

kothari...@gmail.com

unread,
Jun 10, 2014, 7:02:26 AM6/10/14
to
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

unread,
Jun 10, 2014, 10:32:26 AM6/10/14
to
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

unread,
Jun 10, 2014, 3:32:39 PM6/10/14
to
On Tue, 2014-06-10, kothari...@gmail.com wrote:
> hello,
>
> I have libpcap version 0.6 and it has no pcap_breakloop(), and i
> cannot update,

Surely you can link statically to a newer version?

> now how can I stop pcap_loop() without using
> pcap_breakloop?

I don't remember how ancient versions of libpcap worked -- modern
versions have pcap_get_selectable_fd() and pcap_next_ex() so you can
have full control yourself over the event loop. Did 0.6 not have
that?

You could also read the sources and look at how pcap_loop() is
implemented, and maybe get some ideas.
0 new messages