|
Packit |
209cc3 |
.\" Copyright (c) 1994, 1996, 1997
|
|
Packit |
209cc3 |
.\" The Regents of the University of California. All rights reserved.
|
|
Packit |
209cc3 |
.\"
|
|
Packit |
209cc3 |
.\" Redistribution and use in source and binary forms, with or without
|
|
Packit |
209cc3 |
.\" modification, are permitted provided that: (1) source code distributions
|
|
Packit |
209cc3 |
.\" retain the above copyright notice and this paragraph in its entirety, (2)
|
|
Packit |
209cc3 |
.\" distributions including binary code include the above copyright notice and
|
|
Packit |
209cc3 |
.\" this paragraph in its entirety in the documentation or other materials
|
|
Packit |
209cc3 |
.\" provided with the distribution, and (3) all advertising materials mentioning
|
|
Packit |
209cc3 |
.\" features or use of this software display the following acknowledgement:
|
|
Packit |
209cc3 |
.\" ``This product includes software developed by the University of California,
|
|
Packit |
209cc3 |
.\" Lawrence Berkeley Laboratory and its contributors.'' Neither the name of
|
|
Packit |
209cc3 |
.\" the University nor the names of its contributors may be used to endorse
|
|
Packit |
209cc3 |
.\" or promote products derived from this software without specific prior
|
|
Packit |
209cc3 |
.\" written permission.
|
|
Packit |
209cc3 |
.\" THIS SOFTWARE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
|
|
Packit |
209cc3 |
.\" WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
|
|
Packit |
209cc3 |
.\" MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
|
|
Packit |
209cc3 |
.\"
|
|
Packit |
209cc3 |
.TH PCAP_BREAKLOOP 3PCAP "25 July 2018"
|
|
Packit |
209cc3 |
.SH NAME
|
|
Packit |
209cc3 |
pcap_breakloop \- force a pcap_dispatch() or pcap_loop() call to return
|
|
Packit |
209cc3 |
.SH SYNOPSIS
|
|
Packit |
209cc3 |
.nf
|
|
Packit |
209cc3 |
.ft B
|
|
Packit |
209cc3 |
#include <pcap/pcap.h>
|
|
Packit |
209cc3 |
.ft
|
|
Packit |
209cc3 |
.LP
|
|
Packit |
209cc3 |
.ft B
|
|
Packit |
209cc3 |
void pcap_breakloop(pcap_t *);
|
|
Packit |
209cc3 |
.ft
|
|
Packit |
209cc3 |
.fi
|
|
Packit |
209cc3 |
.SH DESCRIPTION
|
|
Packit |
209cc3 |
.B pcap_breakloop()
|
|
Packit |
209cc3 |
sets a flag that will force
|
|
Packit |
209cc3 |
.B pcap_dispatch(3PCAP)
|
|
Packit |
209cc3 |
or
|
|
Packit |
209cc3 |
.B pcap_loop(3PCAP)
|
|
Packit |
209cc3 |
to return rather than looping; they will return the number of packets
|
|
Packit |
209cc3 |
that have been processed so far, or
|
|
Packit |
209cc3 |
.B PCAP_ERROR_BREAK
|
|
Packit |
209cc3 |
if no packets have been processed so far.
|
|
Packit |
209cc3 |
.PP
|
|
Packit |
209cc3 |
This routine is safe to use inside a signal handler on UNIX or a console
|
|
Packit |
209cc3 |
control handler on Windows, as it merely sets a flag that is checked
|
|
Packit |
209cc3 |
within the loop.
|
|
Packit |
209cc3 |
.PP
|
|
Packit |
209cc3 |
The flag is checked in loops reading packets from the OS - a signal by
|
|
Packit |
209cc3 |
itself will not necessarily terminate those loops - as well as in loops
|
|
Packit |
209cc3 |
processing a set of packets returned by the OS.
|
|
Packit |
209cc3 |
.ft B
|
|
Packit |
209cc3 |
Note that if you are catching signals on UNIX systems that support
|
|
Packit |
209cc3 |
restarting system calls after a signal, and calling pcap_breakloop()
|
|
Packit |
209cc3 |
in the signal handler, you must specify, when catching those signals,
|
|
Packit |
209cc3 |
that system calls should NOT be restarted by that signal. Otherwise,
|
|
Packit |
209cc3 |
if the signal interrupted a call reading packets in a live capture,
|
|
Packit |
209cc3 |
when your signal handler returns after calling pcap_breakloop(), the
|
|
Packit |
209cc3 |
call will be restarted, and the loop will not terminate until more
|
|
Packit |
209cc3 |
packets arrive and the call completes.
|
|
Packit |
209cc3 |
.ft R
|
|
Packit |
209cc3 |
.PP
|
|
Packit |
209cc3 |
.ft B
|
|
Packit |
209cc3 |
Note also that, in a multi-threaded application, if one thread is
|
|
Packit |
209cc3 |
blocked in pcap_dispatch(), pcap_loop(), pcap_next(3PCAP), or pcap_next_ex(3PCAP),
|
|
Packit |
209cc3 |
a call to pcap_breakloop() in a different thread will not unblock that
|
|
Packit |
209cc3 |
thread.
|
|
Packit |
209cc3 |
.ft R
|
|
Packit |
209cc3 |
You will need to use whatever mechanism the OS provides for
|
|
Packit |
209cc3 |
breaking a thread out of blocking calls in order to unblock the thread,
|
|
Packit |
209cc3 |
such as thread cancellation or thread signalling in systems that support
|
|
Packit |
209cc3 |
POSIX threads, or
|
|
Packit |
209cc3 |
.B SetEvent()
|
|
Packit |
209cc3 |
on the result of
|
|
Packit |
209cc3 |
.B pcap_getevent()
|
|
Packit |
209cc3 |
on a
|
|
Packit |
209cc3 |
.B pcap_t
|
|
Packit |
209cc3 |
on which the thread is blocked on Windows. Asynchronous procedure calls
|
|
Packit |
209cc3 |
will not work on Windows, as a thread blocked on a
|
|
Packit |
209cc3 |
.B pcap_t
|
|
Packit |
209cc3 |
will not be in an alertable state.
|
|
Packit |
209cc3 |
.ft R
|
|
Packit |
209cc3 |
.PP
|
|
Packit |
209cc3 |
Note that
|
|
Packit |
209cc3 |
.B pcap_next()
|
|
Packit |
209cc3 |
and
|
|
Packit |
209cc3 |
.B pcap_next_ex()
|
|
Packit |
209cc3 |
will, on some platforms, loop reading packets from the OS; that loop
|
|
Packit |
209cc3 |
will not necessarily be terminated by a signal, so
|
|
Packit |
209cc3 |
.B pcap_breakloop()
|
|
Packit |
209cc3 |
should be used to terminate packet processing even if
|
|
Packit |
209cc3 |
.B pcap_next()
|
|
Packit |
209cc3 |
or
|
|
Packit |
209cc3 |
.B pcap_next_ex()
|
|
Packit |
209cc3 |
is being used.
|
|
Packit |
209cc3 |
.PP
|
|
Packit |
209cc3 |
.B pcap_breakloop()
|
|
Packit |
209cc3 |
does not guarantee that no further packets will be processed by
|
|
Packit |
209cc3 |
.B pcap_dispatch()
|
|
Packit |
209cc3 |
or
|
|
Packit |
209cc3 |
.B pcap_loop()
|
|
Packit |
209cc3 |
after it is called; at most one more packet might be processed.
|
|
Packit |
209cc3 |
.PP
|
|
Packit |
209cc3 |
If
|
|
Packit |
209cc3 |
.B PCAP_ERROR_BREAK
|
|
Packit |
209cc3 |
is returned from
|
|
Packit |
209cc3 |
.B pcap_dispatch()
|
|
Packit |
209cc3 |
or
|
|
Packit |
209cc3 |
.BR pcap_loop() ,
|
|
Packit |
209cc3 |
the flag is cleared, so a subsequent call will resume reading packets.
|
|
Packit |
209cc3 |
If a positive number is returned, the flag is not cleared, so a
|
|
Packit |
209cc3 |
subsequent call will return
|
|
Packit |
209cc3 |
.B PCAP_ERROR_BREAK
|
|
Packit |
209cc3 |
and clear the flag.
|
|
Packit |
209cc3 |
.SH SEE ALSO
|
|
Packit |
209cc3 |
pcap(3PCAP)
|